@cryptotaxi247 / netdata-1 / commits / 2da50b591

Assorted cleanup in the OpenRC init script. (#13115)

* Properly handle service dependencies in OpenRC init script. This removes the `NETDATA_START_AFTER_SERVICES` variable from our OpenRC script. This variable made the script somewhat harder to read, and did not actually provide any additional functionality (users can simply define appropriate `rc_after` values in `/etc/conf.d/netdata` to achieve exactly the same net effect).. * Provide more concrete descriptions for OpenRC commands. Updates the command descriptions in the OpenRC init script to properly describe exactly what they are doing, instead of going with generic and rather ambiguous names. * Allow use of netdatacli for additional commands in OpenRC init script. This makes life simpler for users who want to run the agent under OpenRC’s native process supervision, which does not allow use of `start-stop-daemon` commands in the init script. Existing behavior (using `start-stop-daemon`) is preserved as the default. * Fix background command handling. THe `pidfile` variable should only be set if the agent is not being run under `supervise-daemon`. * COnsolidate code from additional commands, and handle supervise-daemon correctly. * Fix typo. * Remove pointless `require_files` line. We don’t actually do anything in the script that cares about the config file existing, and the agent starts fine without it, so we should not be requiring it to be present.

Austin S. Hemmelgarn committed Oct 25, 2022 at 07:33 UTC 2da50b591b1b6a5450f84252e619cdcb69360797
1 file changed +45 -17
system/netdata-openrc.in
+45 -17
@@ -15,16 +15,18 @@
15 # to exit.
16 : "${NETDATA_FORCE_EXIT:=0}"
17
18 -# Netdata will use these services, only if they
19 -# are enabled to start.
20 -: "${NETDATA_START_AFTER_SERVICES:=apache2 squid nginx mysql named opensips upsd hostapd postfix lm_sensors}"
18 +# When set to 1, we use netdatacli for reload/rotate/save commands instead of s-s-d.
19 +: "${NETDATA_USE_NETDATACLI:=0}"
20 +
21 +# Specifies the pidfile to use when running in the background.
22 +: "${NETDATA_PIDFILE:=@localstatedir_POST@/run/netdata/netdata.pid}"
23
24 extra_started_commands="reload rotate save"
23 -pidfile="@localstatedir_POST@/run/netdata/netdata.pid"
24 -command="@sbindir_POST@/netdata"
25 -command_args="-P ${pidfile} ${NETDATA_EXTRA_ARGS}"
25 +command_prefix="@sbindir_POST@"
26 +command="${command_prefix}/netdata"
27 +command_args="-P ${NETDATA_PIDFILE} ${NETDATA_EXTRA_ARGS}"
28 +command_args_foreground="-D"
29 start_stop_daemon_args="-u ${NETDATA_OWNER}"
27 -required_files="/etc/netdata/netdata.conf"
30 if [ "${NETDATA_FORCE_EXIT}" -eq 1 ]; then
31 retry="TERM/${NETDATA_WAIT_EXIT_TIMEOUT}/KILL/1"
32 else
@@ -34,27 +36,53 @@ fi
36 depend() {
37 use logger
38 need net
37 - after ${NETDATA_START_AFTER_SERVICES}
39 + after apache2 squid nginx mysql named opensips upsd hostapd postfix lm_sensors
40 }
41
42 start_pre() {
43 checkpath -o ${NETDATA_OWNER} -d @localstatedir_POST@/cache/netdata @localstatedir_POST@/run/netdata
44 +
45 + if [ -z "${supervisor}" ]; then
46 + pidfile="${NETDATA_PIDFILE}"
47 + fi
48 +}
49 +
50 +run_cmd() {
51 + cmd="${1}"
52 + msg="${2}"
53 + failmsg="${3}"
54 + signal="${4}"
55 +
56 + ebegin "${msg}"
57 + if [ "${NETDATA_USE_NETDATACLI}" = 1 ]; then
58 + "${command_prefix}/netdatacli" "${cmd}" >/dev/null
59 + eend $? "${failmsg}"
60 + elif [ "${supervisor}" = "supervise-daemon" ]; then
61 + supervise-daemon "${RC_SVCNAME}" --signal "${signal}"
62 + eend $? "${failmsg}"
63 + else
64 + start-stop-daemon --signal "${signal}" --pidfile "${pidfile}"
65 + eend $? "${failmsg}"
66 + fi
67 }
68
69 reload() {
45 - ebegin "Reloading Netdata"
46 - start-stop-daemon --signal SIGUSR2 --pidfile "${pidfile}"
47 - eend $? "Failed to reload Netdata"
70 + run_cmd reload-health \
71 + "Reloading Netdata health configuration" \
72 + "Failed to reload Netdata health configuration" \
73 + SIGUSR2
74 }
75
76 rotate() {
51 - ebegin "Logrotating Netdata"
52 - start-stop-daemon --signal SIGHUP --pidfile "${pidfile}"
53 - eend $? "Failed to logrotate Netdata"
77 + run_cmd reopen-logs \
78 + "Reopening Netdata log files" \
79 + "Failed to reopen Netdata log files" \
80 + SIGHUP
81 }
82
83 save() {
57 - ebegin "Saving Netdata database"
58 - start-stop-daemon --signal SIGUSR1 --pidfile "${pidfile}"
59 - eend $? "Failed to save Netdata database"
84 + run_cmd save-database \
85 + "Saving Netdata database" \
86 + "Failed to save Netdata database" \
87 + SIGUSR1
88 }