Code

Diff for NMU version 1.4.7-1.2.
[pkg-rrdtool.git] / debian / rrdcached.init.d
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         # make sure we have the needed directories
65         mkdir -p /var/lib/rrdcached/journal/
66         mkdir -p /var/lib/rrdcached/db/
68         start-stop-daemon --start --quiet --oknodo --pidfile "$PIDFILE" \
69                 --exec $DAEMON -- $OPTS -p "$PIDFILE"
70 }
72 still_running_warning="
73 WARNING: $NAME might still be running.
74 In large setups it might take some time to write all pending data to
75 the disk. You can adjust the waiting time in /etc/default/$NAME."
77 d_stop() {
78         PID=$( cat "$PIDFILE" 2> /dev/null ) || true
80         start-stop-daemon --stop --quiet --oknodo --pidfile "$PIDFILE"
82         sleep 1
83         if test -n "$PID" && kill -0 $PID 2> /dev/null; then
84                 i=0
85                 while kill -0 $PID 2> /dev/null; do
86                         i=$(( $i + 2 ))
87                         echo -n " ."
89                         if test $i -gt $MAXWAIT; then
90                                 echo "$still_running_warning" >&2
91                                 return 1
92                         fi
94                         sleep 2
95                 done
96                 return 0
97         fi
98 }
100 d_status() {
101         PID=$( cat "$PIDFILE" 2> /dev/null ) || true
103         if test -n "$PID" && kill -0 $PID 2> /dev/null; then
104                 echo "$NAME ($PID) is running."
105                 exit 0
106         else
107                 PID=$( pidof $NAME ) || true
109                 if test -n "$PID"; then
110                         echo "$NAME ($PID) is running."
111                         exit 0
112                 else
113                         echo "$NAME is stopped."
114                 fi
115         fi
116         exit 1
119 case "$1" in
120         start)
121                 echo -n "Starting $DESC: $NAME"
122                 d_start
123                 echo "."
124                 ;;
125         stop)
126                 echo -n "Stopping $DESC: $NAME"
127                 d_stop
128                 echo "."
129                 ;;
130         status)
131                 d_status
132                 ;;
133         restart|force-reload)
134                 echo -n "Restarting $DESC: $NAME"
135                 d_stop
136                 sleep 1
137                 d_start
138                 echo "."
139                 ;;
140         *)
141                 echo "Usage: $0 {start|stop|restart|force-reload|status}" >&2
142                 exit 1
143                 ;;
144 esac
146 exit 0
148 # vim: syntax=sh noexpandtab sw=4 ts=4 :