]> TLD Linux GIT Repositories - packages/munin.git/blobdiff - munin-asyncd.init
- fixed asyncd init script, added asyncd sysconfig
[packages/munin.git] / munin-asyncd.init
index b7a89d161572e1c6c8d41a7a4bbe39b813e6888d..5340110fac186e1f558555f8d0422400a7e8d6aa 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
@@ -31,7 +39,7 @@ start() {
        fi
 
        msg_starting "munin-asyncd"
-       daemon /usr/sbin/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
 }
@@ -43,7 +51,25 @@ stop() {
        fi
 
        msg_stopping "munin-asyncd"
-       killproc 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
 }