]> TLD Linux GIT Repositories - packages/munin.git/blobdiff - munin-asyncd.init
- fixed patches
[packages/munin.git] / munin-asyncd.init
index b7a89d161572e1c6c8d41a7a4bbe39b813e6888d..4c2ebea335dc0ece26a9560a8406b45bf2dcbaec 100755 (executable)
 # Source function library.
 . /etc/rc.d/init.d/functions
 
+# Get config
+. /etc/sysconfig/munin-asyncd
+
+# Set defaults in case they're not defined in config
+MUNIN_NODE_HOST=${MUNIN_NODE_HOST:-localhost}
+MUNIN_NODE_PORT=${MUNIN_NODE_HOST:-4949}
+MUNIN_ASYNCD_SHUTDOWN_TIMEOUT=${MUNIN_ASYNCD_SHUTDOWN_TIMEOUT:-15}
+
 start() {
        # Check if the service is already running?
        if [ -f /var/lock/subsys/munin-asyncd ]; then
-               msg_already_running "munin-asyncd"
+               msg_already_running "Munin Asyncd"
                return
        fi
 
-       msg_starting "munin-asyncd"
-       daemon /usr/sbin/munin-asyncd
+       msg_starting "Munin Asyncd"
+       daemon --fork /usr/sbin/munin-asyncd --host ${MUNIN_NODE_HOST}:${MUNIN_NODE_PORT}
        RETVAL=$?
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/munin-asyncd
 }
 
 stop() {
        if [ ! -f /var/lock/subsys/munin-asyncd ]; then
-               msg_not_running "munin-asyncd"
+               msg_not_running "Munin Asyncd"
                return
        fi
 
-       msg_stopping "munin-asyncd"
-       killproc munin-asyncd
+       msg_stopping "Munin Asyncd"
+       busy
+       # We can't kill by process name, asyncd is changing it dynamically
+       # so we simply send TERM to all asyncd processes
+       for ppid in $(pgrep "^munin-asyncd "); do
+               kill -TERM ${ppid}
+       done
+       timeout=0
+       while pgrep "^munin-asyncd " 1>/dev/null 2>&1; do
+               # If timeout was reached send kill signal and break loop
+               if [ $timeout -ge $MUNIN_ASYNCD_SHUTDOWN_TIMEOUT ]; then
+                       for ppid in $(pgrep "^munin-asyncd "); do
+                               kill -KILL ${ppid}
+                       done
+                       break
+               fi
+               sleep 1
+               timeout=$((timeout+1))
+       done
+       ok
        rm -f /var/lock/subsys/munin-asyncd
 }
 
 condrestart() {
        if [ ! -f /var/lock/subsys/munin-asyncd ]; then
-               msg_not_running "munin-asyncd"
+               msg_not_running "Munin Asyncd"
                RETVAL=$1
                return
        fi