Skip to content

Instantly share code, notes, and snippets.

@abn
Created November 15, 2013 07:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abn/7480636 to your computer and use it in GitHub Desktop.
Save abn/7480636 to your computer and use it in GitHub Desktop.
uwsgi control script for OpenShift
#!/bin/bash -e
# This assumes that your openshift repo contains a uwsgi.ini
# configuration file.
# This is a extracted from a script used live for the victims project:
# https://github.com/victims/victims-server-openshift/blob/master/bin/control
source $OPENSHIFT_CARTRIDGE_SDK_BASH
# Setup globals
LOG_PREFIX="[python-uwsgi-control]"
# activate virtenv
echo "$LOG_PREFIX Activating virtenv ..."
source ${OPENSHIFT_PYTHON_DIR}/virtenv/bin/activate
UWSGI_PIDFILE=${OPENSHIFT_PYTHON_DIR}/run/uwsgi.pid
CONFIGFILE=${OPENSHIFT_REPO_DIR}/uwsgi.ini
function stop()
{
if [ -f "$UWSGI_PIDFILE" ]; then
echo "$LOG_PREFIX Stopping uWSGI"
uwsgi --stop "$UWSGI_PIDFILE"
rm "$UWSGI_PIDFILE"
else
echo "$LOG_PREFIX No running UWSGI process"
fi
}
function start()
{
if [ -f "$UWSGI_PIDFILE" ]; then
echo "$LOG_PREFIX uWSGI already running"
else
echo "$LOG_PREFIX Starting UWSGI"
uwsgi "${CONFIGFILE}"
fi
}
function restart()
{
echo "$LOG_PREFIX Restarting uWSGI"
stop
# wait till all workers are burried
sleep 2
start
}
case $1 in
start) start ;;
stop) stop ;;
restart) restart ;;
reload) restart ;;
*) exec $OPENSHIFT_PYTHON_DIR/bin/control "$@"
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment