Blob Blame History Raw
#!/bin/bash
#
# chkconfig: - 88 12
# description:	FusionInventory Agent
# processname: fusioninventory-agent
# config: /etc/sysconfig/fusioninventory-agent.pid
# pidfile: /var/run/fusioninventory-agent.pid
### BEGIN INIT INFO
# Provides: fusioninventory-agent
# Required-Start: $local_fs $remote_fs $network $named $syslog $time
# Required-Stop: $local_fs $remote_fs $network $named $syslog $time
# Default-Start:
# Default-Stop: 0 1 6
# Short-Description: FusionInventory agent
# Description: FusionInventory agent
### END INIT INFO

# source function library
. /etc/rc.d/init.d/functions

RETVAL=0
desc="FusionInventory Agent"
prog=fusioninventory-agent
lockfile=/var/lock/subsys/$prog
pidfile=/var/run/$prog.pid
logfile=/var/log/$prog/$prog.log

# pull in sysconfig settings
[ -r /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

#
# Function that starts the daemon/service
#
do_start()
{
	# Read configuration
	i=0
	OPTS=
	SERVERS=
	while [ $i -lt ${#OCSMODE[*]} ]
	do
		if [ ${OCSMODE[$i]:-none} == daemon ]; then
			if [ ! -z "${OCSTAG[$i]}" ]; then
				OPTS="$OPTS --tag=${OCSTAG[$i]}"
			fi
			if [ "z${OCSSERVER[$i]}" = 'zlocal' ]; then
				# Local inventory
				OPTS="$OPTS --local=/var/lib/$prog"
			elif [ ! -z "${OCSSERVER[$i]}" ]; then
				# Remote inventory
				if [ -z "$SERVERS" ]; then
					SERVERS=${OCSSERVER[$i]}
				else
					SERVERS="$SERVERS,${OCSSERVER[$i]}"
				fi
			fi
		fi
		((i++))
	done
	if [ -n "$SERVERS" ]; then
		OPTS="$OPTS --server=$SERVERS"
	fi
	if [ -n "$OPTS" ]; then
		echo -n $"Starting $prog: "
		daemon $prog --logfile-maxsize=999 --logfile=$logfile $FUSINVOPT --daemon $OPTS 2>/dev/null
		RETVAL=$?
		echo
                [ $RETVAL -eq 0 ] && touch $lockfile
	else
		RETVAL=0
	fi
}

#
# Function that stops the daemon/service
#
do_stop()
{
	echo -n $"Stopping $prog: "
	killproc $prog
	RETVAL=$?
	echo
	if [ $RETVAL -eq 0 ] ; then
	    rm -f $lockfile $pidfile
	fi
}

case "$1" in
  start)
	do_start
	;;
  stop)
	do_stop
	;;
  status)
	status $prog
	;;
  restart|reload|force-reload)
	do_stop
	do_start
	;;
  condrestart)
	[ -f $lockfile ] && do_stop && do_start || :
	;;
  *)
	echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
	exit 1
	;;
esac
exit $RETVAL