From 84165a88c6b4b381c214d595fdf5df5561dc7928 Mon Sep 17 00:00:00 2001 From: octo Date: Sat, 11 Mar 2006 15:05:18 +0000 Subject: [PATCH] Improved the init-Script: Prettier output and hopefully more portable code (no `&&' in tests, e.g.) --- debian/collectd.init.d | 47 ++++++++++++++++++++++++---------------- debian/collectd.postinst | 2 +- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/debian/collectd.init.d b/debian/collectd.init.d index c9d950ff..0503ec94 100755 --- a/debian/collectd.init.d +++ b/debian/collectd.init.d @@ -1,9 +1,8 @@ -#!/bin/sh +#!/bin/bash # # collectd Initscript for collectd # http://verplant.org/collectd/ -# Author: Florian Forster -# Extended to support multiple running instances of collectd: +# Authors: Florian Forster # Sebastian Harl # @@ -32,31 +31,41 @@ fi # Function that starts the daemon/service. # d_start() { - i=1 + i=0 - if [[ ! -d "$CONFIGDIR" && -e "$FALLBACKCONF" ]] + if [ ! -d "$CONFIGDIR" -a -e "$FALLBACKCONF" ] then 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}' ) + for FILE in `ls $CONFIGDIR/*.conf 2>/dev/null` + do + NAME=`basename "$FILE" .conf` - if [ 1 != $i ]; then - echo -n " " + 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"; fi - start-stop-daemon --start --quiet \ - --pidfile $PIDFILE --startas $DAEMON \ - -- -C "$CONFIGDIR/$CONFIG" - echo -n "$NAME" - - let i++ + i=$(($i+1)) done - echo -n ")" + + if [ $i == 0 ] + then + echo -n "[no config found]"; + else + echo -n ")" + fi fi } diff --git a/debian/collectd.postinst b/debian/collectd.postinst index d1aa19cb..05ce45d1 100755 --- a/debian/collectd.postinst +++ b/debian/collectd.postinst @@ -19,7 +19,7 @@ case "$1" in configure) [ -d /etc/collectd ] || mkdir -p /etc/collectd - if [ -e /etc/collectd.conf && ! -e /etc/collectd/default.conf ]; then + if [ -e /etc/collectd.conf -a ! -e /etc/collectd/default.conf ]; then mv /etc/collectd.conf /etc/collectd/default.conf fi ;; -- 2.30.2