diff --git a/manifests/init.pp b/manifests/init.pp index f6c07b4..08b356d 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,62 +1,53 @@ class gunicorn { - $service_name = 'gunicorn' $packages = ['gunicorn3'] - include ::systemd include gunicorn::apt_config package {$packages: ensure => installed, } - service {$service_name: - ensure => running, - enable => true, - require => [ - Package[$packages], - Exec['systemd-daemon-reload'] - ], - } - - file {'/etc/systemd/system/gunicorn.service': - ensure => file, - owner => 'root', - group => 'root', - mode => '0644', + ::systemd::unit_file {'gunicorn.service': source => 'puppet:///modules/gunicorn/gunicorn.service', - notify => Exec['systemd-daemon-reload'], - } + } ~> service {'gunicorn': + ensure => running, + enable => true, + require => [ + Package[$packages], + ], + } + file {['/etc/gunicorn', '/etc/gunicorn/instances']: ensure => directory, owner => 'root', group => 'root', mode => '0644', recurse => true, purge => true, } file {'/etc/tmpfiles.d/gunicorn.conf': ensure => directory, owner => 'root', group => 'root', mode => '0644', source => 'puppet:///modules/gunicorn/gunicorn.tmpfiles', notify => Exec['systemd-tmpfiles-update-gunicorn'], } file {'/etc/gunicorn/logconfig.ini': ensure => file, owner => 'root', group => 'root', mode => '0644', source => 'puppet:///modules/gunicorn/logconfig.ini', } exec {'systemd-tmpfiles-update-gunicorn': path => '/sbin:/usr/sbin:/bin:/usr/bin', command => 'systemd-tmpfiles --create /etc/tmpfiles.d/gunicorn.conf', refreshonly => true, require => File['/etc/tmpfiles.d/gunicorn.conf'] } } diff --git a/manifests/instance.pp b/manifests/instance.pp index 3226382..3828f3d 100644 --- a/manifests/instance.pp +++ b/manifests/instance.pp @@ -1,165 +1,154 @@ # == Defined Type: gunicorn::instance # # gunicorn::instance defines an instance of gunicorn # # === Parameters # # [*ensure*] # Whether the instance should be enabled, present (but disabled) or absent. # # [*environment*] # A hash of environment variables to start the service with. # # [*executable*] # The wsgi callable to pass to gunicorn # # [*settings*] # a hash of settings for the given site. # # === Examples # # gunicorn::instance {'foo': # ensure => enabled, # environment => { # FOOENV => 'foovar', # } # executable => 'foo.wsgi:app' # user => 'foouser', # group => 'foogroup', # config_mode => 0644 # settings => { # plugin => 'python3', # protocol => $uwsgi_protocol, # socket => $uwsgi_listen_address, # workers => $uwsgi_workers, # max_requests => $uwsgi_max_requests, # max_requests_delta => $uwsgi_max_requests_delta, # worker_reload_mercy => $uwsgi_reload_mercy, # reload_mercy => $uwsgi_reload_mercy, # uid => $user, # gid => $user, # module => 'swh.storage.api.server', # callable => 'run_from_webserver', # } # } # # === Authors # # Nicolas Dandrimont # # === Copyright # # Copyright 2017 The Software Heritage developers # define gunicorn::instance ( $executable, $user = 'root', $group = 'root', $ensure = 'enabled', $config_mode = '0644', $working_dir = undef, $log_only_errors = true, $settings = {}, $environment = {} ) { $config_file = "/etc/gunicorn/instances/${name}.cfg" $service_name = "gunicorn-${name}" - $service_file = "/etc/systemd/system/${service_name}.service" - $tmpfiles_file = "/etc/tmpfiles.d/${service_name}.conf" + $unit_name = "${service_name}.service" + $tmpfile_name = "${service_name}.conf" $runtime_dir = "/run/gunicorn/${name}" if $working_dir { $working_dir_override = $working_dir } else { $working_dir_override = $runtime_dir } if $log_only_errors { $log_only_errors_str = 'True' } else { $log_only_errors_str = 'False' } case $ensure { default: { err("Unknown value ensure => ${ensure}.") } 'enabled', 'present': { include ::gunicorn # Uses variables: # - $settings # - $name # - $log_only_errors_str file {$config_file: ensure => present, owner => $user, group => $group, mode => $config_mode, content => template('gunicorn/gunicorn-instance.cfg.erb'), notify => Service[$service_name], } # Uses variables: # - $config_file # - $environment # - $executable # - $group # - $name # - $runtime_dir # - $user # - $working_dir_override - file {$service_file: + ::systemd::unit_file {$unit_name: ensure => present, - owner => 'root', - group => 'root', - mode => '0644', content => template('gunicorn/gunicorn-instance.service.erb'), - notify => Exec['systemd-daemon-reload'], - } + } ~> Service[$service_name] # Uses variables: # - $group # - $name # - $runtime_dir # - $user - file {$tmpfiles_file: + ::systemd::tmpfile {$tmpfile_name: ensure => present, - owner => 'root', - group => 'root', - mode => '0644', content => template('gunicorn/gunicorn-instance.tmpfiles.erb'), - notify => Exec["systemd-tmpfiles-update-${service_name}"], - } - - exec {"systemd-tmpfiles-update-${service_name}": - path => '/sbin:/usr/sbin:/bin:/usr/bin', - command => "systemd-tmpfiles --create ${tmpfiles_file}", - refreshonly => true, - require => File[$tmpfiles_file] } $service_enable = $ensure ? { 'enabled' => true, 'present' => undef, } service {$service_name: ensure => 'running', enable => $service_enable, restart => "/bin/systemctl reload ${service_name}.service", require => [ - File[$service_file], File[$config_file], - Exec['systemd-daemon-reload'], ], } } 'absent': { - file {[$tmpfiles_file, $service_file]: - ensure => 'absent' + ::systemd::unit_file {$unit_name: + ensure => absent, + } + ::systemd::tmpfile {$tmpfile_name: + ensure => absent, + } + file {$config_file: + ensure => absent, } } } }