#! /bin/sh
### BEGIN INIT INFO
# Provides:          python-launcher
# Required-Start:    $local_fs
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      S 0 1 6
### END INIT INFO

set -e

DAEMON=/usr/bin/python-launcher-daemon.sh
NAME=python-launcher
DAEMONUSER=user
DAEMONGROUP=users
DESC="python-launcher daemon"

test -x $DAEMON || exit 0

start_it_up()
{
  echo -n "Starting $DESC: "
  start-stop-daemon --start \
    --chuid $DAEMONUSER --user $DAEMONUSER --exec $DAEMON
  echo "$NAME."
}

shut_it_down()
{
  echo -n "Stopping $DESC: "
  start-stop-daemon --stop --retry 60 --quiet --oknodo --name python-launcher \
    --user $DAEMONUSER
  echo "$NAME."
}

case "$1" in
  start)
    start_it_up
  ;;
  stop)
    shut_it_down
  ;;
  restart)
    shut_it_down
    sleep 1
    start_it_up
  ;;
  *)
    echo "Usage: /etc/init.d/$NAME {start|stop|restart}" >&2
    exit 1
  ;;
esac

exit 0
