Skip to content

Instantly share code, notes, and snippets.

@zodman
Created August 1, 2012 17:17
Show Gist options
  • Save zodman/3228942 to your computer and use it in GitHub Desktop.
Save zodman/3228942 to your computer and use it in GitHub Desktop.
uwsgi init script
#!/bin/bash
# uwsgi - Use uwsgi to run python and wsgi web apps.
#
# chkconfig: - 85 15
# description: Use uwsgi to run python and wsgi web apps.
# processname: uwsgi
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/bin/uwsgi-2.7
OWNER=root
NAME=projectname
DESC=projectname
test -x $DAEMON || exit 0
set -e
get_pid() {
if [ -f /var/run/$NAME.pid ]; then
echo `cat /var/run/$NAME.pid`
fi
}
DAEMON_OPTS=" --uid www-data --gid desarrolloweb -x /export/web/$NAME/uwsgi.xml -d /var/log/uwsgi/$NAME.log --pidfile /var/run/$NAME.pid "
case "$1" in
start)
echo -n "Starting $DESC: "
PID=$(get_pid)
if [ -z "$PID" ]; then
[ -f /var/run/$NAME.pid ] && rm -f /var/run/$NAME.pid
touch /var/run/$NAME.pid
chown $OWNER /var/run/$NAME.pid
su - $OWNER -pc "$DAEMON $DAEMON_OPTS"
echo "$NAME."
fi
;;
stop)
echo -n "Stopping $DESC: "
PID=$(get_pid)
echo $PID
[ ! -z "$PID" ] && kill -s 3 $PID &> /dev/null
if [ $? -gt 0 ]; then
echo "was not running"
exit 1
else
echo "$NAME."
echo "doing rm"
rm -f /var/run/$NAME.pid &> /dev/null
fi
;;
reload)
echo "Reloading $NAME"
PID=$(get_pid)
[ ! -z "$PID" ] && kill -s 1 $PID &> /dev/null
if [ $? -gt 0 ]; then
echo "was not running"
exit 1
else
echo "$NAME."
rm -f /var/run/$NAME.pid &> /dev/null
fi
;;
force-reload)
echo "Reloading $NAME"
PID=$(get_pid)
[ ! -z "$PID" ] && kill -s 15 $PID &> /dev/null
if [ $? -gt 0 ]; then
echo "was not running"
exit 1
else
echo "$NAME."
rm -f /var/run/$NAME.pid &> /dev/null
fi
;;
restart)
$0 stop
sleep 2
$0 start
;;
status)
#killall -10 $DAEMON
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment