debian: switch to uwsgi and a systemd unit (#29472)

This commit is contained in:
Frédéric Péters 2019-01-06 10:34:18 +01:00
parent 8b45ce4986
commit 2e22202dbb
6 changed files with 71 additions and 46 deletions

5
debian/control vendored
View File

@ -2,7 +2,7 @@ Source: hobo
Maintainer: Jérôme Schneider <jschneider@entrouvert.com>
Section: python
Priority: optional
Build-Depends: python-setuptools (>= 0.6b3), python-all (>= 2.6.6-3), python-django, debhelper (>= 7)
Build-Depends: python-setuptools (>= 0.6b3), python-all (>= 2.6.6-3), python-django, debhelper (>= 7), dh-systemd
Standards-Version: 3.9.1
X-Python-Version: >= 2.7
@ -32,7 +32,8 @@ Depends: python-hobo (= ${binary:Version}),
python-django (>= 1.8),
python-gadjo,
python-django-mellon (>= 1.2.17),
gunicorn
uwsgi,
uwsgi-plugin-python
Recommends: nginx,
rabbitmq-server (>= 3.3),
erlang-nox (>= 1:17.1)

58
debian/hobo.init vendored
View File

@ -16,14 +16,12 @@
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Hobo server"
NAME=hobo
DAEMON=/usr/bin/gunicorn
DAEMON=/usr/bin/uwsgi
RUN_DIR=/run/$NAME
PIDFILE=$RUN_DIR/$NAME.pid
LOG_DIR=/var/log/$NAME
SCRIPTNAME=/etc/init.d/$NAME
BIND=unix:$RUN_DIR/$NAME.sock
WORKERS=5
TIMEOUT=30
HOBO_SETTINGS_FILE=/usr/lib/$NAME/debian_config.py
MANAGE_SCRIPT="/usr/bin/$NAME-manage"
@ -32,22 +30,15 @@ USER=$NAME
GROUP=$NAME
# Exit if the package is not installed
[ -x $DAEMON ] || exit 0
[ -x $MANAGE_SCRIPT ] || exit 0
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
DAEMON_ARGS=${DAEMON_ARGS:-"--pid $PIDFILE \
--user $USER --group $GROUP \
--daemon \
--access-logfile $LOG_DIR/gunicorn-access.log \
--log-file $LOG_DIR/gunicorn-error.log \
--bind=$BIND \
--workers=$WORKERS \
--worker-class=sync \
--timeout=$TIMEOUT \
--name $NAME \
$NAME.wsgi:application"}
DAEMON_ARGS=${DAEMON_ARGS:-"--pidfile=$PIDFILE
--uid $USER --gid $GROUP
--ini /etc/$NAME/uwsgi.ini
--daemonize /var/log/uwsgi.$NAME.log"}
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
@ -73,9 +64,7 @@ do_start()
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --exec $DAEMON -- \
start-stop-daemon --start --quiet --user $USER --exec $DAEMON -- \
$DAEMON_ARGS \
|| return 2
}
@ -90,45 +79,29 @@ do_stop()
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
# and if the daemon is only ever run from this initscript.
# If the above conditions are not satisfied then add some other code
# that waits for the process to drop all resources that could be
# needed by services started subsequently. A last resort is to
# sleep for some time.
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
$DAEMON --stop $PIDFILE
rm -f $PIDFILE
return "$RETVAL"
return 0 # hopefully
}
#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
#
# If the daemon can reload its configuration without
# restarting (for example, when it is sent a SIGHUP),
# then implement that here.
#
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name `basename $DAEMON`
$DAEMON --reload $PIDFILE
return 0
}
do_migrate() {
log_action_msg "Applying new migrations .."
log_action_msg "Applying migrations (migrate_schemas).."
su $USER -s /bin/sh -p -c "$MANAGE_SCRIPT migrate_schemas --noinput"
log_action_msg ".. done"
log_action_msg "done"
}
do_collectstatic() {
log_action_msg "Collect static files.."
log_action_msg "Collect static files (collectstatic).."
su $USER -s /bin/sh -p -c "$MANAGE_SCRIPT collectstatic --noinput"
log_action_msg ".. done"
log_action_msg "done"
}
case "$1" in
@ -151,7 +124,7 @@ case "$1" in
esac
;;
status)
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
status_of_proc -p $PIDFILE "$DAEMON" "$NAME" && exit 0 || exit $?
;;
reload|force-reload)
#
@ -191,4 +164,3 @@ case "$1" in
exit 3
;;
esac

1
debian/hobo.install vendored
View File

@ -1,3 +1,4 @@
debian/server/hobo-manage /usr/bin
debian/server/settings.py /etc/hobo
debian/server/uwsgi.ini /etc/hobo
debian/server/debian_config.py /usr/lib/hobo

25
debian/hobo.service vendored Normal file
View File

@ -0,0 +1,25 @@
[Unit]
Description=Hobo
After=network.target syslog.target postgresql.service
Wants=postgresql.service
[Service]
Environment=HOBO_SETTINGS_FILE=/usr/lib/%p/debian_config.py
Environment=LANG=C.UTF-8
User=%p
Group=%p
ExecStartPre=/usr/bin/hobo-manage migrate_schemas --noinput
ExecStartPre=/usr/bin/hobo-manage collectstatic --noinput
ExecStart=/usr/bin/uwsgi --ini /etc/%p/uwsgi.ini
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGQUIT
TimeoutStartSec=0
PrivateTmp=true
Restart=on-failure
RuntimeDirectory=hobo
Type=notify
StandardError=syslog
NotifyAccess=all
[Install]
WantedBy=multi-user.target

2
debian/rules vendored
View File

@ -7,7 +7,7 @@
PYTHON_HOBO_DIR=$(CURDIR)/debian/python-hobo
%:
dh $@ --with python2
dh $@ --with python2,systemd
override_dh_install:
dh_install

26
debian/server/uwsgi.ini vendored Normal file
View File

@ -0,0 +1,26 @@
[uwsgi]
auto-procname = true
procname-prefix-spaced = hobo
plugin = python
module = hobo.wsgi:application
http-socket = /run/hobo/hobo.sock
chmod-socket = 666
vacuum = true
master = true
processes = 5
harakiri = 120
enable-threads = true
buffer-size = 32768
py-tracebacker = /run/hobo/py-tracebacker.sock.
stats = /run/hobo/stats.sock
ignore-sigpipe = true
if-file = /etc/hobo/uwsgi-local.ini
include = /etc/hobo/uwsgi-local.ini
endif =