- fixed asyncd init script, added asyncd sysconfig
[packages/munin.git] / munin-asyncd.init
1 #!/bin/sh
2 #
3 # munin-asyncd  Start/Stop the munin-asyncd daemon.
4 #
5 # chkconfig:    2345 91 09
6 # description:  munin-asyncd enables asyncronous fetching of
7 #               metrics from munin-node in a Munin monitoring setup.
8 #
9 # processname:  munin-asyncd
10 # pidfile:      /var/run/munin-asyncd.pid
11 #
12 ### BEGIN INIT INFO
13 # Provides:             munin-asyncd
14 # Required-Start:       $local_fs $remote_fs $network
15 # Required-Stop:        $local_fs $remote_fs $network
16 # Default-Start:        2 3 4 5
17 # Default-Stop:         0 1 6
18 # Short-Description:    Starts and stops munin-asyncd
19 # Description:          munin-asyncd enables asyncronous fetching of
20 #                       metrics from munin-node in a Munin monitoring setup.
21 ### END INIT INFO
22
23 # Source function library.
24 . /etc/rc.d/init.d/functions
25
26 # Get config
27 . /etc/sysconfig/munin-asyncd
28
29 # Set defaults in case they're not defined in config
30 MUNIN_NODE_HOST=${MUNIN_NODE_HOST:-localhost}
31 MUNIN_NODE_PORT=${MUNIN_NODE_HOST:-4949}
32 MUNIN_ASYNCD_SHUTDOWN_TIMEOUT=${MUNIN_ASYNCD_SHUTDOWN_TIMEOUT:-15}
33
34 start() {
35         # Check if the service is already running?
36         if [ -f /var/lock/subsys/munin-asyncd ]; then
37                 msg_already_running "munin-asyncd"
38                 return
39         fi
40
41         msg_starting "munin-asyncd"
42         daemon --fork /usr/sbin/munin-asyncd --host ${MUNIN_NODE_HOST}:${MUNIN_NODE_PORT}
43         RETVAL=$?
44         [ $RETVAL -eq 0 ] && touch /var/lock/subsys/munin-asyncd
45 }
46
47 stop() {
48         if [ ! -f /var/lock/subsys/munin-asyncd ]; then
49                 msg_not_running "munin-asyncd"
50                 return
51         fi
52
53         msg_stopping "munin-asyncd"
54         busy
55         # We can't kill by process name, asyncd is changing it dynamically
56         # so we simply send TERM to all asyncd processes
57         for ppid in $(pgrep "^munin-asyncd "); do
58                 kill -TERM ${ppid}
59         done
60         timeout=0
61         while pgrep "^munin-asyncd " 1>/dev/null 2>&1; do
62                 # If timeout was reached send kill signal and break loop
63                 if [ $timeout -ge $MUNIN_ASYNCD_SHUTDOWN_TIMEOUT ]; then
64                         for ppid in $(pgrep "^munin-asyncd "); do
65                                 kill -KILL ${ppid}
66                         done
67                         break
68                 fi
69                 sleep 1
70                 timeout=$((timeout+1))
71         done
72         ok
73         rm -f /var/lock/subsys/munin-asyncd
74 }
75
76 condrestart() {
77         if [ ! -f /var/lock/subsys/munin-asyncd ]; then
78                 msg_not_running "munin-asyncd"
79                 RETVAL=$1
80                 return
81         fi
82
83         stop
84         start
85 }
86
87 RETVAL=0
88 # See how we were called.
89 case "$1" in
90   start)
91         start
92         ;;
93   stop)
94         stop
95         ;;
96   restart|reload|force-reload)
97         stop
98         start
99         ;;
100   try-restart)
101         condrestart 0
102         ;;
103   status)
104         status --pidfile /var/run/munin-asyncd.pid munin-asyncd
105         exit $?
106         ;;
107   *)
108         msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|status}"
109         exit 3
110 esac
111
112 exit $RETVAL