Code

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