collectd.conf(5): Updated the “GetSnapshot” entry.
[collectd.git] / debian / collectd.init.d
index c9d950f..7c8ac29 100755 (executable)
@@ -1,9 +1,8 @@
-#!/bin/sh
+#!/bin/bash
 #
 # collectd     Initscript for collectd
-#              http://verplant.org/collectd/
-# Author:      Florian Forster <octo@verplant.org>
-# Extended to support multiple running instances of collectd:
+#              http://collectd.org/
+# Authors:     Florian Forster <octo@verplant.org>
 #              Sebastian Harl <sh@tokkee.org>
 #
 
@@ -32,31 +31,51 @@ fi
 #      Function that starts the daemon/service.
 #
 d_start() {
-       i=1
+       i=0
        
-       if [[ ! -d "$CONFIGDIR" && -e "$FALLBACKCONF" ]]
+       if [ ! -d "$CONFIGDIR" ]
        then
-               start-stop-daemon --start --quiet --exec $DAEMON \
-                       -- -C "$FALLBACKCONF"
+               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
        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]"
+                       exit 1
+               else
+                       echo -n ")"
+               fi
        fi
 }
 
@@ -64,7 +83,7 @@ d_start() {
 #      Function that stops the daemon/service.
 #
 d_stop() {
-       start-stop-daemon --stop --quiet --exec $DAEMON
+       start-stop-daemon --stop --quiet --oknodo --exec $DAEMON
 }
 
 case "$1" in
@@ -93,4 +112,4 @@ esac
 
 exit 0
 
-# vim:syntax=sh
+# vim: syntax=sh noexpandtab sw=8 ts=8 :