From 4ed0dfb218600917d3ab4737096aec5615a46f01 Mon Sep 17 00:00:00 2001 From: Andy Clark Date: Mon, 1 Aug 2016 14:46:27 -0700 Subject: [PATCH 1/2] Add systemd support --- manifests/init.pp | 43 +++++++++++++++++++++++++++-- templates/uwsgi_systemd.service.erb | 15 ++++++++++ templates/uwsgi_upstart.conf.erb | 11 -------- 3 files changed, 56 insertions(+), 13 deletions(-) create mode 100644 templates/uwsgi_systemd.service.erb diff --git a/manifests/init.pp b/manifests/init.pp index ff7f5c4..b06f2c2 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -41,7 +41,7 @@ # [*service_provider*] # The service provider. Default: 'upstart' # 'upstart' is required for the default service_file, and -# works on RedHat >= 6 +# works on RedHat = 6 # # [*manage_service_file*] # Whether to override the system service file if it exists. Default: true @@ -156,6 +156,7 @@ $service_file_real = $service_provider ? { redhat => '/etc/init.d/uwsgi', upstart => '/etc/init/uwsgi.conf', + systemd => '/etc/systemd/system/uwsgi.service', default => '/etc/init/uwsgi.conf', } } else { @@ -166,6 +167,7 @@ $service_file_mode_real = $service_provider ? { redhat => '0555', upstart => '0644', + systemd => '0644', default => '0644', } } else { @@ -176,6 +178,7 @@ $service_template_real = $service_provider ? { redhat => 'uwsgi/uwsgi_service-redhat.erb', upstart => 'uwsgi/uwsgi_upstart.conf.erb', + systemd => 'uwsgi/uwsgi_systemd.service.erb', default => 'uwsgi/uwsgi_upstart.conf.erb', } } else { @@ -192,10 +195,43 @@ require => Package[$package_name] } $required_files = [ $config_file, $service_file_real ] + + if $service_provider == 'systemd' { + exec { 'uwsgi-reload-systemd': + command => '/bin/systemctl daemon-reload', + refreshonly => true, + subscribe => File[$service_file_real], + before => Service[$service_name], + } + } } else { $required_files = $config_file } + $log_directory = dirname($log_file) + $pid_directory = dirname($pidfile) + $socket_directory = dirname($socket) + + exec { $log_directory: + creates => $log_directory, + command => "mkdir -p ${log_directory}", + path => $::path + } -> file { $log_directory: } + + exec { $pid_directory: + creates => $pid_directory, + command => "mkdir -p ${pid_directory}", + path => $::path + } -> file { $pid_directory: } + + if $socket_directory != $pid_directory { + exec { $socket_directory: + creates => $socket_directory, + command => "mkdir -p ${socket_directory}", + path => $::path + } -> file { $socket_directory: } + } + file { $app_directory: ensure => 'directory', owner => 'root', @@ -212,7 +248,10 @@ provider => $service_provider, require => [ Package[$package_name], - File[$required_files] + File[$required_files], + File[$log_directory], + File[$pid_directory], + File[$socket_directory], ], subscribe => File[$required_files] } diff --git a/templates/uwsgi_systemd.service.erb b/templates/uwsgi_systemd.service.erb new file mode 100644 index 0000000..d245f30 --- /dev/null +++ b/templates/uwsgi_systemd.service.erb @@ -0,0 +1,15 @@ +# +# This file is managed by puppet class 'uwsgi' +# +# uWSGI Emperor process systemd service +# +[Unit] +Description=uWSGI Emperor +After=network.target + +[Service] +Type=simple +ExecStart=/usr/sbin/uwsgi --die-on-term --ini <%= @config_file %> + +[Install] +WantedBy=multi-user.target diff --git a/templates/uwsgi_upstart.conf.erb b/templates/uwsgi_upstart.conf.erb index 2f7761e..c658a45 100644 --- a/templates/uwsgi_upstart.conf.erb +++ b/templates/uwsgi_upstart.conf.erb @@ -9,15 +9,4 @@ stop on runlevel [!2345] respawn -pre-start script - uwsgilog="<%= @log_file %>" - uwsgipid="<%= @pidfile %>" - uwsgisocket="<%= @socket %>" - uwsgilogdir="${uwsgilog%/*}" - uwsgipiddir="${uwsgipid%/*}" - uwsgisocketdir="${uwsgisocket%/*}" - mkdir -p "$uwsgipiddir" - mkdir -p "$uwsgisocketdir" - mkdir -p "$uwsgilogdir" -end script exec uwsgi --die-on-term --ini <%= @config_file %> From 6f63b1165110ebb19d551431d7cd3a283e25541f Mon Sep 17 00:00:00 2001 From: Andy Clark Date: Tue, 2 Aug 2016 10:15:48 -0700 Subject: [PATCH 2/2] Add binary_directory parameter for systemd * Add binary_directory parameter for systemd * Add systemd information to README --- README.md | 10 +++++++++- manifests/init.pp | 8 +++++++- manifests/params.pp | 1 + templates/uwsgi_systemd.service.erb | 4 ++-- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4d4b0be..692991c 100644 --- a/README.md +++ b/README.md @@ -64,14 +64,22 @@ redhat init.d or upstart depending on the service provider. Default: 'upstart' `upstart` is required for the default `service_file`, and - works on RedHat >= 6. Setting `service_provider` to `redhat` + works on RedHat 6. Setting `service_provider` to `redhat` will now deploy the init.d service file, unless you specifically set `service_template` etc. + `systemd` will create a systemd service on RedHat 7. * `manage_service_file` Whether to override the system service file if it exists. Default: true +* `binary_directory` + Default: '/usr/sbin' + + Directory containing the uwsgi binary. Used by the `systemd` + service_provider; not used by the `upstart` or `redhat` service_provider + parameter. + * `config_file` The location of the uwsgi config file. Default: '/etc/uwsgi.ini' diff --git a/manifests/init.pp b/manifests/init.pp index b06f2c2..4afbdab 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -41,11 +41,16 @@ # [*service_provider*] # The service provider. Default: 'upstart' # 'upstart' is required for the default service_file, and -# works on RedHat = 6 +# works on RedHat 6. +# 'systemd' works on RedHat 7. # # [*manage_service_file*] # Whether to override the system service file if it exists. Default: true # +# [*binary_directory*] +# Directory containing the uwsgi binary. Used by the 'systemd' +# service_provider, but not 'upstart' or 'redhat'. +# # [*config_file*] # The location of the uwsgi config file. Default: '/etc/uwsgi.ini' # @@ -100,6 +105,7 @@ $service_enable = $uwsgi::params::service_enable, $service_provider = $uwsgi::params::service_provider, $manage_service_file = $uwsgi::params::manage_service_file, + $binary_directory = $uwsgi::params::binary_directory, $config_file = $uwsgi::params::config_file, $log_file = $uwsgi::params::log_file, $log_rotate = $uwsgi::params::log_rotate, diff --git a/manifests/params.pp b/manifests/params.pp index 184c2be..931703b 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -14,6 +14,7 @@ $service_enable = true $service_provider = 'upstart' $manage_service_file = true + $binary_directory = '/usr/sbin' $config_file = '/etc/uwsgi.ini' $tyrant = true $install_pip = true diff --git a/templates/uwsgi_systemd.service.erb b/templates/uwsgi_systemd.service.erb index d245f30..9cd1ef6 100644 --- a/templates/uwsgi_systemd.service.erb +++ b/templates/uwsgi_systemd.service.erb @@ -1,5 +1,5 @@ # -# This file is managed by puppet class 'uwsgi' +# This file is managed by the puppet class 'uwsgi' # # uWSGI Emperor process systemd service # @@ -9,7 +9,7 @@ After=network.target [Service] Type=simple -ExecStart=/usr/sbin/uwsgi --die-on-term --ini <%= @config_file %> +ExecStart=<%= @binary_directory %>/uwsgi --die-on-term --ini <%= @config_file %> [Install] WantedBy=multi-user.target