#!/bin/bash

. /bin/network-functions

PIDFILE=/var/run/restclient.pid

SERVICE=restclient
PROCESS_NAME=restclient

do_start ()
{
	if ! ServiceCheckRunning1 ; then
		return $?
	fi

	# check if config is there or not empty... if not.. copy it from default-conf
	if [ ! -f /etc/fiad-conf/restclient.cfg ] || [ ! -s /etc/fiad-conf/restclient.cfg ]; then
	  cp -f /etc/default-conf/restclient.cfg /etc/fiad-conf/restclient.cfg
	fi

	echo -n $"Starting restclient service: "
	/bin/setsid /bin/$PROCESS_NAME > /dev/null 2>&1 &
	echo $! > $PIDFILE

	ServiceCheckRunning2
	return $?
}

do_stop ()
{
	/etc/init.d/softdogd wait
	echo -n $"Shut down restclient service: "
	ServiceStop
	return $?
}

do_status ()
{
	ServiceStatus
	return $?
}

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

exit $?
