#!/bin/bash
### BEGIN INIT INFO
# Provides:          tweet-django
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: tweet-django daemon
# Description:       tweet-django background stream daemon
### END INIT INFO

set -e

daemon="/usr/share/tweet-django/runstream.py"
pidfile="$APPDIR/emperor.pidfile"

. /lib/lsb/init-functions

case "$1" in
    start)
        echo "Starting uwsgi"
        start-stop-daemon --background --chuid www-data:www-data --make-pidfile --pidfile $pidfile --start --exec $daemon
        ;;
    stop)
        echo "Stopping script uwsgi"
        start-stop-daemon --retry 5 --remove-pidfile --pidfile $pidfile --stop $daemon
        ;;
    restart|force-reload)
        start
        stop
        ;;
    status)
        status_of_proc $daemon tweet-django
        ;;
    *)
        echo "Usage: /etc/init.d/uwsgi {start|stop|restart|force-reload}"
        exit 1
    ;;
esac
exit 0
