Code

rrdcached.{init.d,default}: Added an init script for rrdcached.
authorSebastian Harl <sh@tokkee.org>
Fri, 25 Sep 2009 21:28:54 +0000 (23:28 +0200)
committerSebastian Harl <sh@tokkee.org>
Fri, 25 Sep 2009 21:28:54 +0000 (23:28 +0200)
The script currently supports start, stop, status, restart, force-reload. It
is based on the collectd init script.

debian/changelog
debian/rrdcached.default [new file with mode: 0644]
debian/rrdcached.init.d [new file with mode: 0755]

index f9d580d894cd47eea6918f0ac85907fafffbb091..b95c75fbffbfa5038cdf57bf1f53625af9a6803e 100644 (file)
@@ -27,8 +27,11 @@ rrdtool (1.4~rc2-1) experimental; urgency=low
     - Added symbols introduced in 1.4~rc2.
   * Added new binary package 'rrdcached' for the newly introduced "data
     caching daemon".
+  * debian/rrdcached.init.d, debian/rrdcached.default:
+    - Added an init script for rrdcached supporting start, stop, status,
+      restart, force-reload. The script is based on the collectd init script.
 
- -- Sebastian Harl <tokkee@debian.org>  Fri, 25 Sep 2009 22:35:04 +0200
+ -- Sebastian Harl <tokkee@debian.org>  Fri, 25 Sep 2009 23:27:32 +0200
 
 rrdtool (1.3.8-1) unstable; urgency=low
 
diff --git a/debian/rrdcached.default b/debian/rrdcached.default
new file mode 100644 (file)
index 0000000..257f189
--- /dev/null
@@ -0,0 +1,16 @@
+# /etc/default/rrdcached
+
+# 0: start rrdcached on boot, 1: do not start rrdcached on boot
+# default: 0
+DISABLE=0
+
+# number of seconds to wait for rrdcached to shut down
+# (writing the data to disk may take some time;
+# tune this according to your setup)
+# default: 30
+MAXWAIT=30
+
+# 0: do not enable core-files, 1: enable core-files ... if rrdcached crashes
+# default: 0
+ENABLE_COREFILES=0
+
diff --git a/debian/rrdcached.init.d b/debian/rrdcached.init.d
new file mode 100755 (executable)
index 0000000..48c629c
--- /dev/null
@@ -0,0 +1,141 @@
+#! /bin/bash
+#
+# rrdcached - start and stop the RRDtool data caching daemon
+# http://oss.oetiker.ch/rrdtool/
+#
+# Based on the collectd init script.
+#
+# Copyright (C) 2005-2006 Florian Forster <octo@verplant.org>
+# Copyright (C) 2006-2009 Sebastian Harl <tokkee@debian.org>
+#
+
+### BEGIN INIT INFO
+# Provides:          rrdcached
+# Required-Start:    $local_fs $remote_fs
+# Required-Stop:     $local_fs $remote_fs
+# Should-Start:      $network
+# Should-Stop:       $network
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: start the RRDtool data caching daemon
+### END INIT INFO
+
+set -e
+
+PATH=/sbin:/bin:/usr/sbin:/usr/bin
+
+DISABLE=0
+
+DESC="RRDtool data caching daemon"
+NAME=rrdcached
+DAEMON=/usr/bin/rrdcached
+
+PIDFILE=/var/run/rrdcached.pid
+
+MAXWAIT=30
+
+# Gracefully exit if the package has been removed.
+test -x $DAEMON || exit 0
+
+if [ -r /etc/default/$NAME ]; then
+       . /etc/default/$NAME
+fi
+
+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
+
+d_start() {
+       if test "$DISABLE" != 0; then
+               # we get here during restart
+               echo -n " - disabled by /etc/default/$NAME"
+               return 0
+       fi
+
+       start-stop-daemon --start --quiet --oknodo --pidfile "$PIDFILE" \
+               --exec $DAEMON -- $OPTS -p "$PIDFILE"
+}
+
+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/$NAME."
+
+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
+
+                       sleep 2
+               done
+               return 0
+       fi
+}
+
+d_status() {
+       PID=$( cat "$PIDFILE" 2> /dev/null ) || true
+
+       if test -n "$PID" && kill -0 $PID 2> /dev/null; then
+               echo "$NAME ($PID) is running."
+               exit 0
+       else
+               PID=$( pidof $NAME ) || true
+
+               if test -n "$PID"; then
+                       echo "$NAME ($PID) is running."
+                       exit 0
+               else
+                       echo "$NAME is stopped."
+               fi
+       fi
+       exit 1
+}
+
+case "$1" in
+       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|status}" >&2
+               exit 1
+               ;;
+esac
+
+exit 0
+
+# vim: syntax=sh noexpandtab sw=4 ts=4 :
+