]> arthur.barton.de Git - netdata.git/blob - system/netdata-openrc.in
Removed 'netdata' folder in service files
[netdata.git] / system / netdata-openrc.in
1 #!/sbin/runscript
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="-pidfile ${pidfile} ${NETDATA_EXTRA_ARGS}"
29 start_stop_daemon_args="-u ${NETDATA_OWNER}"
30
31 depend() {
32         use logger
33         need net
34         after ${NETDATA_START_AFTER_SERVICES}
35
36         checkpath -o ${NETDATA_OWNER} -d @localstatedir_POST@/cache/netdata /run/netdata
37 }
38
39 start_post() {
40         if [[ ! -f @sysconfdir_POST@/netdata/netdata.conf ]]; then
41                 ebegin "Downloading default configuration to @sysconfdir_POST@/netdata/netdata.conf"
42                 sleep 2
43                 curl -s -o @sysconfdir_POST@/netdata/netdata.conf.new "${NETDATA_CONFIG_URL}"
44                 ret=$?
45                 if [[ $ret -eq 0 && -s @sysconfdir_POST@/netdata/netdata.conf.new ]]; then
46                         mv @sysconfdir_POST@/netdata/netdata.conf{.new,}
47                 else
48                         ret=1
49                         rm @sysconfdir_POST@/netdata/netdata.conf.new 2>/dev/null
50                 fi
51                 eend $ret
52         fi
53 }
54
55 stop_post() {
56         local result ret=0 count=0 sigkill=0
57
58         ebegin "Waiting for netdata to save its database"
59         while [[ -f "${pidfile}" ]]; do
60                 if [[ $count -gt ${NETDATA_WAIT_EXIT_TIMEOUT} ]]; then
61                         sigkill=1
62                         break
63                 fi
64
65                 count=$[count + 1]
66                 kill -0 $(cat ${pidfile}) 2>/dev/null
67                 ret=$?
68                 test $ret -eq 0 && sleep 1
69         done
70         eend $sigkill
71
72         if [[ $sigkill -eq 1 && -f "${pidfile}" ]]; then
73                 ebegin "Netdata is taking too long to exit, forcing it to quit"
74                 kill -SIGKILL $(cat ${pidfile}) 2>/dev/null
75                 eend $?
76         fi
77 }
78
79 getconf() {
80         ebegin "Downloading configuration from netdata to /tmp/netdata.conf"
81         curl -o /tmp/netdata.conf "${NETDATA_CONFIG_URL}"
82         eend $?
83 }