#!/bin/bash

### BEGIN INIT INFO
# Provides: cronosagent
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start cronosagent at boot time
# Description: CronosAgent for BrandMeister DMR Server
### END INIT INFO

NAME="CronosAgent"
DIRECTORY="/opt/$NAME"

DAEMON="$DIRECTORY/cronosagent.sh"
ARGUMENTS="6"

USER=cronos
GROUP=cronos

[ -f $DAEMON ] || exit 0

start () {
        echo -n "Starting $NAME: "
        start-stop-daemon --start --exec $DAEMON --chuid $USER:$GROUP --chdir $DIRECTORY -- $ARGUMENTS
        RETVAL=$?
        echo
        return $RETVAL
}

stop () {
        echo -n "Stopping $NAME: "
        start-stop-daemon --stop --retry 5 --exec $DAEMON
        RETVAL=$?
        echo
}

case "$1" in
        start)
                start
        ;;
        stop)
                stop
        ;;
        restart)
                stop
                start
        ;;
        status)
                status_of_proc $DAEMON $NAME
        ;;
        *)
                echo "Usage: $0 {start|stop|restart|status}"
                exit 1
esac

exit 0