@cryptotaxi247 / netdata-1 / commits / 51c81e8c4

update openrc init script

Quote variables where able. Switch to a more posix double 'and'. Remove unused variables. The exit timeout was fixed. We also remove fetching the configuration from the init script (it should not live in it). Further we define reload rotate and save commands to prevent the need to restart all the time.

Matthew Thode committed Apr 3, 2018 at 10:12 UTC 51c81e8c4f1ae1b3c565aed66e2816e3321ff8ae
1 file changed +29 -56
system/netdata-openrc.in
+29 -56
@@ -3,82 +3,55 @@
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}
6 +: "${NETDATA_OWNER:=netdata:netdata}"
7
8 # The timeout in seconds to wait for netdata
9 # to save its database on disk and exit.
13 -: ${NETDATA_WAIT_EXIT_TIMEOUT:=60}
10 +: "${NETDATA_WAIT_EXIT_TIMEOUT:=60}"
11
12 # When set to 1, if netdata does not exit in
13 # NETDATA_WAIT_EXIT_TIMEOUT, we will force it
14 # to exit.
18 -: ${NETDATA_FORCE_EXIT:=0}
15 +: "${NETDATA_FORCE_EXIT:=0}"
16
17 # Netdata will use these services, only if they
18 # are enabled to start.
22 -: ${NETDATA_START_AFTER_SERVICES:=apache2 squid nginx mysql named opensips upsd hostapd postfix lm_sensors}
19 +: "${NETDATA_START_AFTER_SERVICES:=apache2 squid nginx mysql named opensips upsd hostapd postfix lm_sensors}"
20
24 -extra_started_commands="getconf"
25 -pidfile="/run/netdata.pid"
21 +extra_started_commands="reload rotate save"
22 +pidfile="/run/netdata/netdata.pid"
23 command="@sbindir_POST@/netdata"
27 -command_background="yes"
24 command_args="-P ${pidfile} ${NETDATA_EXTRA_ARGS}"
29 -# start_stop_daemon_args="-u ${NETDATA_OWNER}"
30 -start_stop_daemon_args=""
25 +start_stop_daemon_args="-u ${NETDATA_OWNER}"
26 +required_files="/etc/netdata/netdata.conf"
27 +if [ "${NETDATA_FORCE_EXIT}" -eq 1 ]; then
28 + retry="TERM/${NETDATA_WAIT_EXIT_TIMEOUT}/KILL/1"
29 +else
30 + retry="TERM/${NETDATA_WAIT_EXIT_TIMEOUT}"
31 +fi
32
33 depend() {
33 - use logger
34 - need net
35 - after ${NETDATA_START_AFTER_SERVICES}
34 + use logger
35 + need net
36 + after ${NETDATA_START_AFTER_SERVICES}
37
37 - checkpath -o ${NETDATA_OWNER} -d @localstatedir_POST@/cache/netdata /run/netdata
38 + checkpath -o ${NETDATA_OWNER} -d @localstatedir_POST@/cache/netdata /run/netdata
39 }
40
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 @sysconfdir_POST@/netdata/netdata.conf
48 - else
49 - ret=1
50 - rm @sysconfdir_POST@/netdata/netdata.conf.new 2>/dev/null
51 - fi
52 - eend $ret
53 - fi
41 +reload() {
42 + ebegin "Reloading Netdata"
43 + start-stop-daemon --signal SIGUSR2 --pidfile "${pidfile}"
44 + eend $? "Failed to reload Netdata"
45 }
46
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 -a -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
47 +rotate() {
48 + ebegin "Logrotating Netdata"
49 + start-stop-daemon --signal SIGHUP --pidfile "${pidfile}"
50 + eend $? "Failed to logrotate Netdata"
51 }
52
80 -getconf() {
81 - ebegin "Downloading configuration from netdata to /tmp/netdata.conf"
82 - curl -o /tmp/netdata.conf "${NETDATA_CONFIG_URL}"
83 - eend $?
53 +save() {
54 + ebegin "Saving Netdata database"
55 + start-stop-daemon --signal SIGUSR1 --pidfile "${pidfile}"
56 + eend $? "Failed to save Netdata database"
57 }