#!/bin/sh
#
# Tandberg Television Alert Server Control Script

### BEGIN INIT INFO
# X-UnitedLinux-Should-Start: $network
# Provides: alerts
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Description: WatchPoint Alerts Server
### END INIT INFO

status() {
	pid=$(ps axww | grep "[o]rg.openorb.ins.Server" | sed -e 's/^\s*//' | cut -d' ' -f1)
	if [ -z "${pid}" ] ; then
		echo "nameservice is stopped"
	else
		echo "nameservice (pid " $pid") is running..."
	fi

	pid=$(ps axww | grep "[c]om.n2bb.SSModule.SettingsServer" | sed -e 's/^\s*//' | cut -d' ' -f1)
	if [ -z "${pid}" ] ; then
		echo "settings server is stopped"
	else
		echo "settings server (pid " $pid") is running..."
	fi

	pid=$(ps axww | grep "[c]om.n2bb.AlertsModule.AlertServer" | sed -e 's/^\s*//' | cut -d' ' -f1)
	if [ -z "${pid}" ] ; then
		echo "alerts is stopped"
	else
		echo "alerts (pid " $pid") is running..."
	fi
}

case "$1" in
start)
	pid=$(ps axww | grep "[c]om.n2bb.AlertsModule.AlertServer" | sed -e 's/^\s*//' | cut -d' ' -f1)
	if [ -z "${pid}" ] ; then
		/usr/local/n2bb/alerts/scripts/NameService_OpenORB $1 >/dev/null 2>&1
		/usr/local/n2bb/SettingsServer/scripts/SettingsServer $1 >/dev/null 2>&1
		/usr/local/n2bb/alerts/scripts/Alerts $1 >/dev/null 2>&1
	else
		echo "alerts is already running..."
	fi
	;;
stop)
	/usr/local/n2bb/alerts/scripts/Alerts $1 >/dev/null 2>&1
	/usr/local/n2bb/SettingsServer/scripts/SettingsServer $1 >/dev/null 2>&1
	/usr/local/n2bb/alerts/scripts/NameService_OpenORB $1 >/dev/null 2>&1
	;;
status)
	status
	;;
restart)
    $0 stop
    $0 start
    ;;
*)
	echo "Usage: $0 {start | stop | status | restart}"
	;;
esac

