From 98f5987a9f11976a08d0efd648256fdfa2f0640d Mon Sep 17 00:00:00 2001 From: tokkee Date: Mon, 6 Mar 2006 20:37:14 +0000 Subject: [PATCH] Added simple support to configure and run multiple instances of collectd to the init script. --- debian/collectd.init.d | 33 ++++++++++++++++++++++++++++++--- debian/collectd.postinst | 40 ++++++++++++++++++++++++++++++++++++++++ debian/collectd.postrm | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+), 3 deletions(-) create mode 100755 debian/collectd.postinst create mode 100755 debian/collectd.postrm diff --git a/debian/collectd.init.d b/debian/collectd.init.d index 13118fab..c9d950ff 100755 --- a/debian/collectd.init.d +++ b/debian/collectd.init.d @@ -3,6 +3,8 @@ # collectd Initscript for collectd # http://verplant.org/collectd/ # Author: Florian Forster +# Extended to support multiple running instances of collectd: +# Sebastian Harl # 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 index 00000000..d1aa19cb --- /dev/null +++ b/debian/collectd.postinst @@ -0,0 +1,40 @@ +#!/bin/bash -e +# postinst script for collectd +# +# see: dh_installdeb(1) +# +# summary of how this script can be called: +# * `configure' +# * `abort-upgrade' +# * `abort-remove' `in-favour' +# +# * `abort-deconfigure' `in-favour' +# `removing' +# +# 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 index 00000000..2ea2e748 --- /dev/null +++ b/debian/collectd.postrm @@ -0,0 +1,41 @@ +#! /bin/sh +# postrm script for collectd +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `remove' +# * `purge' +# * `upgrade' +# * `failed-upgrade' +# * `abort-install' +# * `abort-install' +# * `abort-upgrade' +# * `disappear' overwrit>r> +# 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 -- 2.11.0