#!/bin/sh

### BEGIN INIT INFO
# Provides:          parental-control-web
# Required-Start:    $all
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:
# Short-Description: Allows to control weekly schelule of users and spent time in the system
### END INIT INFO

# Quick start-stop-daemon example, derived from Debian /etc/init.d/ssh
set -e

# Must be a valid filename
NAME=parental-control-web
PIDFILE=/var/run/$NAME.pid
#This is the command to be run, give the full pathname
DAEMON=/usr/bin/$NAME
DAEMON_OPTS="-c /etc/parental-control/config.yml"

export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"

case "$1" in
  start)
    echo -n "Starting daemon: "$NAME
    start-stop-daemon --start --user nobody --background --make-pidfile --remove-pidfile --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_OPTS
    echo "."
    ;;
  stop)
    echo -n "Stopping daemon: "$NAME
    start-stop-daemon --stop --signal TERM --quiet --oknodo --remove-pidfile --pidfile $PIDFILE
    echo "."
    ;;
  restart)
    echo -n "Restarting daemon: "$NAME
    start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile $PIDFILE
    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_OPTS
    echo "."
    ;;

  *)
    echo "Usage: "$1" {start|stop|restart}"
    exit 1
esac

exit 0
