#! /bin/bash
#
# chkconfig: 2345 9 91
# description: start and stop imaging-fwcld services
#

### BEGIN INIT INFO
# Provides:          fw-imaging-client
# Required-Start:    $local_fs $network $named $time $syslog
# Required-Stop:     $local_fs $network $named $time $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Description:       Start and stop imaging-fwcld services
### END INIT INFO

PATH=/bin:/sbin:/usr/bin:/usr/sbin

. /lib/lsb/init-functions
set +e # again, because init-functions disables it

function start()
{
	procCount=`pidof fwcld | wc -w`
	if [ ! $procCount -eq 0 ]; then
		echo "The FileWave Client is already started -- $procCount fwxcld processes running."
		return
	fi

	# makes it possible to generate core files
	#ulimit -c unlimited
	#Start the Client
	/usr/local/sbin/fwcld --imaging &>/dev/null &

	log_success_msg "Starting FileWave Client"
}


function stop()
{
	killproc fwcld &>/dev/null

	if [ -f "/var/run/fwcld.pid" ]; then
		echo "removing old .pid file"
		rm /var/run/fwcld.pid
	fi

	log_success_msg "Stopping FileWave Client"
	return 0
}

function restart()
{
    stop
    start
}

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

exit 0
