#! /bin/sh
#
# Start or stop the spong system monitoring client
#

test -x /usr/sbin/spong-client || exit 0

# Change /etc/default/spong-client in order to start spong-client/-network
. /etc/default/spong-client

CLIENTPID=/var/run/spong/spong-client.pid
NETWORKPID=/var/run/spong/spong-network.pid

case "$1" in
	start)

              if [ "$run_client" = 1 -o "$run_network" = 1 ]; then

               echo -n 'Starting spong client programs:'

               if [ "$run_client" = 1 ]; then
                echo -n ' spong-client'
		start-stop-daemon --start --quiet --pidfile $CLIENTPID \
			--chuid spong --exec /usr/sbin/spong-client
               fi

               if [ "$run_network" = 1 ]; then
                echo -n ' spong-network'
		start-stop-daemon --start --quiet --pidfile $NETWORKPID \
			--chuid spong --exec /usr/sbin/spong-network
               fi 

               echo '.'

              fi

		;;
	stop)

              if [ "$run_client" = 1 -o "$run_network" = 1 ]; then

               echo -n 'Stopping spong client programs:'

               if [ "$run_client" = 1 ]; then
                echo -n ' spong-client'
		start-stop-daemon --stop --quiet --pidfile $CLIENTPID
               fi

               if [ "$run_network" = 1 ]; then
                echo -n ' spong-network'
		start-stop-daemon --stop --quiet --pidfile $NETWORKPID
               fi

               echo '.'

              fi

		;;
	restart)

              /etc/init.d/spong-client stop
              /etc/init.d/spong-client start

		;;
	reload|force-reload)

              if [ "$run_client" = 1 -o "$run_network" = 1 ]; then

               echo -n 'Reloading spong client programs:'

               if [ "$run_client" = 1 ]; then
                echo -n ' spong-client'
		start-stop-daemon --stop --quiet --signal 1 \
                --pidfile $CLIENTPID
               fi

               if [ "$run_network" = 1 ]; then
                echo -n ' spong-network'
		start-stop-daemon --stop --quiet --signal 1 \
                --pidfile $NETWORKPID
               fi

               echo '.'

              fi
		;;
	*)
		echo "Usage: /etc/init.d/spong-client {start|stop|restart}"
		exit 1 
esac

exit 0
