fargo/debian/fargo.init

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

168 lines
3.8 KiB
Plaintext
Raw Normal View History

2015-03-05 23:46:47 +01:00
#!/bin/sh
### BEGIN INIT INFO
# Provides: fargo
# Required-Start: $network $local_fs $remote_fs $syslog
# Required-Stop: $network $local_fs $remote_fs $syslog
# Should-Start: postgresql
# Should-Stop: postgresql
2015-03-05 23:46:47 +01:00
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
2015-08-18 16:09:48 +02:00
# Short-Description: Document Box
# Description: Document Box
2015-03-05 23:46:47 +01:00
### END INIT INFO
2015-08-18 16:09:48 +02:00
# Author: Entr'ouvert <info@entrouvert.com>
2015-03-05 23:46:47 +01:00
PATH=/sbin:/usr/sbin:/bin:/usr/bin
2015-08-18 16:09:48 +02:00
DESC="Document Box"
2015-03-05 23:46:47 +01:00
NAME=fargo
2019-07-08 21:41:09 +02:00
DAEMON=/usr/bin/uwsgi
2015-08-18 16:09:48 +02:00
RUN_DIR=/run/$NAME
PIDFILE=$RUN_DIR/$NAME.pid
2015-03-05 23:46:47 +01:00
LOG_DIR=/var/log/$NAME
SCRIPTNAME=/etc/init.d/$NAME
2015-08-18 16:09:48 +02:00
BIND=unix:$RUN_DIR/$NAME.sock
2015-04-10 17:05:55 +02:00
FARGO_SETTINGS_FILE=/usr/lib/$NAME/debian_config.py
2015-08-18 16:09:48 +02:00
MANAGE_SCRIPT="/usr/bin/$NAME-manage"
2015-03-05 23:46:47 +01:00
2015-08-18 16:09:48 +02:00
USER=$NAME
GROUP=$NAME
2015-03-05 23:46:47 +01:00
# Exit if the package is not installed
2015-08-18 16:09:48 +02:00
[ -x $MANAGE_SCRIPT ] || exit 0
2015-03-05 23:46:47 +01:00
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
2019-07-08 21:41:09 +02:00
DAEMON_ARGS=${DAEMON_ARGS:-"--pidfile=$PIDFILE
--uid $USER --gid $GROUP
--ini /etc/$NAME/uwsgi.ini
2021-07-13 15:24:55 +02:00
--spooler /var/lib/$NAME/spooler/
2019-07-08 21:41:09 +02:00
--daemonize /var/log/uwsgi.$NAME.log"}
2015-03-05 23:46:47 +01:00
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
2015-08-18 16:09:48 +02:00
# Create /run directory
if [ ! -d $RUN_DIR ]; then
install -d -m 755 -o $USER -g $GROUP $RUN_DIR
2015-03-05 23:46:47 +01:00
fi
2015-08-18 16:09:48 +02:00
# environment for wsgi
2015-04-21 14:26:21 +02:00
export FARGO_SETTINGS_FILE
2015-03-05 23:46:47 +01:00
#
# Function that starts the daemon/service
#
do_start()
{
2015-08-18 16:09:48 +02:00
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
2019-07-08 21:41:09 +02:00
start-stop-daemon --start --quiet --user $USER --exec $DAEMON -- \
2015-08-18 16:09:48 +02:00
$DAEMON_ARGS \
|| return 2
2015-03-05 23:46:47 +01:00
}
#
# Function that stops the daemon/service
#
do_stop()
{
2015-08-18 16:09:48 +02:00
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
2019-07-08 21:41:09 +02:00
$DAEMON --stop $PIDFILE
2015-08-18 16:09:48 +02:00
rm -f $PIDFILE
2019-07-08 21:41:09 +02:00
return 0 # hopefully
2015-03-05 23:46:47 +01:00
}
#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
2019-07-08 21:41:09 +02:00
$DAEMON --reload $PIDFILE
2015-08-18 16:09:48 +02:00
return 0
2015-03-05 23:46:47 +01:00
}
do_migrate() {
2015-08-18 16:09:48 +02:00
log_action_msg "Applying migrations (migrate_schemas).."
su $USER -s /bin/sh -p -c "$MANAGE_SCRIPT migrate_schemas --noinput"
2015-08-18 16:09:48 +02:00
log_action_msg "done"
2015-03-05 23:46:47 +01:00
}
do_collectstatic() {
2015-08-18 16:09:48 +02:00
log_action_msg "Collect static files (collectstatic).."
su $USER -s /bin/sh -p -c "$MANAGE_SCRIPT collectstatic --noinput"
log_action_msg "done"
2015-03-05 23:46:47 +01:00
}
case "$1" in
start)
log_daemon_msg "Starting $DESC " "$NAME"
do_migrate
do_collectstatic
do_start
case "$?" in
2015-08-18 16:09:48 +02:00
0|1) log_end_msg 0 ;;
2) log_end_msg 1 ;;
esac
2015-03-05 23:46:47 +01:00
;;
stop)
2015-08-18 16:09:48 +02:00
log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
2015-03-05 23:46:47 +01:00
case "$?" in
2015-08-18 16:09:48 +02:00
0|1) log_end_msg 0 ;;
2) log_end_msg 1 ;;
2015-03-05 23:46:47 +01:00
esac
;;
2015-08-18 16:09:48 +02:00
status)
2019-07-08 21:41:09 +02:00
status_of_proc -p $PIDFILE "$DAEMON" "$NAME" && exit 0 || exit $?
2015-03-05 23:46:47 +01:00
;;
2015-08-18 16:09:48 +02:00
reload|force-reload)
#
# If do_reload() is not implemented then leave this commented out
# and leave 'force-reload' as an alias for 'restart'.
#
log_daemon_msg "Reloading $DESC" "$NAME"
do_reload
log_end_msg $?
;;
restart|force-reload)
#
# If the "reload" option is implemented then remove the
# 'force-reload' alias
#
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_migrate
do_collectstatic
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
2015-03-05 23:46:47 +01:00
*)
2015-08-18 16:09:48 +02:00
echo "Usage: $SCRIPTNAME {start|stop|status|restart|reload|force-reload}" >&2
exit 3
;;
2015-03-05 23:46:47 +01:00
esac