From 538b7ff0c8125a3f412154807e3425127968448f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 24 Apr 2023 17:05:29 +0200 Subject: Add everything. --- manifests/instance.pp | 38 ++++++++++++++++++++++++++++++++++++++ manifests/setup.pp | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 manifests/instance.pp create mode 100644 manifests/setup.pp (limited to 'manifests') diff --git a/manifests/instance.pp b/manifests/instance.pp new file mode 100644 index 0000000..0cd72bc --- /dev/null +++ b/manifests/instance.pp @@ -0,0 +1,38 @@ +# @summary Sets up a single gunicorn instance +# +# @param app +# Name of the app, probably something like "wsgi_module:app" +# @param address +# Address to bind Gunicorn to +# @param instance_name +# Name for this instance +# @param workers +# Workers used by this gunicorn instance. `$cpu_count * 2 + 1` is +# copied from the Gunicorn manual. +# @param user +# User to run this instance as. +# @param group +# Group to run this instance as. +define gunicorn::instance ( + String $app, + String $address, + String $instance_name = $name, + Integer $workers = $facts['processor']['count'] * 2 + 1, + Variant[String, Integer] $user = $gunicorn::setup::user, + Variant[String, Integer] $group = $gunicorn::setup::group, +) { + $options = { + 'proc_name' => $instance_name, + 'wsgi_app' => $app, + } + + file { "${gunicorn::setup::instance_dir}/${instance_name}.conf.pp": + content => epp("${module_name}/gunicorn.conf.py.epp", $options), + validate_cmd => 'gunicorn --check-config', + } + + service { "gunicorn@${instance_name}": + ensure => running, + enable => true, + } +} diff --git a/manifests/setup.pp b/manifests/setup.pp new file mode 100644 index 0000000..aebfe46 --- /dev/null +++ b/manifests/setup.pp @@ -0,0 +1,34 @@ +# @summary General configuration of gunicorn +# +# @param package_name +# Name of system package +# @param instance_dir +# Where instance configuration files should be plced +# Should currently not be changed, since it's hard-coded in the +# service file. +# @param user +# Default user to use for each instance. +# @param group +# Default group to use for each instance. +class gunicorn::setup ( + String $package_name = 'gunicorn', + String $instance_dir = '/var/lib/gunicorn', + Variant[String, Integer] $user = 'gunicorn', + Variant[String, Integer] $group = 'gunicorn', +) { + ensure_packages([ + $package_name, + ]) + + # python-setproctitle + + file { $instance_dir: + ensure => directory, + } + + systemd::unit_file { 'gunicorn@.service': + source => "puppet:///modules/${module_name}/gunicorn@.service", + enable => false, + active => false, + } +} -- cgit v1.2.3