summaryrefslogtreecommitdiffstats
path: root/fusioninventory-agent.init
blob: aacadab86dbd9a91b34984b132e792cc555f65a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
#
# chkconfig: 345 88 12
# description:	FusionInventory Agent
# processname: fusioninventory-agent
# config: /etc/sysconfig/fusioninventory-agent.pid
# pidfile: /var/run/fusioninventory-agent.pid

# 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=
	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
				OPTS="$OPTS --server=${OCSSERVER[$i]}"
			fi
		fi
		((i++))
	done
	if [ -n "$OPTS" ]; then
		echo -n $"Starting $prog: "
		daemon $prog --logfile=$logfile $FUSINVOPT --daemon $OPTS 2>/dev/null
		RETVAL=$?
		echo
	else
		RETVAL=1
	fi
	[ $RETVAL -eq 0 ] && touch $lockfile
}

#
# 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