#!/bin/sh
### BEGIN INIT INFO
# Provides:          noc
# Required-Start:    $local_fs $remote_fs postgreqsl mongodb
# Required-Stop:     $local_fs $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      S 0 1 6
# Short-Description: noc initscript
# Description:       noc
### END INIT INFO

# First reset status of this service
. /etc/rc.status
rc_reset

# Return values acc. to LSB for all commands but status:
# 0 - success
# 1 - generic or unspecified error
# 2 - invalid or excess argument(s)
# 3 - unimplemented feature (e.g. "reload")
# 4 - insufficient privilege
# 5 - program is not installed
# 6 - program is not configured
# 7 - program is not running


PREFIX=/opt/noc
LAUNCHER=./scripts/noc-launcher.py

if [ ! -d ${PREFIX} ]; then
  echo -n "NOC not installed!"
  rc_status -s
  exit 5
fi

cd $PREFIX

case "$1" in
    start)
        echo -n "Starting noc-launcher"
        $LAUNCHER start
        rc_status -v
        ;;
    stop)
        echo -n "Stopping noc-launcher"
        $LAUNCHER stop
        rc_status -v
        ;;
    restart)
        $0 stop
        $0 start
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
        ;;
esac
rc_exit

