Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -166,6 +167,7 @@
$service_file_mode_real = $service_provider ? {
redhat => '0555',
upstart => '0644',
systemd => '0644',
default => '0644',
}
} else {
Expand All @@ -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 {
Expand All @@ -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',
Expand All @@ -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]
}
Expand Down
15 changes: 15 additions & 0 deletions templates/uwsgi_systemd.service.erb
Original file line number Diff line number Diff line change
@@ -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 %>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you parameterise the uwsgi binary location or just leave the path off? I'm just imagining other distros that use systemd may not install uwsgi into sbin.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll parameterize the binary path. On CentOS 7, the service failed to start without the full path.
Any preference for the name of the parameter? "app_binary_directory"?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just go with something like "binary_location" and include the uwsgi component. Thoughts?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the name "binary_directory" in order to match the variables "app_directory", "log_directory", etc.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, that makes sense. Fine with me.


[Install]
WantedBy=multi-user.target
11 changes: 0 additions & 11 deletions templates/uwsgi_upstart.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>