summaryrefslogtreecommitdiffstats
path: root/system/lsb/init.d/netdata.in
blob: e429ad1c93f5a50fe01f6e899db0c3bab8755181 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env bash
#
# Netdata LSB start script
#
# Copyright:
#         SPDX-License-Identifier: GPL-3.0-or-later
#
# Author:
#         Costa Tsaousis  <costa@netdata.cloud>
#         Pavlos Emm. Katsoulakis <paul@netdata.cloud>

### BEGIN INIT INFO
# Provides:          netdata
# Required-Start:    $local_fs $remote_fs $network $named $time
# Required-Stop:     $local_fs $remote_fs $network $named $time
# Should-Start:      $local_fs $network $named $remote_fs $time $all
# Should-Stop:       $local_fs $network $named $remote_fs $time $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start and stop the netdata real-time monitoring server daemon
# Description:       Controls the main netdata monitoring server daemon "netdata".
#                    and all its plugins.
### END INIT INFO
#
set -e
set -u
${DEBIAN_SCRIPT_DEBUG:+ set -v -x}

DAEMON="netdata"
DAEMON_PATH=@sbindir_POST@
PIDFILE_PATH=@localstatedir_POST@/run/netdata
PIDFILE=$PIDFILE_PATH/$DAEMON.pid
DAEMONOPTS="-P $PIDFILE"

test -x $DAEMON_PATH/$DAEMON || exit 0

. /lib/lsb/init-functions

# Safeguard (relative paths, core dumps..)
cd /
umask 022

service_start() {
	if [ ! -d $PIDFILE_PATH ]; then
		mkdir -p $PIDFILE_PATH
	fi
	
	chown @netdata_user_POST@:@netdata_user_POST@ $PIDFILE_PATH
	
	log_daemon_msg "Starting real-time performance monitoring" "netdata"
	start_daemon -p $PIDFILE $DAEMON_PATH/$DAEMON $DAEMONOPTS
	RETVAL=$?
	log_end_msg $RETVAL
	return $RETVAL
}

service_stop() {
	log_daemon_msg "Stopping real-time performance monitoring" "netdata"
	killproc -p ${PIDFILE} $DAEMON_PATH/$DAEMON
	RETVAL=$?
	log_end_msg $RETVAL

	if [ $RETVAL -eq 0 ]; then
		rm -f ${PIDFILE}
	fi
	return $RETVAL
}

condrestart() {
	if ! service_status > /dev/null; then
		RETVAL=$1
		return
	fi

	service_stop
	service_start
}

service_status() {
	status_of_proc -p $PIDFILE $DAEMON_PATH/$DAEMON netdata
}


#
# main()
#

case "${1:-''}" in
	'start')
		service_start
		;;

	'stop')
		service_stop
		;;

	'restart')
		service_stop
		service_start
		;;

	'try-restart')
		condrestart 0
		;;

	'force-reload')
		condrestart 7
		;;

	'status')
		service_status && exit 0 || exit $?
		;;
	*)
		echo "Usage: $0 {start|stop|restart|try-restart|force-reload|status}"
		exit 1
esac