#!/bin/sh
#
# chkconfig: 2345 55 25
# description: Starts the NPAD server
#
# This file is auto-generated by config.py in the NPAD server distribution.
# It is a general init script for starting the NPAD server daemon.  It does
# not use distribution-specific init functions.  You may want to customize
# this if they are important to you.

DIAG_SERVER_DAEMON=/opt/npad/DiagServer.py
USER=npad
PIDFILE=/var/run/npad.pid
DIAG_SERVER_OPTS="-d -u $USER -p $PIDFILE"

start() {
	if [ -f $PIDFILE ]; then
		pid=`cat $PIDFILE`
		if [ "`ps -p $pid -o comm=`" = "DiagServer.py" ]; then
			echo "NPAD server already running, not starting."
			exit 1
		fi
	fi
	${DIAG_SERVER_DAEMON} ${DIAG_SERVER_OPTS}
	echo "NPAD server started."
}

stop() {
	if [ -f $PIDFILE ]; then
		pid=`cat $PIDFILE`
		if [ "`ps -p $pid -o comm=`" = "python" ]; then
			kill $pid
			rm $PIDFILE
			exit 0
		fi
	fi
	exit 1
}

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

exit 0

