Code

Added simple support to configure and run multiple instances of collectd to
authortokkee <tokkee>
Mon, 6 Mar 2006 20:37:14 +0000 (20:37 +0000)
committertokkee <tokkee>
Mon, 6 Mar 2006 20:37:14 +0000 (20:37 +0000)
the init script.

debian/collectd.init.d
debian/collectd.postinst [new file with mode: 0755]
debian/collectd.postrm [new file with mode: 0755]

index 13118fabf4136d4de344a4b222aa3284727b2a32..c9d950ffc866bedc6ed3f4cad79044775ca88037 100755 (executable)
@@ -3,6 +3,8 @@
 # collectd     Initscript for collectd
 #              http://verplant.org/collectd/
 # Author:      Florian Forster <octo@verplant.org>
+# Extended to support multiple running instances of collectd:
+#              Sebastian Harl <sh@tokkee.org>
 #
 
 set -e
@@ -13,7 +15,10 @@ NAME=collectd
 DAEMON=/usr/sbin/$NAME
 SCRIPTNAME=/etc/init.d/$NAME
 ARGS=""
-CONFIG=/etc/collectd.conf
+
+CONFIGDIR=/etc/collectd
+# for backward compatibility
+FALLBACKCONF=/etc/collectd.conf
 
 # Gracefully exit if the package has been removed.
 test -x $DAEMON || exit 0
@@ -27,9 +32,31 @@ fi
 #      Function that starts the daemon/service.
 #
 d_start() {
-       if [ -e "$CONFIG" ]
+       i=1
+       
+       if [[ ! -d "$CONFIGDIR" && -e "$FALLBACKCONF" ]]
        then
-               start-stop-daemon --start --quiet --exec $DAEMON -- -C "$CONFIG"
+               start-stop-daemon --start --quiet --exec $DAEMON \
+                       -- -C "$FALLBACKCONF"
+       else
+               echo -n " ("
+               for CONFIG in `cd $CONFIGDIR; ls *.conf 2> /dev/null`; do
+                       CONF="$CONFIGDIR/$CONFIG"
+                       NAME=${CONFIG%%.conf}
+                       PIDFILE=$( grep PIDFile $CONF | awk '{print $2}' )
+
+                       if [ 1 != $i ]; then
+                               echo -n " "
+                       fi
+
+                       start-stop-daemon --start --quiet \
+                               --pidfile $PIDFILE --startas $DAEMON \
+                               -- -C "$CONFIGDIR/$CONFIG"
+                       echo -n "$NAME"
+
+                       let i++
+               done
+               echo -n ")"
        fi
 }
 
diff --git a/debian/collectd.postinst b/debian/collectd.postinst
new file mode 100755 (executable)
index 0000000..d1aa19c
--- /dev/null
@@ -0,0 +1,40 @@
+#!/bin/bash -e
+# postinst script for collectd
+#
+# see: dh_installdeb(1)
+#
+# summary of how this script can be called:
+#              * <postinst> `configure' <most-recently-configured-version>
+#              * <old-postinst> `abort-upgrade' <new version>
+#              * <conflictor's-postinst> `abort-remove' `in-favour' <package>
+#                <new-version>
+#              * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
+#                <failed-install-package> <version> `removing'
+#                <conflicting-package> <version>
+# for details, see http://www.debian.org/doc/debian-policy/ or
+# the debian-policy package
+#
+
+case "$1" in
+       configure)
+               [ -d /etc/collectd ] || mkdir -p /etc/collectd
+               
+               if [ -e /etc/collectd.conf && ! -e /etc/collectd/default.conf ]; then
+                       mv /etc/collectd.conf /etc/collectd/default.conf
+               fi
+       ;;
+
+       abort-upgrade|abort-remove|abort-deconfigure)
+       ;;
+
+       *)
+               echo "postinst called with unknown argument \`$1'" >&2
+               exit 1
+       ;;
+esac
+
+#DEBHELPER#
+
+exit 0
+
+
diff --git a/debian/collectd.postrm b/debian/collectd.postrm
new file mode 100755 (executable)
index 0000000..2ea2e74
--- /dev/null
@@ -0,0 +1,41 @@
+#! /bin/sh
+# postrm script for collectd
+#
+# see: dh_installdeb(1)
+
+set -e
+
+# summary of how this script can be called:
+#        * <postrm> `remove'
+#        * <postrm> `purge'
+#        * <old-postrm> `upgrade' <new-version>
+#        * <new-postrm> `failed-upgrade' <old-version>
+#        * <new-postrm> `abort-install'
+#        * <new-postrm> `abort-install' <old-version>
+#        * <new-postrm> `abort-upgrade' <old-version>
+#        * <disappearer's-postrm> `disappear' <r>overwrit>r> <new-version>
+# for details, see http://www.debian.org/doc/debian-policy/ or
+# the debian-policy package
+
+
+case "$1" in
+       purge)
+               rm -rf /var/lib/collectd
+               rm -rf /etc/collectd
+               rm -f /etc/collectd.conf
+       ;;
+
+       remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
+       ;;
+
+       *)
+        echo "postrm called with unknown argument \`$1'" >&2
+        exit 1
+esac
+
+# dh_installdeb will replace this with shell code automatically
+# generated by other debhelper scripts.
+
+#DEBHELPER#
+
+exit 0