Merge branch 'collectd-5.1' into collectd-5.2
[collectd.git] / contrib / redhat / init.d-collectd
1 #!/bin/bash
2 #
3 # collectd    Startup script for the Collectd statistics gathering daemon
4 # chkconfig: - 99 01
5 # description: Collectd is a statistics gathering daemon used to collect \
6 #   system information ie. cpu, memory, disk, network
7 # processname: collectd
8 # config: /etc/collectd.conf
9 # config: /etc/sysconfig/collectd
10 # pidfile: /var/run/collectd.pid
11
12 # Source function library.
13 . /etc/init.d/functions
14
15 RETVAL=0
16 ARGS=""
17 prog="collectdmon"
18 service="collectd"
19 CONFIG=/etc/collectd.conf
20 COLLECTD=/usr/sbin/collectd
21 COLLECTDMONPID=/var/run/collectdmon.pid
22
23 if [ -r /etc/sysconfig/$service ]; then
24         . /etc/sysconfig/$service
25 fi
26
27 check_config() {
28         if test ! -r "$CONFIG"; then
29                 return 2
30         fi
31         if ! $COLLECTD -t -C "$CONFIG"; then
32                 return 1
33         fi
34         return 0
35 }
36
37
38 start () {
39         echo -n $"Starting collectd: "
40         check_config
41         rc="$?"
42         if test "$rc" -ne 0; then
43                 RETVAL=6
44                 echo $"not starting due to configuration error"
45                 failure $"not starting $service due to configuration error"
46         else
47                 daemon $prog -P $COLLECTDMONPID -c $COLLECTD -- -C "$CONFIG" $ARGS
48                 RETVAL=$?
49                 echo
50                 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$service
51         fi
52 }
53 stop () {
54         echo -n $"Stopping collectd: "
55         killproc $prog
56         RETVAL=$?
57         echo
58         [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$service
59 }
60 # See how we were called.
61 case "$1" in
62   start)
63         start
64         ;;
65   stop)
66         stop
67         ;;
68   status)
69         status $prog
70         ;;
71   restart|reload)
72         check_config
73         rc="$?"
74         if test "$rc" -ne 0; then
75                 RETVAL=6
76                 echo $"not restarting due to configuration error"
77                 failure $"not restarting $service due to configuration error"
78         else
79                 stop
80                 start
81         fi
82         ;;
83   condrestart)
84         [ -f /var/lock/subsys/$prog ] && restart || :
85         ;;
86   *)
87         echo $"Usage: $0 {start|stop|status|restart|reload|condrestart}"
88         exit 1
89 esac
90
91 exit $?
92
93 # vim:syntax=sh