#!/bin/bash
#
# Init file for perfSONAR perfSONAR-BUOY BWCTL Collection Service
#
# chkconfig: 2345 65 20
# description: perfSONAR perfSONAR-BUOY BWCTL Collection Service
#

TOOL="perfSONAR perfSONAR-BUOY BWCTL Collection Service"
PREFIX=/opt/perfsonar_ps/perfsonarbuoy_ma
CONF_PREFIX=${PREFIX}/etc
TOOL_EXE=${PREFIX}/bin/bwcollector.pl

cmd="$TOOL_EXE -c $CONF_PREFIX "

case "$1" in
start)
        [ -x $TOOL_EXE ] && $cmd && echo 'perfSONAR-BUOY BWCTL Measurement Collector Daemon Started'
	if [ $? != 0 ]; then
		echo "Couldn't start perfSONAR-BUOY BWCTL Measurement Collector Daemon"
        else
            touch /var/lock/subsys/perfsonarbuoy_bw_collector
	fi
        ;;
stop)
        [ -x $TOOL_EXE ] && $cmd -k && echo 'perfSONAR-BUOY BWCTL Measurement Collector Daemon Stopped'
	if [ $? != 0 ]; then
		echo "Couldn't stop perfSONAR-BUOY BWCTL Measurement Collector Daemon"
        else
            rm /var/lock/subsys/perfsonarbuoy_bw_collector
	fi
        ;;
restart)
	# try a HUP, and then kill/start if not
        [ -x $TOOL_EXE ] && $cmd -h && echo 'perfSONAR-BUOY BWCTL Measurement Collector Daemon Restarted'
	if [ $? != 0 ]; then
        	[ -x $TOOL_EXE ] && $cmd -k && echo 'perfSONAR-BUOY BWCTL Measurement Collector Daemon Stopped'
        	[ -x $TOOL_EXE ] && $cmd && echo 'perfSONAR-BUOY BWCTL Measurement Collector Daemon Started'

		if [ $? != 0 ]; then
			echo "Couldn't start perfSONAR-BUOY BWCTL Measurement Collector Daemon"
                else
                    touch /var/lock/subsys/perfsonarbuoy_bw_collector
		fi
	fi

        ;;
*)
        echo "Usage: `basename $0` {start|stop}" >&2
        ;;
esac

exit 0
