Created
July 11, 2013 13:02
-
-
Save meteozond/5975253 to your computer and use it in GitHub Desktop.
Non-safe init.d script
This file contains hidden or 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/sh | |
NAME='example.com' | |
USER='example_user' | |
PROJDIRPRE="/sites/" | |
PYTHON="/sites/envs/project/bin/python" | |
SAFE_NAME=`echo "$NAME" | sed 's/\./_/g'` | |
PROJDIR="$PROJDIRPRE/$SAFE_NAME" | |
PIDFILE="/tmp/$SAFE_NAME.pid" | |
SOCKET="/tmp/$SAFE_NAME.sock" | |
case "$1" in | |
restart) | |
$0 stop $NAME | |
$0 start $NAME | |
;; | |
start) | |
echo "Starting $NAME server..." | |
if [ -f $PIDFILE ]; then | |
$0 stop $NAME | |
fi | |
su -l $USER -c "$PYTHON $PROJDIR/manage.py runfcgi method=prefork maxspare=30 socket=$SOCKET pidfile=$PIDFILE" | |
chmod a+w $SOCKET | |
;; | |
stop) | |
PID=`cat $PIDFILE` | |
kill $PID | |
while [ -x /proc/${PID} ] | |
do | |
echo "Waiting for $NAME to shutdown ..." | |
sleep 1 | |
done | |
echo "$NAME stopped" | |
unlink $PIDFILE; | |
unlink $SOCKET; | |
;; | |
*) | |
echo "Usage: $THIS {start|stop|restart}" >&2 | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment