Assorted improvements to OpenRC support. (#14620)
* Add OpenRC conf.d file for Netdata. * Tidy-up handling of retry schedule. It should be computed in stop_pre so it gets evaluated after the conf file, and it also needs to handle variables not being defined properly (which it currently does not). * Add a service description and command descriptions. * Only install `/etc/conf.d/netdata` if it does not already exist. This prevents overwriting user configuration.
Austin S. Hemmelgarn committed
Mar 1, 2023 at 07:27 UTC
4c20aca875a0784ff807c980a8fae2f7fb7d51a0
4 files changed
+58
-23
system/Makefile.am
+8
@@ -9,6 +9,7 @@ CLEANFILES = \
9
launchd/netdata.plist \
10
logrotate/netdata \
11
lsb/init.d/netdata \
12
+ openrc/conf.d/netdata \
13
openrc/init.d/netdata \
14
systemd/netdata.service \
15
systemd/netdata.service.v235 \
@@ -37,6 +38,7 @@ libsyslsbdir=$(libsysdir)/lsb
38
libsyslsbinitddir=$(libsyslsbdir)/init.d
39
libsysopenrcdir=$(libsysdir)/openrc
40
libsysopenrcinitddir=$(libsysopenrcdir)/init.d
41
+libsysopenrcconfddir=$(libsysopenrcdir)/conf.d
42
libsyssystemddir=$(libsysdir)/systemd
43
44
# Explicitly install directories to avoid permission issues due to umask
@@ -51,6 +53,7 @@ install-exec-local:
53
$(INSTALL) -d $(DESTDIR)$(libsyslsbinitddir)
54
$(INSTALL) -d $(DESTDIR)$(libsyssystemddir)
55
$(INSTALL) -d $(DESTDIR)$(libsysopenrcinitddir)
56
+ $(INSTALL) -d $(DESTDIR)$(libsysopenrcconfddir)
57
58
libexecnetdatadir=$(libexecdir)/netdata
59
nodist_libexecnetdata_SCRIPTS = \
@@ -85,6 +88,10 @@ nodist_libsysopenrcinitd_DATA = \
88
openrc/init.d/netdata \
89
$(NULL)
90
91
+nodist_libsysopenrcconfd_DATA = \
92
+ openrc/conf.d/netdata \
93
+ $(NULL)
94
+
95
nodist_libsyssystemd_DATA = \
96
systemd/netdata.service \
97
systemd/netdata.service.v235 \
@@ -104,6 +111,7 @@ dist_noinst_DATA = \
111
launchd/netdata.plist.in \
112
logrotate/netdata.in \
113
lsb/init.d/netdata.in \
114
+ openrc/conf.d/netdata.in \
115
openrc/init.d/netdata.in \
116
systemd/netdata.service.in \
117
systemd/netdata.service.v235.in \
system/install-service.sh.in
+11
@@ -290,6 +290,9 @@ _check_openrc() {
290
# if there is no /etc/init.d, it's not OpenRC
291
[ ! -d /etc/init.d ] && echo "NO" && return 0
292
293
+ # if there is no /etc/conf.d, it's not OpenRC
294
+ [ ! -d /etc/conf.d ] && echo "NO" && return 0
295
+
296
# if there is no rc-update command, it's not OpenRC
297
[ -z "$(command -v rc-update 2>/dev/null || true)" ] && echo "NO" && return 0
298
@@ -342,6 +345,14 @@ disable_openrc() {
345
346
install_openrc_service() {
347
install_generic_service openrc/init.d OpenRC /etc/init.d/netdata enable_openrc disable_openrc
348
+
349
+ if [ ! -f /etc/conf.d/netdata ]; then
350
+ info "Installing OpenRC configuration file."
351
+
352
+ if ! install -p -m 0755 -o 0 -g 0 "${SVC_SOURCE}/openrc/conf.d/netdata" "/etc/conf.d/netdata"; then
353
+ warning "Failed to install configuration file, however the service will still work."
354
+ fi
355
+ fi
356
}
357
358
openrc_cmds() {
system/openrc/conf.d/netdata.in
new
+24
@@ -0,0 +1,24 @@
1
+# The user netdata is configured to run as.
2
+# If you edit its configuration file to set a different user, set it
3
+# here too, to have its files switch ownership
4
+NETDATA_OWNER="@netdata_user_POST@:@netdata_user_POST@"
5
+
6
+# How long to wait for the agent to save it's database during shutdown.
7
+NETDATA_WAIT_EXIT_TIMEOUT=60
8
+
9
+# If set to 1, force an exit if we time out waiting for the agent to
10
+# save it's database during shutdown.
11
+NETDATA_FORCE_EXIT=0
12
+
13
+# If set to 1, use netdatacli when sending commands to the agent.
14
+# This should not be needed in most cases, but it can sometimes help
15
+# work around issues.
16
+#NETDATA_USE_NETDATACLI=1
17
+
18
+# Specify the path to the pidfile to be used when running in the
19
+# background.
20
+NETDATA_PIDFILE="@localstatedir_POST@/run/netdata/netdata.pid"
21
+
22
+# Uncomment the below line to run Netdata under OpenRC's native process
23
+# supervision.
24
+#supervisor="supervise-daemon"
system/openrc/init.d/netdata.in
+15
-23
@@ -1,37 +1,21 @@
1
#!/sbin/openrc-run
2
# SPDX-License-Identifier: GPL-3.0-or-later
3
4
-# The user netdata is configured to run as.
5
-# If you edit its configuration file to set a different
6
-# user, set it here too, to have its files switch ownership
7
-: "${NETDATA_OWNER:=@netdata_user_POST@:@netdata_user_POST@}"
4
+NETDATA_OWNER="@netdata_user_POST@:@netdata_user_POST@"
5
+NETDATA_PIDFILE="@localstatedir_POST@/run/netdata/netdata.pid"
6
9
-# The timeout in seconds to wait for netdata
10
-# to save its database on disk and exit.
11
-: "${NETDATA_WAIT_EXIT_TIMEOUT:=60}"
12
-
13
-# When set to 1, if netdata does not exit in
14
-# NETDATA_WAIT_EXIT_TIMEOUT, we will force it
15
-# to exit.
16
-: "${NETDATA_FORCE_EXIT:=0}"
17
-
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}"
7
+description="Run the Netdata system monitoring agent."
8
9
extra_started_commands="reload rotate save"
10
+description_reload="Reload health configuration."
11
+description_rotate="Reopen log files."
12
+description_save="Force sync of database to disk."
13
+
14
command_prefix="@sbindir_POST@"
15
command="${command_prefix}/netdata"
16
command_args="-P ${NETDATA_PIDFILE} ${NETDATA_EXTRA_ARGS}"
17
command_args_foreground="-D"
18
start_stop_daemon_args="-u ${NETDATA_OWNER}"
30
-if [ "${NETDATA_FORCE_EXIT}" -eq 1 ]; then
31
- retry="TERM/${NETDATA_WAIT_EXIT_TIMEOUT}/KILL/1"
32
-else
33
- retry="TERM/${NETDATA_WAIT_EXIT_TIMEOUT}"
34
-fi
19
20
depend() {
21
use logger
@@ -47,6 +31,14 @@ start_pre() {
31
fi
32
}
33
34
+stop_pre() {
35
+ if [ "0${NETDATA_FORCE_EXIT}" -eq 1 ]; then
36
+ retry="TERM/${NETDATA_WAIT_EXIT_TIMEOUT:-60}/KILL/1"
37
+ else
38
+ retry="TERM/${NETDATA_WAIT_EXIT_TIMEOUT:-60}"
39
+ fi
40
+}
41
+
42
run_cmd() {
43
cmd="${1}"
44
msg="${2}"