Skip to content

Instantly share code, notes, and snippets.

@hqman
Created March 13, 2012 03:53
Show Gist options
  • Save hqman/2026631 to your computer and use it in GitHub Desktop.
Save hqman/2026631 to your computer and use it in GitHub Desktop.
manage process gunicorn_paster on ubuntu
#!/bin/bash
### BEGIN INIT INFO
# Provides: manage process gunicorn_paster
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: $gunicorn_paster
# Should-Stop: $gunicorn_paster
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start gunicorn_paster.
# Description: Start gunicorn_paster.
### END INIT INFO
BASE_PATH='/home/hqman/projects/pydev'
NAME='meside'
APP_HOME=$BASE_PATH/$NAME
APP_BIN=$BASE_PATH/bin
DAEMON=$APP_BIN/gunicorn_paster
PIDFILE=$APP_HOME/$NAME.pid
#need sudo user
#if [ `id -u` -ne 0 ]; then
# echo "You need root or sudo privileges to run this script"
# exit 1
#fi
start_app() {
if [ -e $PIDFILE ]; then
echo "meside is running"
return 1
fi
cd $BASE_PATH
source bin/activate
echo "start $NAME"
start-stop-daemon --start --pidfile $PIDFILE --exec $DAEMON -- -b 127.0.0.1:8000 -D $APP_HOME/development.ini -p $PIDFILE
}
stop_app() {
echo "stop meside"
if [ -f $PIDFILE ]; then
echo "Killing $NAME"
kill $(cat $PIDFILE )
fi
}
case "$1" in
start)
start_app
;;
stop)
stop_app
;;
restart)
stop_app
sleep 2
start_app
;;
*)
echo ' * Usage: gunicornctl {start|stop|restart}'
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment