diff options
author | Austin S. Hemmelgarn <austin@netdata.cloud> | 2023-03-27 09:19:27 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-27 09:19:27 -0400 |
commit | 2a9c0b54b1759c31c99669498cabc5606ecea193 (patch) | |
tree | f8dee3c9ba559c21e7215c7a20c71ff23c1a167b /system | |
parent | 03dc41202ac4d65ca156095f317580d71e8603f3 (diff) |
Fix how we are handling system services in RPM packages. (#14781)
* Drop non-systemd init code in RPM spec file.
All of our currently supported RPM-based platforms are systemd-based, so
this is functionally dead code.
* Fix how we handle systemd service installation.
- Rely on the platform-provided macros, instead of doing our own thing.
These do the right thing in 99.99% of cases, and behave how we
actually need them to.
- Don’t depend on systemd at runtime. The macros handle this correctly,
and nothing we actually do _needs_ systemd at runtime.
- Actually follow packaging guidelines for upgrades. In particular, only
restart the agent if it’s already running (instead of unconditionally),
and don’t enable it if it’s disabled.
- Just put the macro invocations down in the actual scriptlets, instead
of using complicated nested macro definitions to compute things ahead
of time. This makes the code _much_ easier to understand.
* Add a systemd preset file so the service is enabled by default.
Diffstat (limited to 'system')
-rw-r--r-- | system/Makefile.am | 1 | ||||
-rwxr-xr-x | system/install-service.sh.in | 14 | ||||
-rw-r--r-- | system/systemd/50-netdata.preset | 1 |
3 files changed, 13 insertions, 3 deletions
diff --git a/system/Makefile.am b/system/Makefile.am index 747c6d4e43..13466639d5 100644 --- a/system/Makefile.am +++ b/system/Makefile.am @@ -113,6 +113,7 @@ nodist_libsyssystemd_DATA = \ dist_libsyssystemd_DATA = \ systemd/netdata-updater.timer \ + systemd/50-netdata.preset $(NULL) dist_noinst_DATA = \ diff --git a/system/install-service.sh.in b/system/install-service.sh.in index 9a37528c54..a885a8618c 100755 --- a/system/install-service.sh.in +++ b/system/install-service.sh.in @@ -237,6 +237,8 @@ get_systemd_service_dir() { install_systemd_service() { SRCFILE="${SVC_SOURCE}/systemd/netdata.service" + PRESET_FILE="${SVC_SOURCE}/systemd/50-netdata.preset" + SVCDIR="$(get_systemd_service_dir)" if [ "$(systemctl --version | head -n 1 | cut -f 2 -d ' ')" -le 235 ]; then SRCFILE="${SVC_SOURCE}/systemd/netdata.service.v235" @@ -255,18 +257,24 @@ install_systemd_service() { fi info "Installing systemd service..." - if ! install -p -m 0644 -o 0 -g 0 "${SRCFILE}" "$(get_systemd_service_dir)/netdata.service"; then + if ! install -p -m 0644 -o 0 -g 0 "${SRCFILE}" "${SVCDIR}/netdata.service"; then error "Failed to install systemd service file." exit 4 fi + if [ -f "${PRESET_FILE}" ]; then + if ! install -p -m 0644 -o 0 -g 0 "${PRESET_FILE}" "${SVCDIR}-preset/50-netdata.preset"; then + warning "Failed to install netdata preset file." + fi + fi + if [ "$(check_systemd)" = "YES" ]; then if ! systemctl daemon-reload; then - warning "Failed to reload systemd unit files." + warning "Failed to reload systemd unit files." fi if ! systemctl "${ENABLE}" netdata; then - warning "Failed to ${ENABLE} Netdata service." + warning "Failed to ${ENABLE} Netdata service." fi fi } diff --git a/system/systemd/50-netdata.preset b/system/systemd/50-netdata.preset new file mode 100644 index 0000000000..fe4e5a1977 --- /dev/null +++ b/system/systemd/50-netdata.preset @@ -0,0 +1 @@ +enable netdata.service |