Reformat and use more variables to uniformize with hobo

This commit is contained in:
Benjamin Dauvergne 2014-09-18 14:56:00 +02:00
parent bdab059a5e
commit 409b2494f2
1 changed files with 21 additions and 21 deletions

42
init.d
View File

@ -15,33 +15,34 @@ PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC=Passerelle
NAME=passerelle
DAEMON=/usr/bin/gunicorn
RUN_DIR=/var/run/passerelle
RUN_DIR=/var/run/$NAME
PIDFILE=$RUN_DIR/$NAME.pid
LOG_DIR=/var/log/passerelle
LOG_DIR=/var/log/$NAME
SCRIPTNAME=/etc/init.d/$NAME
MANAGE_SCRIPT=/usr/lib/$NAME/manage.py
SOCKFILE=$RUN_DIR/$NAME.sock
USER=$NAME
GROUP=$NAME
# Exit if the package is not installed
[ -x $DAEMON ] || exit 0
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
DAEMON_ARGS="--pid $PIDFILE \
--user $USER --group $GROUP \
--daemon \
--access-logfile $LOG_DIR/gunicorn-access.log \
--log-file $LOG_DIR/gunicorn-error.log \
--bind=unix:$SOCKFILE
--bind=unix:$SOCKFILE \
--workers=10 \
--worker-class=sync \
--timeout=60 \
--name $NAME
--name $NAME \
passerelle.wsgi:application"
# Exit if the package is not installed
[ -x $DAEMON ] || exit 0
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
@ -49,7 +50,7 @@ passerelle.wsgi:application"
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
# Create run directory (pid, sock, etc.)
# Create /run directory
if [ ! -d $RUN_DIR ]; then
install -d -m 755 -o $USER -g $GROUP $RUN_DIR
fi
@ -112,22 +113,21 @@ do_reload() {
do_migrate() {
log_action_msg "Applying new migrations .."
if [ "x$TENANT_BASE" != "x" ]; then
su $USER -p -c "python /usr/lib/$NAME/manage.py create_schema"
su $USER -p -c "python /usr/lib/$NAME/manage.py sync_schemas --noinput --traceback"
su $USER -p -c "python /usr/lib/$NAME/manage.py migrate_schemas --noinput --traceback"
su $USER -p -c "python $MANAGE_SCRIPT create_schema"
su $USER -p -c "python $MANAGE_SCRIPT sync_schemas --noinput --traceback"
su $USER -p -c "python $MANAGE_SCRIPT migrate_schemas --noinput --traceback"
else
su $USER -p -c "python /usr/lib/$NAME/manage.py syncdb --migrate --noinput"
su $USER -p -c "python $MANAGE_SCRIPT syncdb --migrate --noinput"
fi
log_action_msg ".. done"
}
do_collectstatic() {
log_action_msg "Collect static files.."
su $USER -p -c "python /usr/lib/$NAME/manage.py collectstatic --noinput"
su $USER -p -c "python $MANAGE_SCRIPT collectstatic --noinput"
log_action_msg ".. done"
}
case "$1" in
start)
log_daemon_msg "Starting $DESC " "$NAME"
@ -185,15 +185,15 @@ case "$1" in
;;
manage)
shift
if [ $(id -un) != 'passerelle' ]; then
sudo -E -H -u passerelle python /usr/lib/$NAME/manage.py "$@"
if [ $(id -un) != "$USER" ]; then
sudo -E -H -u $USER python $MANAGE_SCRIPT "$@"
else
python /usr/lib/$NAME/manage.py "$@"
python $MANAGE_SCRIPT "$@"
fi
;;
create-tenant)
shift
TENANT=`su $USER -p -c "python /usr/lib/$NAME/manage.py get_tenant_by_domain \"$1\""`
TENANT=`su $USER -p -c "python $MANAGE_SCRIPT get_tenant_by_domain \"$1\""`
log_daemon_msg "Creating tenant" "$TENANT"
if [ "x$TENANT_BASE" == "x" ]; then
log_failure_msg "TENANT_BASE is not set in /etc/default/$NAME"