#!/bin/bash
#
# noc	Startup script for the noc noc-launcher.

# chkconfig: - 88 11
# description: NOC Project is an Operation Support System
# processname: noc-launcher.py
# config:  /etc/noc/noc.conf
# pidfile: /var/run/noc/noc.pid

### BEGIN INIT INFO
# Provides:          noc
# Required-Start:    $remote_fs
# Should-Start:      $network
# Required-Stop:     $remote_fs
# Should-Stop:       $network
# Default-Start:     3 5
# Default-Stop:
# Short-Description: NOC project
# Description:       Starts NOC project daemons
### END INIT INFO

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

# Source function library.
. /etc/init.d/functions

NOC_CONFIG=/etc/sysconfig/noc
CONFIGFILE=/etc/noc/noc.conf
PIDFILE=/var/run/noc/noc-launcher.pid
LOCKFILE=/var/lock/subsys/noc
RETVAL=0

SourceIfNotEmpty $NOC_CONFIG
# Read config
. $NOC_CONFIG
NOC_LAUNCHER_BIN=$NOC_PREFIX/scripts/noc-launcher.py

start()
{
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --name noc --displayname noc -- python $NOC_LAUNCHER_BIN start
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --displayname noc -- python $NOC_LAUNCHER_BIN stop
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

reload()
{
	msg_reloading noc
	stop_daemon --displayname noc  --pidfile "$PIDFILE" -HUP -- python $NOC_LAUNCHER_BIN
	RETVAL=$?
	return $RETVAL
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	reload)
		reload
		;;
	restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	condreload)
		if [ -e "$LOCKFILE" ]; then
			reload
		fi
		;;
	status)
		status --displayname noc --pidfile "$PIDFILE" -- python $NOC_LAUNCHER_BIN
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
