Code

rules: Fix the arch selection for enabling the gRPC plugin.
[pkg-collectd.git] / debian / collectd-core.collectd.init.d
1 #! /bin/bash
2 #
3 # collectd - start and stop the statistics collection daemon
4 # https://collectd.org/
5 #
6 # Copyright (C) 2005-2006 Florian Forster <octo@verplant.org>
7 # Copyright (C) 2006-2009 Sebastian Harl <tokkee@debian.org>
8 #
10 ### BEGIN INIT INFO
11 # Provides:          collectd
12 # Required-Start:    $local_fs $remote_fs
13 # Required-Stop:     $local_fs $remote_fs
14 # Should-Start:      $network $named $syslog $time cpufrequtils
15 # Should-Stop:       $network $named $syslog
16 # Default-Start:     2 3 4 5
17 # Default-Stop:      0 1 6
18 # Short-Description: manage the statistics collection daemon
19 # Description:       collectd is the statistics collection daemon.
20 #                    It is a small daemon which collects system information
21 #                    periodically and provides mechanisms to monitor and store
22 #                    the values in a variety of ways.
23 ### END INIT INFO
25 . /lib/lsb/init-functions
27 export PATH=/sbin:/bin:/usr/sbin:/usr/bin
29 DISABLE=0
31 DESC="statistics collection and monitoring daemon"
32 NAME=collectd
33 DAEMON=/usr/sbin/collectd
35 CONFIGFILE=/etc/collectd/collectd.conf
36 PIDFILE=/var/run/collectd.pid
38 USE_COLLECTDMON=1
39 COLLECTDMON_DAEMON=/usr/sbin/collectdmon
41 MAXWAIT=30
43 # Gracefully exit if the package has been removed.
44 test -x $DAEMON || exit 0
46 if [ -r /etc/default/$NAME ]; then
47         . /etc/default/$NAME
48 fi
50 if test "$ENABLE_COREFILES" == 1; then
51         ulimit -c unlimited
52 fi
54 # return:
55 #   0 if config is fine
56 #   1 if there is a syntax error
57 #   2 if there is no configuration
58 check_config() {
59         if test ! -e "$CONFIGFILE"; then
60                 return 2
61         fi
62         if ! $DAEMON -t -C "$CONFIGFILE"; then
63                 return 1
64         fi
65         return 0
66 }
68 # return:
69 #   0 if the daemon has been started
70 #   1 if the daemon was already running
71 #   2 if the daemon could not be started
72 #   3 if the daemon was not supposed to be started
73 d_start() {
74         if test "$DISABLE" != 0; then
75                 # we get here during restart
76                 log_progress_msg "disabled by /etc/default/$NAME"
77                 return 3
78         fi
80         if test ! -e "$CONFIGFILE"; then
81                 # we get here during restart
82                 log_progress_msg "disabled, no configuration ($CONFIGFILE) found"
83                 return 3
84         fi
86         check_config
87         rc="$?"
88         if test "$rc" -ne 0; then
89                 log_progress_msg "not starting, configuration error"
90                 return 2
91         fi
93         if test "$USE_COLLECTDMON" == 1; then
94                 start-stop-daemon --start --quiet --oknodo --pidfile "$PIDFILE" \
95                         --exec $COLLECTDMON_DAEMON -- -P "$PIDFILE" -- -C "$CONFIGFILE" \
96                         || return 2
97         else
98                 start-stop-daemon --start --quiet --oknodo --pidfile "$PIDFILE" \
99                         --exec $DAEMON -- -C "$CONFIGFILE" -P "$PIDFILE" \
100                         || return 2
101         fi
102         return 0
105 still_running_warning="
106 WARNING: $NAME might still be running.
107 In large setups it might take some time to write all pending data to
108 the disk. You can adjust the waiting time in /etc/default/collectd."
110 # return:
111 #   0 if the daemon has been stopped
112 #   1 if the daemon was already stopped
113 #   2 if daemon could not be stopped
114 d_stop() {
115         PID=$( cat "$PIDFILE" 2> /dev/null ) || true
117         start-stop-daemon --stop --quiet --oknodo --pidfile "$PIDFILE"
118         rc="$?"
120         if test "$rc" -eq 2; then
121                 return 2
122         fi
124         sleep 1
125         if test -n "$PID" && kill -0 $PID 2> /dev/null; then
126                 i=0
127                 while kill -0 $PID 2> /dev/null; do
128                         i=$(( $i + 2 ))
129                         echo -n " ."
131                         if test $i -gt $MAXWAIT; then
132                                 log_progress_msg "$still_running_warning"
133                                 return 2
134                         fi
136                         sleep 2
137                 done
138                 return "$rc"
139         fi
140         return "$rc"
143 case "$1" in
144         start)
145                 log_daemon_msg "Starting $DESC" "$NAME"
146                 d_start
147                 case "$?" in
148                         0|1) log_end_msg 0 ;;
149                         2) log_end_msg 1 ;;
150                         3) log_end_msg 255; true ;;
151                         *) log_end_msg 1 ;;
152                 esac
153                 ;;
154         stop)
155                 log_daemon_msg "Stopping $DESC" "$NAME"
156                 d_stop
157                 case "$?" in
158                         0|1) log_end_msg 0 ;;
159                         2) log_end_msg 1 ;;
160                 esac
161                 ;;
162         status)
163                 status_of_proc -p "$PIDFILE" "$DAEMON" "$NAME" && exit 0 || exit $?
164                 ;;
165         restart|force-reload)
166                 log_daemon_msg "Restarting $DESC" "$NAME"
167                 check_config
168                 rc="$?"
169                 if test "$rc" -eq 1; then
170                         log_progress_msg "not restarting, configuration error"
171                         log_end_msg 1
172                         exit 1
173                 fi
174                 d_stop
175                 rc="$?"
176                 case "$rc" in
177                         0|1)
178                                 sleep 1
179                                 d_start
180                                 rc2="$?"
181                                 case "$rc2" in
182                                         0|1) log_end_msg 0 ;;
183                                         2) log_end_msg 1 ;;
184                                         3) log_end_msg 255; true ;;
185                                         *) log_end_msg 1 ;;
186                                 esac
187                                 ;;
188                         *)
189                                 log_end_msg 1
190                                 ;;
191                 esac
192                 ;;
193         *)
194                 echo "Usage: $0 {start|stop|restart|force-reload|status}" >&2
195                 exit 3
196                 ;;
197 esac
199 # vim: syntax=sh noexpandtab sw=4 ts=4 :