#!/bin/sh
#
#     Startup script for daemon fusioninventory-agent
#          
#     This library is free software; you can redistribute it and/or modify it
#     under the terms of the GNU Lesser General Public License as published by
#     the Free Software Foundation; either version 2.1 of the License, or (at
#     your option) any later version.
#			      
#     This library is distributed in the hope that it will be useful, but
#     WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#     Lesser General Public License for more details.
#      
#     You should have received a copy of the GNU Lesser General Public
#     License along with this library; if not, write to the Free Software
#     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
#     USA.
#
# /etc/init.d/fusioninventory-agent
#   and its symbolic link
# /(usr/)sbin/rcfusioninventory-agent
#
### BEGIN INIT INFO
# Provides:          FOO
# Required-Start:    $syslog $remote_fs
# Required-Stop:     $syslog $remote_fs
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: FusionInventory Agent 
# Description:	     This script launch FusionInventory Agent as daemon 
### END INIT INFO
# 

DESC="FusionInventory Agent"
NAME=fusioninventory-agent
DAEMON=/usr/bin/$NAME
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
test -x $DAEMON || { echo "$DAEMON not installed"; 
	if [ "$1" = "stop" ]; then exit 0;
	else exit 5; fi; }

# Check for existence of needed config file and read it
#CONFIG=/etc/sysconfig/$NAME
#test -r $CONFIG || { echo "$CONFIG not existing";
#	if [ "$1" = "stop" ]; then exit 0;
#	else exit 6; fi; }

# Read config	
#. $CONFIG
#DAEMON_ARGS="-d -s $SERVER"
DAEMON_ARGS=""

. /etc/rc.status

# Reset status of this service
rc_reset

case "$1" in
    start)
	echo -n "Starting $DESC "
	/sbin/startproc $DAEMON $DAEMON_ARGS
	rc_status -v
	;;
    stop)
	echo -n "Shutting down $DESC "
	/sbin/killproc $DAEMON
	rc_status -v
	;;
    try-restart|condrestart)
	if test "$1" = "condrestart"; then
		echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
	fi
	$0 status
	if test $? = 0; then
		$0 restart
	else
		rc_reset	# Not running is not a failure.
	fi
	rc_status
	;;
    restart)
	$0 stop
	$0 start
	rc_status
	;;
    force-reload)
	echo -n "Reload service $DESC "
	/sbin/killproc -HUP $DAEMON
	#touch /var/run/FOO.pid
	rc_status -v

	## Otherwise:
	#$0 try-restart
	#rc_status
	;;
    reload)
	# If it supports signaling:
	echo -n "Reload service $DESC "
	/sbin/killproc -HUP $DAEMON
	#touch /var/run/FOO.pid
	rc_status -v
	
	## Otherwise if it does not support reload:
	#rc_failed 3
	#rc_status -v
	;;
    status)
	echo -n "Checking for service $DESC "
	/sbin/checkproc $DAEMON
	rc_status -v
	;;
    *)
	echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload}"
	exit 1
	;;
esac
rc_exit
