From: Sebastian Harl Date: Sun, 2 Sep 2007 14:08:53 +0000 (+0200) Subject: Updated init script to wait for collectd to shut down. X-Git-Tag: collectd-4.2.0-1~27 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=e6aef05b27b7919c0c0fd298394df5fda9ee18b4;p=pkg-collectd.git Updated init script to wait for collectd to shut down. * Closes: #422208. * Added collectd.default. --- diff --git a/debian/changelog b/debian/changelog index 83245c0..0f5bd39 100644 --- a/debian/changelog +++ b/debian/changelog @@ -7,8 +7,9 @@ collectd (4.1.0-1) experimental; urgency=low - Detailed Linux network interface and routing statistics: netlink - Values from SNMP enabled network devices: snmp - Bitrate and frequency of music played with XMMS: xmms + * Updated init script to wait for collectd to shut down (Closes: #422208). - -- Sebastian Harl Sun, 2 Sep 2007 00:56:10 +0200 + -- Sebastian Harl Sun, 2 Sep 2007 15:24:40 +0200 collectd (4.0.7-1) experimental; urgency=low diff --git a/debian/collectd.default b/debian/collectd.default new file mode 100644 index 0000000..d89fd04 --- /dev/null +++ b/debian/collectd.default @@ -0,0 +1,10 @@ +# /etc/default/collectd + +# 0: start collectd on boot, 1: do not start collectd on boot +# default: 0 +DISABLE=0 + +# number of seconds to wait for collectd to shut down +# default: 30 +MAXWAIT=30 + diff --git a/debian/collectd.init.d b/debian/collectd.init.d index 5b33322..31d9827 100755 --- a/debian/collectd.init.d +++ b/debian/collectd.init.d @@ -1,9 +1,10 @@ #!/bin/bash # -# collectd Initscript for collectd -# http://collectd.org/ -# Authors: Florian Forster -# Sebastian Harl +# collectd - start and stop the statistics collection daemon +# http://collectd.org/ +# +# Copyright (C) 2005-2006 Florian Forster +# Copyright (C) 2006-2007 Sebastian Harl # ### BEGIN INIT INFO @@ -20,13 +21,17 @@ set -e PATH=/sbin:/bin:/usr/sbin:/usr/bin + +DISABLE=0 + DESC="statistics collection daemon" NAME=collectd -DAEMON=/usr/sbin/$NAME -SCRIPTNAME=/etc/init.d/$NAME -ARGS="" +DAEMON=/usr/sbin/collectd CONFIGFILE=/etc/collectd/collectd.conf +PIDFILE=/var/run/collectd.pid + +MAXWAIT=30 # Gracefully exit if the package has been removed. test -x $DAEMON || exit 0 @@ -35,21 +40,42 @@ if [ -r /etc/default/$NAME ]; then . /etc/default/$NAME fi +if test "$DISABLE" != 0; then + echo "$NAME has been disabled - see /etc/default/$NAME." + exit 0 +fi + d_start() { - if [ -f "$CONFIGFILE" ]; then - $DAEMON -C $CONFIGFILE 2> /dev/null - else - echo "" - echo "This package is not configured yet. Please refer" - echo "to /usr/share/doc/collectd/README.Debian for" - echo "details." - echo "" - exit 0 - fi + start-stop-daemon --start --quiet --pidfile "$PIDFILE" \ + --exec $DAEMON -- -C "$CONFIGFILE" -P "$PIDFILE" 2> /dev/null } +still_running_warning=" +WARNING: $NAME might still be running. +In large setups it might take some time to write all pending data to +the disk. You can adjust the waiting time in /etc/default/collectd." + d_stop() { - start-stop-daemon --stop --quiet --oknodo --exec $DAEMON + PID=$( cat "$PIDFILE" 2> /dev/null ) || true + + start-stop-daemon --stop --quiet --oknodo --pidfile "$PIDFILE" + + sleep 1 + if test -n "$PID" && kill -0 $PID 2> /dev/null; then + i=0 + while kill -0 $PID 2> /dev/null; do + i=$(( $i + 2 )) + echo -n " ." + + if test $i -gt $MAXWAIT; then + echo "$still_running_warning" + return 1 + fi + + sleep 2 + done + return 0 + fi } case "$1" in @@ -71,7 +97,7 @@ case "$1" in echo "." ;; *) - echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 + echo "Usage: $0 {start|stop|restart|force-reload}" >&2 exit 1 ;; esac @@ -79,3 +105,4 @@ esac exit 0 # vim: syntax=sh noexpandtab sw=4 ts=4 : +