1 #! /bin/bash
2 #
3 # rrdcached - start and stop the RRDtool data caching daemon
4 # http://oss.oetiker.ch/rrdtool/
5 #
6 # Based on the collectd init script.
7 #
8 # Copyright (C) 2005-2006 Florian Forster <octo@verplant.org>
9 # Copyright (C) 2006-2009 Sebastian Harl <tokkee@debian.org>
10 #
12 ### BEGIN INIT INFO
13 # Provides: rrdcached
14 # Required-Start: $local_fs $remote_fs
15 # Required-Stop: $local_fs $remote_fs
16 # Should-Start: $network
17 # Should-Stop: $network
18 # Default-Start: 2 3 4 5
19 # Default-Stop: 0 1 6
20 # Short-Description: start the RRDtool data caching daemon
21 ### END INIT INFO
23 set -e
25 PATH=/sbin:/bin:/usr/sbin:/usr/bin
27 DISABLE=0
29 DESC="RRDtool data caching daemon"
30 NAME=rrdcached
31 DAEMON=/usr/bin/rrdcached
33 OPTS="-l unix:/var/run/rrdcached.sock"
34 OPTS="$OPTS -j /var/lib/rrdcached/journal/ -F"
35 OPTS="$OPTS -b /var/lib/rrdcached/db/ -B"
37 PIDFILE=/var/run/rrdcached.pid
39 MAXWAIT=30
41 # Gracefully exit if the package has been removed.
42 test -x $DAEMON || exit 0
44 if [ -r /etc/default/$NAME ]; then
45 . /etc/default/$NAME
46 fi
48 if test "$DISABLE" != 0 -a "$1" == "start"; then
49 echo "$NAME has been disabled - see /etc/default/$NAME."
50 exit 0
51 fi
53 if test "$ENABLE_COREFILES" == 1; then
54 ulimit -c unlimited
55 fi
57 d_start() {
58 if test "$DISABLE" != 0; then
59 # we get here during restart
60 echo -n " - disabled by /etc/default/$NAME"
61 return 0
62 fi
64 start-stop-daemon --start --quiet --oknodo --pidfile "$PIDFILE" \
65 --exec $DAEMON -- $OPTS -p "$PIDFILE"
66 }
68 still_running_warning="
69 WARNING: $NAME might still be running.
70 In large setups it might take some time to write all pending data to
71 the disk. You can adjust the waiting time in /etc/default/$NAME."
73 d_stop() {
74 PID=$( cat "$PIDFILE" 2> /dev/null ) || true
76 start-stop-daemon --stop --quiet --oknodo --pidfile "$PIDFILE"
78 sleep 1
79 if test -n "$PID" && kill -0 $PID 2> /dev/null; then
80 i=0
81 while kill -0 $PID 2> /dev/null; do
82 i=$(( $i + 2 ))
83 echo -n " ."
85 if test $i -gt $MAXWAIT; then
86 echo "$still_running_warning" >&2
87 return 1
88 fi
90 sleep 2
91 done
92 return 0
93 fi
94 }
96 d_status() {
97 PID=$( cat "$PIDFILE" 2> /dev/null ) || true
99 if test -n "$PID" && kill -0 $PID 2> /dev/null; then
100 echo "$NAME ($PID) is running."
101 exit 0
102 else
103 PID=$( pidof $NAME ) || true
105 if test -n "$PID"; then
106 echo "$NAME ($PID) is running."
107 exit 0
108 else
109 echo "$NAME is stopped."
110 fi
111 fi
112 exit 1
113 }
115 case "$1" in
116 start)
117 echo -n "Starting $DESC: $NAME"
118 d_start
119 echo "."
120 ;;
121 stop)
122 echo -n "Stopping $DESC: $NAME"
123 d_stop
124 echo "."
125 ;;
126 status)
127 d_status
128 ;;
129 restart|force-reload)
130 echo -n "Restarting $DESC: $NAME"
131 d_stop
132 sleep 1
133 d_start
134 echo "."
135 ;;
136 *)
137 echo "Usage: $0 {start|stop|restart|force-reload|status}" >&2
138 exit 1
139 ;;
140 esac
142 exit 0
144 # vim: syntax=sh noexpandtab sw=4 ts=4 :