#!/bin/sh
#
# Startup script for the TSDB MOC-side queue daemon, TSDBLocalQueue.pl.
#
# description: TSDB local queue daemon
# processname: TSDBLocalQueue.pl
# pidfile: /var/run/TSDBLocalQueue.pid

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

bin=/usr/bin
var=/var/log/nocpulse

# Make sure we're in a directory readable by nocpulse
cd /tmp

# See how we were called.
case "$1" in
  start)
	echo -n "Starting TSDBLocalQueue: "
        /sbin/runuser - nocpulse -c ${bin}/TSDBLocalQueue.pl >>${var}/TSDBLocalQueue-errors.log 2>&1 &
        echo $! > /var/run/TSDBLocalQueue.pid
	touch /var/lock/subsys/TSDBLocalQueue
	echo_success
	echo
	;;
  stop)
	echo -n "Shutting down TSDBLocalQueue: "
	killproc TSDBLocalQueue
	echo
	rm -f /var/run/TSDBLocalQueue.pid
	rm -f /var/lock/subsys/TSDBLocalQueue
	;;
  status)
        proc=TSDBLocalQueue
        pid=`pidofproc $proc`
        if [ ! -z "$pid" ]; then
            if ps h $pid>/dev/null 2>&1; then
                echo "$proc (pid $pid) is running..."
                exit 0
            else
                echo "$proc dead but pid file exists"
            fi
            exit 1
        fi
	if [ -f /var/lock/subsys/$proc ]; then
            echo "$proc dead but subsys locked"
            exit 2
	fi
	echo "$proc is stopped"
	exit 3
	;;
  restart)
	$0 stop
	$0 start
	;;
  *)
	echo "Usage: $0 {start|stop|restart|status}"
	exit 1
esac

exit 0
