#!/bin/sh

DESC="loldongs"
EXEC="/usr/bin/loldongs"
PIDFILE="/var/run/loldongs.pid"

if [ -f /etc/osso-af-init/af-defines.sh ]; then
    . /etc/osso-af-init/af-defines.sh
fi

start_loldongs()
{
    start-stop-daemon --start --pidfile $PIDFILE \
        --background --make-pidfile --startas $EXEC
}

stop_loldongs()
{
    # this should use start-stop-daemon --stop at some point
    if ! [ -f $PIDFILE ]; then
        echo "$DESC not running"
    else
        kill `cat $PIDFILE`
        rm $PIDFILE
    fi
}

case "$1" in
start)
    echo "Starting $DESC..."
    start_loldongs
;;
stop)
    echo "Stopping $DESC..."
    stop_loldongs
;;
restart)
    echo "Stopping $DESC..."
    stop_loldongs
    echo "Starting $DESC..."
    start_loldongs
;;
*)
    echo "usage: $0 (start|stop|restart)"
;;
esac

exit 0
