Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init.d support #2

Merged
merged 4 commits into from
Jun 19, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
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
45 changes: 38 additions & 7 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
# [*service_file*]
# The location of the service file. Default: '/etc/init/uwsgi.conf'
#
# [*service_file_mode*]
# The mode of the service file. Default: '0644'
#
# [*service_template*]
# The location of the template to generate the *service_file*.
# Default: 'uwsgi/uwsgi_upstart.conf.erb'
Expand Down Expand Up @@ -77,8 +80,9 @@
$package_ensure = $uwsgi::params::package_ensure,
$package_provider = $uwsgi::params::package_provider,
$service_name = $uwsgi::params::service_name,
$service_file = $uwsgi::params::service_file,
$service_template = $uwsgi::params::service_template,
$service_file = undef,
$service_file_mode = undef,
$service_template = undef,
$service_ensure = $uwsgi::params::service_ensure,
$service_enable = $uwsgi::params::service_enable,
$service_provider = $uwsgi::params::service_provider,
Expand Down Expand Up @@ -127,13 +131,40 @@
require => Package[$package_name]
}

file { $service_file:
if $service_file == undef {
$service_file_real = $service_provider ? {
redhat => '/etc/init.d/uwsgi',
upstart => '/etc/init/uwsgi.conf',
}
} else {
$service_file_real = $service_file
}

if $service_file_mode == undef {
$service_file_mode_real = $service_provider ? {
redhat => '0555',
upstart => '0644',
}
} else {
$service_file_mode_real = $service_file_mode
}

if $service_template == undef {
$service_template_real = $service_provider ? {
redhat => 'uwsgi/uwsgi_service-redhat.erb',
upstart => 'uwsgi/uwsgi_upstart.conf.erb',
}
} else {
$service_template_real = $service_template
}

file { $service_file_real:
ensure => $file_ensure,
owner => 'root',
group => 'root',
mode => '0644',
mode => $service_file_mode_real,
replace => $manage_service_file,
content => template($service_template),
content => template($service_template_real),
require => Package[$package_name]
}

Expand All @@ -154,11 +185,11 @@
require => [
Package[$package_name],
File[$config_file],
File[$service_file]
File[$service_file_real]
],
subscribe => [
File[$config_file],
File[$service_file]
File[$service_file_real]
]
}

Expand Down
6 changes: 4 additions & 2 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
$package_ensure = 'installed'
$package_provider = 'pip'
$service_name = 'uwsgi'
$service_file = '/etc/init/uwsgi.conf'
$service_template = 'uwsgi/uwsgi_upstart.conf.erb'
$service_ensure = true
$service_enable = true
$service_provider = 'upstart'
Expand All @@ -24,11 +22,15 @@
case $::osfamily {
redhat: {
$app_directory = '/etc/uwsgi.d'
$pidfile = '/var/run/uwsgi/uwsgi.pid'
$python_dev = 'python-devel'
$socket = '/var/run/uwsgi/uwsgi.socket'
}
default: {
$app_directory = '/etc/uwsgi/apps-enabled'
$pidfile = '/run/uwsgi/uwsgi.pid'
$python_dev = 'python-dev'
$socket = '/run/uwsgi/uwsgi.socket'
}
}
}
4 changes: 2 additions & 2 deletions templates/uwsgi.ini.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# uWSGI main process configuration
#
[uwsgi]
socket = /run/uwsgi/uwsgi.socket
pidfile = /run/uwsgi/uwsgi.pid
socket = <%= @socket %>
pidfile = <%= @pidfile %>
emperor = <%= @app_directory %>
emperor-tyrant = true
master = true
Expand Down
99 changes: 99 additions & 0 deletions templates/uwsgi_service-redhat.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/bin/sh
# This file is managed by puppet class 'uwsgi'
#
# uWSGI Emperor process init.d script
#
# chkconfig: - 85 15
# description: uWSGI Emperor process init.d script

### BEGIN INIT INFO
# Provides: uwsgi
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop uwsgi
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

OPTIONS="--daemonize --die-on-term --ini <%= @config_file %>"
UWSGIPID="<%= @pidfile %>"
UWSGISOCKET="<%= @socket %>"

UWSGIPIDDIR="${UWSGIPID%/*}"
UWSGISOCKETDIR="${UWSGISOCKET%/*}"

[ -f /etc/sysconfig/uwsgi ] && . /etc/sysconfig/uwsgi

if [ ! -d "${UWSGIPIDDIR}" ]; then
mkdir -p "${UWSGIPIDDIR}"
[ -n "${RUNAS}" ] && chown "${RUNAS}:" "${UWSGIPIDDIR}"
fi

if [ ! -d "${UWSGISOCKETDIR}" ]; then
mkdir -p "${UWSGISOCKETDIR}"
[ -n "${RUNAS}" ] && chown "${RUNAS}:" "${UWSGISOCKETDIR}"
fi

RETVAL=0
prog=uwsgi
lockfile=/var/lock/subsys/$prog

start() {
[ "$EUID" != "0" ] && exit 4

# Start daemons.
echo -n $"Starting $prog: "
daemon $prog $OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch $lockfile
return $RETVAL
}

stop() {
[ "$EUID" != "0" ] && exit 4

echo -n $"Shutting down $prog: "
killproc $prog
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $lockfile
return $RETVAL
}

reload() {
[ "$EUID" != "0" ] && exit 4

echo -n $"Reloading $prog: "
killproc $prog -HUP
RETVAL=$?
echo
return $RETVAL
}

case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $prog
;;
restart)
stop
start
;;
reload)
reload
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload}"
exit 2
;;
esac
exit $?