summaryrefslogtreecommitdiffstats
path: root/fusioninventory-agent.init
blob: 4a488f2d91f59743a195ecaeb6be5fd06b75722a (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/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