#!/bin/sh
### BEGIN INIT INFO
# Provides:          glewlwyd
# Required-Start:    $network $time
# Required-Stop:     $network $time
# Should-Start:
# Should-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Starts the glewlwyd daemon
# Description:
### END INIT INFO

user=pi
group=pi
prefix=/usr/bin
exec_prefix=${prefix}
glewlwyd=${prefix}/glewlwyd
glewlwydconf=--config=/etc/glewlwyd.conf
pidfile=/var/run/glewlwyd.pid

case "$1" in
  stop)
    echo -n "Stopping Glewlwyd "
    start-stop-daemon --stop --pidfile $pidfile
    echo "OK"
    ;;

  start)
    echo -n "Starting Glewlwyd "
    touch $pidfile
    chown $user:$group $pidfile
    start-stop-daemon --start --quiet --make-pidfile --pidfile $pidfile \
      --chuid $user:$group --background --exec $glewlwyd -- $glewlwydconf
    echo "OK"
    ;;

  restart)
    $0 stop
    $0 start
    ;;

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