# !/bin/sh # ### BEGIN INIT INFO # Provides: uwsgi # Required-Start: $network # Required-Stop: $network # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: uwsgi application server ### END INIT INFO # Author: Alex J. Crowe DESC="uwsgi emperor daemon" NAME="uwsgi" DAEMON="/usr/local/bin/uwsgi" DAEMON_AGRS="--ini /etc/uwsgi/emperor.ini" SCRIPTNAME=/etc/init.d/$NAME PIDFILE="/var/run/uwsgi/emperor.pid" RUNDIR="/var/run/uwsgi" [ -x "$DAEMON" ] || exit 0 if [ ! -d "$RUNDIR" ] then mkdir "$RUNDIR" chown root:www-data "$RUNDIR" chmod 770 "$RUNDIR" fi running_pid() { # Check if a given process pid's cmdline matches a given name pid=$1 name=$2 [ -z "$pid" ] && return 1 [ ! -d /proc/$pid ] && return 1 (cat /proc/$pid/cmdline | tr "\000" "\n"|grep -q $name) || return 1 return 0 } running() { # Check if the process is running looking at /proc # (works for all users) # No pidfile, probably no daemon present [ ! -f "$PIDFILE" ] && return 1 # Obtain the pid and check it against the binary name pid=`cat $PIDFILE` running_pid $pid $DAEMON || return 1 return 0 } start() { if [ -e $PIDFILE ]; then echo "$DESC - already running with pid: `cat $PIDFILE`" exit 0 fi $DAEMON --ini /etc/uwsgi/emperor.ini } stop() { if [ -f $PIDFILE ]; then kill `cat $PIDFILE` rm $PIDFILE else echo "PID not found at $PIDFILE exiting" exit 1 fi } case "$1" in start) echo "Starting $DESC" start ;; stop) echo "Stopping $DESC" stop ;; status) echo -n "$DESC is " if running ; then echo "running" else echo "not running." exit 1 fi ;; restart) stop sleep 5 start exit 0 ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2 exit 3 ;; esac exit 0