#!/bin/sh
#
# uwsgi - this script starts and stops the uwsgi daemon
#
# chkconfig: - 85 15
# processname: uwsgi
# config: /etc/uwsgi.yaml
# config: /etc/sysconfig/uwsgi
# pidfile: /var/run/uwsgi.pid
# description: uwsgi is a WSGI server
#

# Source function library.
. /etc/rc.d/init.d/functions

CONFFILE="/etc/uwsgi.yaml"

if [ -f /etc/sysconfig/uwsgi ]; then
        . /etc/sysconfig/uwsgi
fi

prog=uwsgi
uwsgi=${NGINX-/usr/bin/uwsgi}
conffile=${CONFFILE-/etc/uwsgi.yaml}
lockfile=${LOCKFILE-/var/lock/subsys/uwsgi}
pidfile=${PIDFILE-/var/run/uwsgi.pid}
RETVAL=0

start() {
    echo -n $"Starting $prog: "

    #daemon --pidfile=${pidfile} ${uwsgi} --yaml ${conffile}
    daemon ${uwsgi} --yaml ${conffile} --pidfile ${pidfile}
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && touch ${lockfile}
    return $RETVAL
}

stop() {
    echo -n $"Stopping $prog: "
    killproc -p ${pidfile} ${prog} -INT
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
        status -p ${pidfile} ${uwsgi}
	RETVAL=$?
	;;
  restart)
	stop
	start
	;;
  *)
	echo $"Usage: $prog {start|stop|restart|status}"
	RETVAL=2
esac

exit $RETVAL
