1 #!/bin/bash
2 #
3 # collectd Initscript for collectd
4 # http://collectd.org/
5 # Authors: Florian Forster <octo@verplant.org>
6 # Sebastian Harl <sh@tokkee.org>
7 #
9 set -e
11 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
12 DESC="Statistics collection daemon"
13 NAME=collectd
14 DAEMON=/usr/sbin/$NAME
15 SCRIPTNAME=/etc/init.d/$NAME
16 ARGS=""
18 CONFIGDIR=/etc/collectd
19 # for backward compatibility
20 FALLBACKCONF=/etc/collectd.conf
22 # Gracefully exit if the package has been removed.
23 test -x $DAEMON || exit 0
25 if [ -r /etc/default/$NAME ]
26 then
27 . /etc/default/$NAME
28 fi
30 #
31 # Function that starts the daemon/service.
32 #
33 d_start() {
34 i=0
36 if [ ! -d "$CONFIGDIR" -a -e "$FALLBACKCONF" ]
37 then
38 start-stop-daemon --start --quiet --exec $DAEMON \
39 -- -C "$FALLBACKCONF"
40 else
41 for FILE in `ls $CONFIGDIR/*.conf 2>/dev/null`
42 do
43 NAME=`basename "$FILE" .conf`
45 if [ $i == 0 ]
46 then
47 echo -n " (";
48 else
49 echo -n ", ";
50 fi
52 $DAEMON -C "$FILE" 2>/dev/null
53 if [ $? == 0 ]
54 then
55 echo -n "$NAME";
56 else
57 echo -n "$NAME failed";
58 fi
60 i=$(($i+1))
61 done
63 if [ $i == 0 ]
64 then
65 echo -n "[no config found]";
66 else
67 echo -n ")"
68 fi
69 fi
70 }
72 #
73 # Function that stops the daemon/service.
74 #
75 d_stop() {
76 start-stop-daemon --stop --quiet --exec $DAEMON
77 }
79 case "$1" in
80 start)
81 echo -n "Starting $DESC: $NAME"
82 d_start
83 echo "."
84 ;;
85 stop)
86 echo -n "Stopping $DESC: $NAME"
87 d_stop
88 echo "."
89 ;;
90 restart|force-reload)
91 echo -n "Restarting $DESC: $NAME"
92 d_stop
93 sleep 1
94 d_start
95 echo "."
96 ;;
97 *)
98 echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
99 exit 1
100 ;;
101 esac
103 exit 0
105 # vim:syntax=sh