debian: add systemd unit, with a switch to uwsgi

This commit is contained in:
Frédéric Péters 2018-12-26 13:31:18 +01:00
parent 28dc6effb7
commit 7cf73ab567
3 changed files with 36 additions and 40 deletions

5
debian/control vendored
View File

@ -2,7 +2,7 @@ Source: scrutiny
Maintainer: Frederic Peters <fpters@entrouvert.com> Maintainer: Frederic Peters <fpters@entrouvert.com>
Section: python Section: python
Priority: optional Priority: optional
Build-Depends: python-setuptools (>= 0.6b3), python-all (>= 2.6.6-3), debhelper (>= 7) Build-Depends: python-setuptools (>= 0.6b3), python-all (>= 2.6.6-3), debhelper (>= 9), dh-systemd
Standards-Version: 3.9.6 Standards-Version: 3.9.6
X-Python-Version: >= 2.7 X-Python-Version: >= 2.7
@ -20,7 +20,8 @@ Depends: ${misc:Depends},
python-scrutiny (= ${binary:Version}), python-scrutiny (= ${binary:Version}),
python-memcache, python-memcache,
python-psycopg2, python-psycopg2,
gunicorn, uwsgi,
uwsgi-plugin-python,
memcached memcached
Recommends: nginx, postgresql Recommends: nginx, postgresql
Description: Tracker of installed modules Description: Tracker of installed modules

47
debian/scrutiny.init vendored
View File

@ -16,14 +16,12 @@
PATH=/sbin:/usr/sbin:/bin:/usr/bin PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Tracker of installed modules" DESC="Tracker of installed modules"
NAME=scrutiny NAME=scrutiny
DAEMON=/usr/bin/gunicorn DAEMON=/usr/bin/uwsgi
RUN_DIR=/run/$NAME RUN_DIR=/run/$NAME
PIDFILE=$RUN_DIR/$NAME.pid PIDFILE=$RUN_DIR/$NAME.pid
LOG_DIR=/var/log/$NAME LOG_DIR=/var/log/$NAME
SCRIPTNAME=/etc/init.d/$NAME SCRIPTNAME=/etc/init.d/$NAME
BIND=unix:$RUN_DIR/$NAME.sock BIND=unix:$RUN_DIR/$NAME.sock
WORKERS=5
TIMEOUT=30
SCRUTINY_SETTINGS_FILE=/usr/lib/$NAME/debian_config.py SCRUTINY_SETTINGS_FILE=/usr/lib/$NAME/debian_config.py
MANAGE_SCRIPT="/usr/bin/$NAME-manage" MANAGE_SCRIPT="/usr/bin/$NAME-manage"
@ -37,17 +35,10 @@ GROUP=$NAME
# Read configuration variable file if it is present # Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME [ -r /etc/default/$NAME ] && . /etc/default/$NAME
DAEMON_ARGS=${DAEMON_ARGS:-"--pid $PIDFILE \ DAEMON_ARGS=${DAEMON_ARGS:-"--pidfile=$PIDFILE
--user $USER --group $GROUP \ --uid $USER --gid $GROUP
--daemon \ --ini /etc/$NAME/uwsgi.ini
--access-logfile $LOG_DIR/gunicorn-access.log \ --daemonize /var/log/uwsgi.$NAME.log"}
--log-file $LOG_DIR/gunicorn-error.log \
--bind=$BIND \
--workers=$WORKERS \
--worker-class=sync \
--timeout=$TIMEOUT \
--name $NAME \
$NAME.wsgi:application"}
# Load the VERBOSE setting and other rcS variables # Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh . /lib/init/vars.sh
@ -73,9 +64,7 @@ do_start()
# 0 if daemon has been started # 0 if daemon has been started
# 1 if daemon was already running # 1 if daemon was already running
# 2 if daemon could not be started # 2 if daemon could not be started
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ start-stop-daemon --start --quiet --user $USER --exec $DAEMON -- \
|| return 1
start-stop-daemon --start --quiet --exec $DAEMON -- \
$DAEMON_ARGS \ $DAEMON_ARGS \
|| return 2 || return 2
} }
@ -90,32 +79,16 @@ do_stop()
# 1 if daemon was already stopped # 1 if daemon was already stopped
# 2 if daemon could not be stopped # 2 if daemon could not be stopped
# other if a failure occurred # other if a failure occurred
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE $DAEMON --stop $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.
rm -f $PIDFILE rm -f $PIDFILE
return "$RETVAL" return 0 # hopefully
} }
# #
# Function that sends a SIGHUP to the daemon/service # Function that sends a SIGHUP to the daemon/service
# #
do_reload() { do_reload() {
# $DAEMON --reload $PIDFILE
# 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`
return 0 return 0
} }
@ -159,8 +132,6 @@ case "$1" in
# and leave 'force-reload' as an alias for 'restart'. # and leave 'force-reload' as an alias for 'restart'.
# #
log_daemon_msg "Reloading $DESC" "$NAME" log_daemon_msg "Reloading $DESC" "$NAME"
do_collectstatic
do_migrate
do_reload do_reload
log_end_msg $? log_end_msg $?
;; ;;

24
debian/scrutiny.service vendored Normal file
View File

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