]> arthur.barton.de Git - netdata.git/blob - system/netdata-lsb.in
Merge pull request #2022 from l2isbad/dns_query_time_fixes
[netdata.git] / system / netdata-lsb.in
1 #!/bin/bash
2 #
3 ### BEGIN INIT INFO
4 # Provides:          netdata
5 # Required-Start:    $local_fs $remote_fs $network $named $time apache2 httpd squid nginx mysql named opensips upsd hostapd postfix lm_sensors
6 # Required-Stop:     $local_fs $remote_fs $network $named $time apache2 httpd squid nginx mysql named opensips upsd hostapd postfix lm_sensors
7 # Should-Start:      $local_fs $network $named $remote_fs $time $all
8 # Should-Stop:       $local_fs $network $named $remote_fs $time $all
9 # Default-Start:     2 3 4 5
10 # Default-Stop:      0 1 6
11 # Short-Description: Start and stop the netdata real-time monitoring server daemon
12 # Description:       Controls the main netdata monitoring server daemon "netdata".
13 #                    and all its plugins.
14 ### END INIT INFO
15 #
16 set -e
17 set -u
18 ${DEBIAN_SCRIPT_DEBUG:+ set -v -x}
19
20 DAEMON="netdata"
21 DAEMON_PATH=@sbindir_POST@
22 PIDFILE=@localstatedir_POST@/run/$DAEMON.pid
23 DAEMONOPTS="-P $PIDFILE"
24
25 test -x $DAEMON_PATH/$DAEMON || exit 0
26
27 . /lib/lsb/init-functions
28
29 # Safeguard (relative paths, core dumps..)
30 cd /
31 umask 022
32
33 service_start() {
34         log_daemon_msg "Starting real-time performance monitoring" "netdata"
35         start_daemon -p $PIDFILE $DAEMON_PATH/$DAEMON $DAEMONOPTS
36         RETVAL=$?
37         log_end_msg $RETVAL
38         return $RETVAL
39 }
40
41 service_stop() {
42         log_daemon_msg "Stopping real-time performance monitoring" "netdata"
43         killproc -p ${PIDFILE} $DAEMON_PATH/$DAEMON
44         RETVAL=$?
45         log_end_msg $RETVAL
46
47         if [ $RETVAL -eq 0 ]; then
48                 rm -f ${PIDFILE}
49         fi
50         return $RETVAL
51 }
52
53 condrestart() {
54         if ! service_status > /dev/null; then
55                 RETVAL=$1
56                 return
57         fi
58
59         service_stop
60         service_start
61 }
62
63 service_status() {
64         status_of_proc -p $PIDFILE $DAEMON_PATH/$DAEMON netdata
65 }
66
67
68 #
69 # main()
70 #
71
72 case "${1:-''}" in
73         'start')
74                 service_start
75                 ;;
76
77         'stop')
78                 service_stop
79                 ;;
80
81         'restart')
82                 service_stop
83                 service_start
84                 ;;
85
86         'try-restart')
87                 condrestart 0
88                 ;;
89
90         'force-reload')
91                 condrestart 7
92                 ;;
93
94         'status')
95                 service_status && exit 0 || exit $?
96                 ;;
97         *)
98                 echo "Usage: $0 {start|stop|restart|try-restart|force-reload|status}"
99                 exit 1
100 esac