]> arthur.barton.de Git - netdata.git/blob - system/netdata-openrc.in
fail2bain plugin: "Currently In Jail" chart renamed
[netdata.git] / system / netdata-openrc.in
1 #!/sbin/openrc-run
2
3 # The user netdata is configured to run as.
4 # If you edit its configuration file to set a different
5 # user, set it here too, to have its files switch ownership
6 : ${NETDATA_OWNER:=netdata:netdata}
7
8 # The URL to download netdata config.
9 : ${NETDATA_CONFIG_URL:=http://localhost:19999/netdata.conf}
10
11 # The timeout in seconds to wait for netdata
12 # to save its database on disk and exit.
13 : ${NETDATA_WAIT_EXIT_TIMEOUT:=15}
14
15 # When set to 1, if netdata does not exit in
16 # NETDATA_WAIT_EXIT_TIMEOUT, we will force it
17 # to exit.
18 : ${NETDATA_FORCE_EXIT:=0}
19
20 # Netdata will use these services, only if they
21 # are enabled to start.
22 : ${NETDATA_START_AFTER_SERVICES:=apache2 squid nginx mysql named opensips upsd hostapd postfix lm_sensors}
23
24 extra_started_commands="getconf"
25 pidfile="/run/netdata.pid"
26 command="${NETDATA_INSTALL_PATH}/usr/sbin/netdata"
27 command_background="yes"
28 command_args="-P ${pidfile} ${NETDATA_EXTRA_ARGS}"
29 # start_stop_daemon_args="-u ${NETDATA_OWNER}"
30 start_stop_daemon_args=""
31
32 depend() {
33         use logger
34         need net
35         after ${NETDATA_START_AFTER_SERVICES}
36
37         checkpath -o ${NETDATA_OWNER} -d @localstatedir_POST@/cache/netdata /run/netdata
38 }
39
40 start_post() {
41         if [[ ! -f @sysconfdir_POST@/netdata/netdata.conf ]]; then
42                 ebegin "Downloading default configuration to @sysconfdir_POST@/netdata/netdata.conf"
43                 sleep 2
44                 curl -s -o @sysconfdir_POST@/netdata/netdata.conf.new "${NETDATA_CONFIG_URL}"
45                 ret=$?
46                 if [[ $ret -eq 0 && -s @sysconfdir_POST@/netdata/netdata.conf.new ]]; then
47                         mv @sysconfdir_POST@/netdata/netdata.conf{.new,}
48                 else
49                         ret=1
50                         rm @sysconfdir_POST@/netdata/netdata.conf.new 2>/dev/null
51                 fi
52                 eend $ret
53         fi
54 }
55
56 stop_post() {
57         local result ret=0 count=0 sigkill=0
58
59         ebegin "Waiting for netdata to save its database"
60         while [[ -f "${pidfile}" ]]; do
61                 if [[ $count -gt ${NETDATA_WAIT_EXIT_TIMEOUT} ]]; then
62                         sigkill=1
63                         break
64                 fi
65
66                 count=$[count + 1]
67                 kill -0 $(cat ${pidfile}) 2>/dev/null
68                 ret=$?
69                 test $ret -eq 0 && sleep 1
70         done
71         eend $sigkill
72
73         if [[ $sigkill -eq 1 && -f "${pidfile}" ]]; then
74                 ebegin "Netdata is taking too long to exit, forcing it to quit"
75                 kill -SIGKILL $(cat ${pidfile}) 2>/dev/null
76                 eend $?
77         fi
78 }
79
80 getconf() {
81         ebegin "Downloading configuration from netdata to /tmp/netdata.conf"
82         curl -o /tmp/netdata.conf "${NETDATA_CONFIG_URL}"
83         eend $?
84 }