@cryptotaxi247 / netdata-1 / commits / 2597f4f03

Add experimental support for running under runit. (#13841)

* Add basic runit service script for Netdata. * Integrate runit handling in install-service script. * Add new runit script to .gitignore. * Fix service file installation. We need to ensure the service directory actually gets created, and thus need to use `-D` with the `install` command. * Sync with system restructure. * Fix botched update to Makefile.am.

Austin S. Hemmelgarn committed Mar 14, 2023 at 11:40 UTC 2597f4f0354d8b7b746c8095dbf1c0a6e9c7b872
5 files changed +75 -10
.gitignore
+1
@@ -123,6 +123,7 @@ system/initd/init.d/netdata
123 system/launchd/netdata.plist
124 system/lsb/init.d/netdata
125 system/openrc/init.d/netdata
126 +system/runit/run
127 system/systemd/netdata.service
128 system/systemd/netdata.service.*
129 system/systemd/netdata-updater.service
netdata-installer.sh
+1 -1
@@ -1060,7 +1060,7 @@ fi
1060 # -----------------------------------------------------------------------------
1061 progress "Fix generated files permissions"
1062
1063 -run chmod 755 ./system/*/init.d/netdata ./system/*/rc.d/netdata ./system/install-service.sh
1063 +run chmod 755 ./system/*/init.d/netdata ./system/*/rc.d/netdata ./system/runit/run ./system/install-service.sh
1064
1065 # -----------------------------------------------------------------------------
1066 progress "Creating standard user and groups for netdata"
system/Makefile.am
+8
@@ -11,6 +11,7 @@ CLEANFILES = \
11 lsb/init.d/netdata \
12 openrc/conf.d/netdata \
13 openrc/init.d/netdata \
14 + runit/run \
15 systemd/netdata.service \
16 systemd/netdata.service.v235 \
17 systemd/netdata-updater.service \
@@ -40,6 +41,7 @@ libsyslsbinitddir=$(libsyslsbdir)/init.d
41 libsysopenrcdir=$(libsysdir)/openrc
42 libsysopenrcinitddir=$(libsysopenrcdir)/init.d
43 libsysopenrcconfddir=$(libsysopenrcdir)/conf.d
44 +libsysrunitdir=$(libsysdir)/runit
45 libsyssystemddir=$(libsysdir)/systemd
46
47 # Explicitly install directories to avoid permission issues due to umask
@@ -55,6 +57,7 @@ install-exec-local:
57 $(INSTALL) -d $(DESTDIR)$(libsyssystemddir)
58 $(INSTALL) -d $(DESTDIR)$(libsysopenrcinitddir)
59 $(INSTALL) -d $(DESTDIR)$(libsysopenrcconfddir)
60 + $(INSTALL) -d $(DESTDIR)$(libsysrunitdir)
61 $(INSTALL) -d $(DESTDIR)$(libconfigvnodesdir)
62
63 dist_libconfigvnodes_DATA = \
@@ -98,6 +101,10 @@ nodist_libsysopenrcconfd_DATA = \
101 openrc/conf.d/netdata \
102 $(NULL)
103
104 +nodist_libsysrunit_DATA = \
105 + runit/run \
106 + $(NULL)
107 +
108 nodist_libsyssystemd_DATA = \
109 systemd/netdata.service \
110 systemd/netdata.service.v235 \
@@ -119,6 +126,7 @@ dist_noinst_DATA = \
126 lsb/init.d/netdata.in \
127 openrc/conf.d/netdata.in \
128 openrc/init.d/netdata.in \
129 + runit/run.in \
130 systemd/netdata.service.in \
131 systemd/netdata.service.v235.in \
132 systemd/netdata-updater.service.in \
system/install-service.sh.in
+49 -9
@@ -87,7 +87,7 @@ get_os_key() {
87 valid_types() {
88 case "${PLATFORM}" in
89 Linux)
90 - echo "detect systemd openrc lsb initd"
90 + echo "detect ${LINUX_INIT_TYPES}"
91 ;;
92 FreeBSD)
93 echo "detect freebsd"
@@ -475,8 +475,6 @@ initd_cmds() {
475
476 # =====================================================================
477 # runit support functions
478 -#
479 -# Currently not supported, this exists to provide useful error messages.
478
479 _check_runit() {
480 # if there is no runsvdir command, then it's not runit
@@ -503,19 +501,61 @@ check_runit() {
501 }
502
503 install_runit_service() {
506 - error "Detected runit, which we do not currently support."
507 - exit 3
504 + if [ -d /etc/sv ]; then
505 + svc_dir="/etc/sv/netdata"
506 + elif [ -d /etc/runit/sv ]; then
507 + svc_dir="/etc/runit/sv/netdata"
508 + else
509 + error "Failed to locate service directory"
510 + exit 4
511 + fi
512 +
513 + if [ -d /service ]; then
514 + live_svc_dir="/service"
515 + elif [ -d /var/service ]; then
516 + live_svc_dir="/var/service"
517 + elif [ -d /run/runit/service ]; then
518 + live_svc_dir="/run/runit/service"
519 + elif [ -d /etc/runit/runsvdir/default ]; then
520 + live_svc_dir="/etc/runit/runsvdir/default"
521 + else
522 + error "Failed to locate live service directory"
523 + exit 4
524 + fi
525 +
526 + svc_file="${svc_dir}/run"
527 +
528 + info "Installing runit service file."
529 + if [ ! -f "${svc_file}" ] && [ "${ENABLE}" = "auto" ]; then
530 + ENABLE="enable"
531 + fi
532 +
533 + if ! install -D -p -m 0755 -o 0 -g 0 "${SVC_SOURCE}/runit/run" "${svc_file}"; then
534 + error "Failed to install service file."
535 + exit 4
536 + fi
537 +
538 + case ${ENABLE} in
539 + enable)
540 + if ! ln -s "${svc_dir}" "${live_svc_dir}"; then
541 + warning "Failed to enable the Netdata service."
542 + fi
543 + ;;
544 + disable)
545 + if ! rm "${live_svc_dir}/netdata"; then
546 + warning "Failed to disable the Netdata service."
547 + fi
548 + ;;
549 + esac
550 }
551
552 runit_cmds() {
511 - error "Detected runit, which we do not currently support."
512 - exit 3
553 + NETDATA_START_CMD="sv start netdata"
554 + NETDATA_STOP_CMD="sv stop netdata"
555 }
556
557 # =====================================================================
558 # WSL support functions
517 -#
518 -# Cannot be supported, this exists to provide useful error messages.
559
560 _check_wsl() {
561 # If uname -r contains the string WSL, then it's WSL.
system/runit/run.in new
+16
@@ -0,0 +1,16 @@
1 +#!/bin/sh
2 +
3 +piddir="@localstatedir_POST@/run/netdata/netdata.pid"
4 +pidfile="${piddir}/netdata.pid"
5 +
6 +cachedir="@localstatedir_POST@/cache/netdata"
7 +
8 +command="@sbindir_POST@/netdata"
9 +command_args="-P ${pidfile} -D"
10 +
11 +[ ! -d "${piddir}" ] && mkdir -p "${piddir}"
12 +[ ! -d "${cachedir}" ] && mkdir -p "${cachedir}"
13 +chown -R @netdata_user_POST@ "${piddir}"
14 +chown -R @netdata_user_POST@ "${cachedir}"
15 +
16 +exec ${command} ${command_args}