0
0
Fork 0
mirror of https://github.com/netdata/netdata.git synced 2025-04-02 20:48:06 +00:00

Assorted improvements to OpenRC support. ()

* 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.
This commit is contained in:
Austin S. Hemmelgarn 2023-03-01 07:27:32 -05:00 committed by GitHub
parent f3f58081c8
commit 4c20aca875
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 23 deletions

View file

@ -9,6 +9,7 @@ CLEANFILES = \
launchd/netdata.plist \
logrotate/netdata \
lsb/init.d/netdata \
openrc/conf.d/netdata \
openrc/init.d/netdata \
systemd/netdata.service \
systemd/netdata.service.v235 \
@ -37,6 +38,7 @@ libsyslsbdir=$(libsysdir)/lsb
libsyslsbinitddir=$(libsyslsbdir)/init.d
libsysopenrcdir=$(libsysdir)/openrc
libsysopenrcinitddir=$(libsysopenrcdir)/init.d
libsysopenrcconfddir=$(libsysopenrcdir)/conf.d
libsyssystemddir=$(libsysdir)/systemd
# Explicitly install directories to avoid permission issues due to umask
@ -51,6 +53,7 @@ install-exec-local:
$(INSTALL) -d $(DESTDIR)$(libsyslsbinitddir)
$(INSTALL) -d $(DESTDIR)$(libsyssystemddir)
$(INSTALL) -d $(DESTDIR)$(libsysopenrcinitddir)
$(INSTALL) -d $(DESTDIR)$(libsysopenrcconfddir)
libexecnetdatadir=$(libexecdir)/netdata
nodist_libexecnetdata_SCRIPTS = \
@ -85,6 +88,10 @@ nodist_libsysopenrcinitd_DATA = \
openrc/init.d/netdata \
$(NULL)
nodist_libsysopenrcconfd_DATA = \
openrc/conf.d/netdata \
$(NULL)
nodist_libsyssystemd_DATA = \
systemd/netdata.service \
systemd/netdata.service.v235 \
@ -104,6 +111,7 @@ dist_noinst_DATA = \
launchd/netdata.plist.in \
logrotate/netdata.in \
lsb/init.d/netdata.in \
openrc/conf.d/netdata.in \
openrc/init.d/netdata.in \
systemd/netdata.service.in \
systemd/netdata.service.v235.in \

View file

@ -290,6 +290,9 @@ _check_openrc() {
# if there is no /etc/init.d, it's not OpenRC
[ ! -d /etc/init.d ] && echo "NO" && return 0
# if there is no /etc/conf.d, it's not OpenRC
[ ! -d /etc/conf.d ] && echo "NO" && return 0
# if there is no rc-update command, it's not OpenRC
[ -z "$(command -v rc-update 2>/dev/null || true)" ] && echo "NO" && return 0
@ -342,6 +345,14 @@ disable_openrc() {
install_openrc_service() {
install_generic_service openrc/init.d OpenRC /etc/init.d/netdata enable_openrc disable_openrc
if [ ! -f /etc/conf.d/netdata ]; then
info "Installing OpenRC configuration file."
if ! install -p -m 0755 -o 0 -g 0 "${SVC_SOURCE}/openrc/conf.d/netdata" "/etc/conf.d/netdata"; then
warning "Failed to install configuration file, however the service will still work."
fi
fi
}
openrc_cmds() {

View file

@ -0,0 +1,24 @@
# The user netdata is configured to run as.
# If you edit its configuration file to set a different user, set it
# here too, to have its files switch ownership
NETDATA_OWNER="@netdata_user_POST@:@netdata_user_POST@"
# How long to wait for the agent to save it's database during shutdown.
NETDATA_WAIT_EXIT_TIMEOUT=60
# If set to 1, force an exit if we time out waiting for the agent to
# save it's database during shutdown.
NETDATA_FORCE_EXIT=0
# If set to 1, use netdatacli when sending commands to the agent.
# This should not be needed in most cases, but it can sometimes help
# work around issues.
#NETDATA_USE_NETDATACLI=1
# Specify the path to the pidfile to be used when running in the
# background.
NETDATA_PIDFILE="@localstatedir_POST@/run/netdata/netdata.pid"
# Uncomment the below line to run Netdata under OpenRC's native process
# supervision.
#supervisor="supervise-daemon"

View file

@ -1,37 +1,21 @@
#!/sbin/openrc-run
# SPDX-License-Identifier: GPL-3.0-or-later
# The user netdata is configured to run as.
# If you edit its configuration file to set a different
# user, set it here too, to have its files switch ownership
: "${NETDATA_OWNER:=@netdata_user_POST@:@netdata_user_POST@}"
NETDATA_OWNER="@netdata_user_POST@:@netdata_user_POST@"
NETDATA_PIDFILE="@localstatedir_POST@/run/netdata/netdata.pid"
# The timeout in seconds to wait for netdata
# to save its database on disk and exit.
: "${NETDATA_WAIT_EXIT_TIMEOUT:=60}"
# When set to 1, if netdata does not exit in
# NETDATA_WAIT_EXIT_TIMEOUT, we will force it
# to exit.
: "${NETDATA_FORCE_EXIT:=0}"
# When set to 1, we use netdatacli for reload/rotate/save commands instead of s-s-d.
: "${NETDATA_USE_NETDATACLI:=0}"
# Specifies the pidfile to use when running in the background.
: "${NETDATA_PIDFILE:=@localstatedir_POST@/run/netdata/netdata.pid}"
description="Run the Netdata system monitoring agent."
extra_started_commands="reload rotate save"
description_reload="Reload health configuration."
description_rotate="Reopen log files."
description_save="Force sync of database to disk."
command_prefix="@sbindir_POST@"
command="${command_prefix}/netdata"
command_args="-P ${NETDATA_PIDFILE} ${NETDATA_EXTRA_ARGS}"
command_args_foreground="-D"
start_stop_daemon_args="-u ${NETDATA_OWNER}"
if [ "${NETDATA_FORCE_EXIT}" -eq 1 ]; then
retry="TERM/${NETDATA_WAIT_EXIT_TIMEOUT}/KILL/1"
else
retry="TERM/${NETDATA_WAIT_EXIT_TIMEOUT}"
fi
depend() {
use logger
@ -47,6 +31,14 @@ start_pre() {
fi
}
stop_pre() {
if [ "0${NETDATA_FORCE_EXIT}" -eq 1 ]; then
retry="TERM/${NETDATA_WAIT_EXIT_TIMEOUT:-60}/KILL/1"
else
retry="TERM/${NETDATA_WAIT_EXIT_TIMEOUT:-60}"
fi
}
run_cmd() {
cmd="${1}"
msg="${2}"