uwsgi-DEB-dist 1.8 KB
#!/bin/sh
### BEGIN INIT INFO
# Provides: uwsgi
# Required-Start: $network $remote_fs $local_fs
# Required-Stop: $network $remote_fs $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Use uwsgi to run python and wsgi web apps.
### END INIT INFO

PATH=/opt/uwsgi:/sbin:/bin:/usr/sbin:/usr/bin

DAEMON="<UWSGI_VE32_PATH>/bin/uwsgi"
NAME=uwsgi
DESC=uwsgi

test -x $DAEMON || exit 0

# Include uwsgi defaults if available.
if [ -f /etc/default/uwsgi ] ; then
    . /etc/default/uwsgi
fi

set -e

DAEMON_OPTS="--ini <UWSGI_VE32_PATH>/src/uWSGI/production.ini"

case "$1" in
    start)
        echo -n "Starting $DESC: "
        sleep 2
        start-stop-daemon --start --exec $DAEMON -- $DAEMON_OPTS
        echo "$NAME."
    ;;
    stop)
        echo -n "Stopping $DESC: "
        start-stop-daemon --signal 3 --retry 2 --stop \
                --exec $DAEMON
        echo "$NAME."
    ;;
    restart)
        echo -n "Restarting $DESC: "
        # NOTE: O comando "set +e" é necessário para que caso o serviço já 
        # esteja parado o comando "start-stop-daemon" não faça o script de 
        # inicialização parar! By Questor
        set +e
        start-stop-daemon --signal 3 --retry 2 --stop \
                --exec $DAEMON
        RETVAL="$?"
        # RETVAL:
        #   0 if daemon has been stopped;
        #   1 if daemon was already stopped;
        #   2 if daemon could not be stopped;
        #   other if a failure occurred.
        if [ ${RETVAL} -eq 0 ] || [ ${RETVAL} -eq 1 ] ; then
            sleep 1
            start-stop-daemon --start --exec $DAEMON -- $DAEMON_OPTS
            echo "$NAME."
        fi
    ;;
    status)
        killall -10 $DAEMON
    ;;
    *)
        N=/etc/init.d/$NAME
        echo "Usage: $N {start|stop|restart|status}" >&2
        exit 1
    ;;
esac
exit 0