X-Git-Url: https://git.tld-linux.org/?p=packages%2Fmunin.git;a=blobdiff_plain;f=munin-asyncd.init;h=4c2ebea335dc0ece26a9560a8406b45bf2dcbaec;hp=b7a89d161572e1c6c8d41a7a4bbe39b813e6888d;hb=d5910e0aa4a37928e95746cb73d3090e1dcce56e;hpb=77c4bfbe37910bcd417dafcc6a671698f6cee6b3 diff --git a/munin-asyncd.init b/munin-asyncd.init index b7a89d1..4c2ebea 100755 --- a/munin-asyncd.init +++ b/munin-asyncd.init @@ -23,33 +23,59 @@ # 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