Created
December 20, 2010 12:38
-
-
Save suda/748335 to your computer and use it in GitHub Desktop.
Gunicorn init.d script (gentoo)
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
#!/sbin/runscript | |
# Gunicorn init.d script for gentoo | |
# Written by Wojtek 'suda' Siudzinski <[email protected]> | |
# Gist: https://gist.github.com/748335 | |
# | |
# Sample config (/etc/conf.d/gunicorn): | |
# | |
# SERVERS=( | |
# 'server_name port project_path number_of_workers' | |
# ) | |
# RUN_AS='www-data' | |
# | |
# WARNING: user $RUN_AS must have +w on /var/run/gunicorn | |
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | |
DAEMON=/usr/bin/gunicorn_django | |
NAME=gunicorn | |
DESC=gunicorn | |
SERVER="$2" | |
if [ ! -d /var/run/gunicorn ]; then | |
mkdir /var/run/gunicorn | |
fi | |
depend() { | |
need net | |
} | |
start() { | |
ebegin "Starting gunicorn" | |
for i in "${SERVERS[@]}" | |
do | |
: | |
set -- "$i" | |
IFS=" "; declare -a data=($*) | |
echo "Spawning ${data[0]}" | |
start-stop-daemon --start --pidfile /var/run/gunicorn/${data[0]}.pid -c $RUN_AS -d ${data[2]} --exec $DAEMON -- -b 127.0.0.1:${data[1]} -w ${data[3]} -D -p /var/run/gunicorn/${data[0]}.pid | |
done | |
eend $? | |
} | |
stop() { | |
ebegin "Stoping gunicorn" | |
for i in "${SERVERS[@]}" | |
do | |
: | |
set -- "$i" | |
IFS=" "; declare -a data=($*) | |
if [ -f /var/run/gunicorn/${data[0]}.pid ]; then | |
echo "Killing ${data[0]}" | |
kill $(cat /var/run/gunicorn/${data[0]}.pid) | |
fi | |
done | |
eend $? | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment