Created
December 21, 2015 14:13
-
-
Save roramirez/698bbdeac00574ab9e11 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
# idea: https://www.linode.com/docs/websites/nginx/wsgi-using-uwsgi-and-nginx-on-centos-5 | |
PATH=/sbin:/bin:/usr/sbin:/usr/bin | |
DAEMON=/usr/bin/uwsgi | |
OWNER=uwsgi | |
NAME=uwsgi | |
DESC=uwsgi | |
UWSGI_EMPEROR_MODE=true | |
UWSGI_VASSALS="/etc/uwsgi/" | |
test -x $DAEMON || exit 0 | |
# Include uwsgi defaults if available | |
if [ -f /etc/default/uwsgi ] ; then | |
. /etc/default/uwsgi | |
fi | |
set -e | |
get_pid() { | |
if [ -f /var/run/$NAME.pid ]; then | |
echo `cat /var/run/$NAME.pid` | |
fi | |
} | |
DAEMON_OPTS="-s 127.0.0.1:9001 -d /var/log/uwsgi.log --pidfile /var/run/$NAME.pid" | |
if [ "$UWSGI_EMPEROR_MODE" = "true" ] ; then | |
DAEMON_OPTS="$DAEMON_OPTS --emperor $UWSGI_VASSALS" | |
fi | |
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 | |
$DAEMON $DAEMON_OPTS | |
#su - $OWNER -pc "$DAEMON $DAEMON_OPTS" | |
echo "$NAME." | |
fi | |
;; | |
stop) | |
echo -n "Stopping $DESC: " | |
PID=$(get_pid) | |
[ ! -z "$PID" ] && kill -s 3 $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 | |
;; | |
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