diff --git a/debian/collectd.init.d b/debian/collectd.init.d
index 7c8ac291c50f28dab151b6120d88e76d96f09d9d..bb27de9cd89c3c29cdb47b09fc46c7e071a1170d 100755 (executable)
--- a/debian/collectd.init.d
+++ b/debian/collectd.init.d
#!/bin/bash
#
-# collectd Initscript for collectd
-# http://collectd.org/
-# Authors: Florian Forster <octo@verplant.org>
-# Sebastian Harl <sh@tokkee.org>
+# collectd - start and stop the statistics collection daemon
+# http://collectd.org/
#
+# Copyright (C) 2005-2006 Florian Forster <octo@verplant.org>
+# Copyright (C) 2006-2008 Sebastian Harl <sh@tokkee.org>
+#
+
+### BEGIN INIT INFO
+# Provides: collectd
+# Required-Start: $local_fs $remote_fs
+# Required-Stop: $local_fs $remote_fs
+# Should-Start: $network $named $syslog $time
+# Should-Stop: $network $named $syslog
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: start the statistics collection daemon
+### END INIT INFO
set -e
-PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
-DESC="Statistics collection daemon"
+PATH=/sbin:/bin:/usr/sbin:/usr/bin
+
+DISABLE=0
+
+DESC="statistics collection and monitoring 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
+
+USE_COLLECTDMON=1
+COLLECTDMON_DAEMON=/usr/sbin/collectdmon
+COLLECTDMON_PIDFILE=/var/run/collectdmon.pid
-CONFIGDIR=/etc/collectd
-# for backward compatibility
-FALLBACKCONF=/etc/collectd.conf
+MAXWAIT=30
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
-if [ -r /etc/default/$NAME ]
-then
+if [ -r /etc/default/$NAME ]; then
. /etc/default/$NAME
fi
-#
-# Function that starts the daemon/service.
-#
+if test "$DISABLE" != 0 -a "$1" == "start"; then
+ echo "$NAME has been disabled - see /etc/default/$NAME."
+ exit 0
+fi
+
+if test "$ENABLE_COREFILES" == 1; then
+ ulimit -c unlimited
+fi
+
+if test "$USE_COLLECTDMON" == 1; then
+ _PIDFILE="$COLLECTDMON_PIDFILE"
+else
+ _PIDFILE="$PIDFILE"
+fi
+
d_start() {
- i=0
-
- if [ ! -d "$CONFIGDIR" ]
- then
- if [ -e "$FALLBACKCONF" ]
- then
- $DAEMON -C "$FALLBACKCONF" 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
+ if test "$DISABLE" != 0; then
+ # we get here during restart
+ echo -n " - disabled by /etc/default/$NAME"
+ return 0
+ fi
+
+ if ! $DAEMON -t -C "$CONFIGFILE" > /dev/null 2>&1; then
+ $DAEMON -t -C "$CONFIGFILE"
+ exit 1
+ fi
+
+ if test "$USE_COLLECTDMON" == 1; then
+ start-stop-daemon --start --quiet --pidfile "$_PIDFILE" \
+ --exec $COLLECTDMON_DAEMON -- -P "$_PIDFILE" -- -C "$CONFIGFILE"
else
- for FILE in `ls $CONFIGDIR/*.conf 2>/dev/null`
- do
- NAME=`basename "$FILE" .conf`
-
- if [ $i == 0 ]
- then
- echo -n " ("
- else
- echo -n ", "
- fi
-
- $DAEMON -C "$FILE" 2> /dev/null
- if [ $? == 0 ]
- then
- echo -n "$NAME"
- else
- echo -n "$NAME failed"
+ start-stop-daemon --start --quiet --pidfile "$_PIDFILE" \
+ --exec $DAEMON -- -C "$CONFIGFILE" -P "$_PIDFILE"
+ fi
+}
+
+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() {
+ 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" >&2
+ return 1
fi
- i=$(($i+1))
+ sleep 2
done
+ return 0
+ fi
+}
- if [ $i == 0 ]
- then
- echo -n "[no config found]"
- exit 1
+d_status() {
+ PID=$( cat "$_PIDFILE" 2> /dev/null ) || true
+
+ if test -n "$PID" && kill -0 $PID 2> /dev/null; then
+ echo "collectd ($PID) is running."
+ exit 0
+ else
+ PID=$( pidof collectd ) || true
+
+ if test -n "$PID"; then
+ echo "collectd ($PID) is running."
+ exit 0
else
- echo -n ")"
+ echo "collectd is stopped."
fi
fi
}
-#
-# Function that stops the daemon/service.
-#
-d_stop() {
- start-stop-daemon --stop --quiet --oknodo --exec $DAEMON
-}
-
case "$1" in
- start)
- echo -n "Starting $DESC: $NAME"
- d_start
- echo "."
- ;;
- stop)
- echo -n "Stopping $DESC: $NAME"
- d_stop
- echo "."
- ;;
- restart|force-reload)
- echo -n "Restarting $DESC: $NAME"
- d_stop
- sleep 1
- d_start
- echo "."
- ;;
- *)
- echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
- exit 1
- ;;
+ start)
+ echo -n "Starting $DESC: $NAME"
+ d_start
+ echo "."
+ ;;
+ stop)
+ echo -n "Stopping $DESC: $NAME"
+ d_stop
+ echo "."
+ ;;
+ status)
+ d_status
+ ;;
+ restart|force-reload)
+ echo -n "Restarting $DESC: $NAME"
+ d_stop
+ sleep 1
+ d_start
+ echo "."
+ ;;
+ *)
+ echo "Usage: $0 {start|stop|restart|force-reload}" >&2
+ exit 1
+ ;;
esac
exit 0
-# vim: syntax=sh noexpandtab sw=8 ts=8 :
+# vim: syntax=sh noexpandtab sw=4 ts=4 :
+