Code

48c629cf4f151e2b899532a0a418af8d6e3ee297
[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 PIDFILE=/var/run/rrdcached.pid
35 MAXWAIT=30
37 # Gracefully exit if the package has been removed.
38 test -x $DAEMON || exit 0
40 if [ -r /etc/default/$NAME ]; then
41         . /etc/default/$NAME
42 fi
44 if test "$DISABLE" != 0 -a "$1" == "start"; then
45         echo "$NAME has been disabled - see /etc/default/$NAME."
46         exit 0
47 fi
49 if test "$ENABLE_COREFILES" == 1; then
50         ulimit -c unlimited
51 fi
53 d_start() {
54         if test "$DISABLE" != 0; then
55                 # we get here during restart
56                 echo -n " - disabled by /etc/default/$NAME"
57                 return 0
58         fi
60         start-stop-daemon --start --quiet --oknodo --pidfile "$PIDFILE" \
61                 --exec $DAEMON -- $OPTS -p "$PIDFILE"
62 }
64 still_running_warning="
65 WARNING: $NAME might still be running.
66 In large setups it might take some time to write all pending data to
67 the disk. You can adjust the waiting time in /etc/default/$NAME."
69 d_stop() {
70         PID=$( cat "$PIDFILE" 2> /dev/null ) || true
72         start-stop-daemon --stop --quiet --oknodo --pidfile "$PIDFILE"
74         sleep 1
75         if test -n "$PID" && kill -0 $PID 2> /dev/null; then
76                 i=0
77                 while kill -0 $PID 2> /dev/null; do
78                         i=$(( $i + 2 ))
79                         echo -n " ."
81                         if test $i -gt $MAXWAIT; then
82                                 echo "$still_running_warning" >&2
83                                 return 1
84                         fi
86                         sleep 2
87                 done
88                 return 0
89         fi
90 }
92 d_status() {
93         PID=$( cat "$PIDFILE" 2> /dev/null ) || true
95         if test -n "$PID" && kill -0 $PID 2> /dev/null; then
96                 echo "$NAME ($PID) is running."
97                 exit 0
98         else
99                 PID=$( pidof $NAME ) || true
101                 if test -n "$PID"; then
102                         echo "$NAME ($PID) is running."
103                         exit 0
104                 else
105                         echo "$NAME is stopped."
106                 fi
107         fi
108         exit 1
111 case "$1" in
112         start)
113                 echo -n "Starting $DESC: $NAME"
114                 d_start
115                 echo "."
116                 ;;
117         stop)
118                 echo -n "Stopping $DESC: $NAME"
119                 d_stop
120                 echo "."
121                 ;;
122         status)
123                 d_status
124                 ;;
125         restart|force-reload)
126                 echo -n "Restarting $DESC: $NAME"
127                 d_stop
128                 sleep 1
129                 d_start
130                 echo "."
131                 ;;
132         *)
133                 echo "Usage: $0 {start|stop|restart|force-reload|status}" >&2
134                 exit 1
135                 ;;
136 esac
138 exit 0
140 # vim: syntax=sh noexpandtab sw=4 ts=4 :