Skip to content

Instantly share code, notes, and snippets.

@chengdh
Forked from shrkw/gunicorn_with_virtualenv
Last active December 31, 2015 11:48
Show Gist options
  • Save chengdh/7981572 to your computer and use it in GitHub Desktop.
Save chengdh/7981572 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# gunicorn_sr Startup script for gunicorn for sr
#
# chkconfig: - 86 14
# processname: gunicorn
# pidfile:
# description: Python application server in ubuntu
#
### BEGIN INIT INFO
# Provides: gunicorn_sr
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 3
# Default-Stop: 0 1 2 4 5 6
# Short-Description: start and stop gunicorn
### END INIT INFO
# Source function library.
#. /etc/rc.d/init.d/functions
prog=gunicorn
gunicorn_home=/home/openerp/gunicorn
APP_HOME=/home/openerp/openerp/openobject-server
APP_ROOT=$APP_HOME/current
UNICORN_CONF=$APP_ROOT/newtime-wsgi.py
lockfile=${LOCKFILE-$APP_HOME/shared/system/gunicorn.lock}
pidfile=$APP_HOME/shared/pids/gunicorn.pid
pidfile_old=${pidfile}.oldbin
RETVAL=0
##gunicorn config###
gunicorn_wsgi_app=openerp:service.wsgi_server.application
gunicorn_bind=0.0.0.0:8069
gunicorn_workers=4
errorlog=$APP_ROOT/log/gunicorn-error.log
accesslog=$APP_ROOT/log/gunicorn-access.log
loglevel=debug
timeout=50000
virtualenv_dir=/home/openerp/openerp/openobject-server/shared/virtualenv
start() {
echo -n $"Starting $prog: "
cd $APP_ROOT
. $virtualenv_dir/bin/activate
gunicorn --config $UNICORN_CONF --pid $pidfile --daemon -w $gunicorn_workers --access-logfile $accesslog --log-level $loglevel -b $gunicorn_bind $gunicorn_wsgi_app
RETVAL=$?
echo -n
[ $RETVAL = 0 ] && echo -e '[\e[32m OK \e[m]'
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
kill -QUIT $(cat ${pidfile})
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
restart() {
echo -n $"Restarting $prog: "
kill -USR2 $(cat ${pidfile})
RETVAL=$?
echo
echo -n $"Stopping old $prog: "
kill -QUIT $(cat ${pidfile_old})
RETVAL=$?
echo
}
reload() {
echo -n $"Reloading $prog: "
kill -HUP $(cat ${pidfile})
RETVAL=$?
echo
}
rh_status() {
status -p ${pidfile} ${prog}
}
# See how we were called.
case "$1" in
start)
rh_status >/dev/null 2>&1 && exit 0
start
;;
stop)
stop
;;
restart)
restart
;;
reload)
reload
;;
condrestart|try-restart)
if rh_status >/dev/null 2>&1; then
stop
start
fi
;;
status)
rh_status
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|condrestart|try-restart|status|help}"
RETVAL=2
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment