Skip to content

Instantly share code, notes, and snippets.

@caseydunham
Created April 1, 2015 19:44
Show Gist options
  • Save caseydunham/b1ae7d8644585827bdee to your computer and use it in GitHub Desktop.
Save caseydunham/b1ae7d8644585827bdee to your computer and use it in GitHub Desktop.
Simple uWSGI CentOS 6 Init Script
#!/bin/bash
#
# uwsgi - This script starts and stops all configured uwsgi applications
#
# chkconfig: - 85 15
# description: uWSGI is a program to run applications adhering to the
# Web Server Gateway Interface.
# processname: uwsgi
# config: /etc/sysconfig/uwsgi
# pidfile: /var/run/uwsgi.pid
#
### BEGIN INIT INFO
# Provides: uwsgi
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Short-Description: start and stop uwsgi
### END INIT INFO
# Source function library
. /etc/rc.d/init.d/functions
if [ -L $0 ]; then
initscript=`/bin/readlink -f $0`
else
initscript=$0
fi
sysconfig=`/bin/basename $initscript`
if [ -f /etc/sysconfig/$sysconfig ]; then
. /etc/sysconfig/$sysconfig
fi
uwsgi=${UWSGI-/usr/sbin/uwsgi}
prog=`/bin/basename $uwsgi`
lockfile=${LOCKFILE-/var/lock/subsys/uwsgi}
pidfile=${PIDFILE-/var/run/uwsgi.pid}
RETVAL=0
start() {
echo -n $"Starting $prog: "
daemon ${uwsgi} --pidfile ${pidfile} ${UWSGI_OPTIONS}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} ${prog}
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -rf ${lockfile} ${pidfile}
}
reload() {
echo -n $"Reloading $prog"
killproc -p ${pidfile} ${prog} -HUP
RETVAL=$?
echo
}
rh_status() {
status -p ${pidfile} ${uwsgi}
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
rh_status
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status}"
RETVAL=2
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment