summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
authorAustin S. Hemmelgarn <austin@netdata.cloud>2023-03-14 11:40:24 -0400
committerGitHub <noreply@github.com>2023-03-14 11:40:24 -0400
commit2597f4f0354d8b7b746c8095dbf1c0a6e9c7b872 (patch)
tree7da54236c6e35c75259906d6e817aaca04819f8e /system
parent48572591975d3cbd6cf81e9876ee671ceb93e1b1 (diff)
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.
Diffstat (limited to 'system')
-rw-r--r--system/Makefile.am8
-rwxr-xr-xsystem/install-service.sh.in58
-rw-r--r--system/runit/run.in16
3 files changed, 73 insertions, 9 deletions
diff --git a/system/Makefile.am b/system/Makefile.am
index b6efe45009..747c6d4e43 100644
--- a/system/Makefile.am
+++ b/system/Makefile.am
@@ -11,6 +11,7 @@ CLEANFILES = \
lsb/init.d/netdata \
openrc/conf.d/netdata \
openrc/init.d/netdata \
+ runit/run \
systemd/netdata.service \
systemd/netdata.service.v235 \
systemd/netdata-updater.service \
@@ -40,6 +41,7 @@ libsyslsbinitddir=$(libsyslsbdir)/init.d
libsysopenrcdir=$(libsysdir)/openrc
libsysopenrcinitddir=$(libsysopenrcdir)/init.d
libsysopenrcconfddir=$(libsysopenrcdir)/conf.d
+libsysrunitdir=$(libsysdir)/runit
libsyssystemddir=$(libsysdir)/systemd
# Explicitly install directories to avoid permission issues due to umask
@@ -55,6 +57,7 @@ install-exec-local:
$(INSTALL) -d $(DESTDIR)$(libsyssystemddir)
$(INSTALL) -d $(DESTDIR)$(libsysopenrcinitddir)
$(INSTALL) -d $(DESTDIR)$(libsysopenrcconfddir)
+ $(INSTALL) -d $(DESTDIR)$(libsysrunitdir)
$(INSTALL) -d $(DESTDIR)$(libconfigvnodesdir)
dist_libconfigvnodes_DATA = \
@@ -98,6 +101,10 @@ nodist_libsysopenrcconfd_DATA = \
openrc/conf.d/netdata \
$(NULL)
+nodist_libsysrunit_DATA = \
+ runit/run \
+ $(NULL)
+
nodist_libsyssystemd_DATA = \
systemd/netdata.service \
systemd/netdata.service.v235 \
@@ -119,6 +126,7 @@ dist_noinst_DATA = \
lsb/init.d/netdata.in \
openrc/conf.d/netdata.in \
openrc/init.d/netdata.in \
+ runit/run.in \
systemd/netdata.service.in \
systemd/netdata.service.v235.in \
systemd/netdata-updater.service.in \
diff --git a/system/install-service.sh.in b/system/install-service.sh.in
index 3784cd1fd9..9a37528c54 100755
--- a/system/install-service.sh.in
+++ b/system/install-service.sh.in
@@ -87,7 +87,7 @@ get_os_key() {
valid_types() {
case "${PLATFORM}" in
Linux)
- echo "detect systemd openrc lsb initd"
+ echo "detect ${LINUX_INIT_TYPES}"
;;
FreeBSD)
echo "detect freebsd"
@@ -475,8 +475,6 @@ initd_cmds() {
# =====================================================================
# runit support functions
-#
-# Currently not supported, this exists to provide useful error messages.
_check_runit() {
# if there is no runsvdir command, then it's not runit
@@ -503,19 +501,61 @@ check_runit() {
}
install_runit_service() {
- error "Detected runit, which we do not currently support."
- exit 3
+ if [ -d /etc/sv ]; then
+ svc_dir="/etc/sv/netdata"
+ elif [ -d /etc/runit/sv ]; then
+ svc_dir="/etc/runit/sv/netdata"
+ else
+ error "Failed to locate service directory"
+ exit 4
+ fi
+
+ if [ -d /service ]; then
+ live_svc_dir="/service"
+ elif [ -d /var/service ]; then
+ live_svc_dir="/var/service"
+ elif [ -d /run/runit/service ]; then
+ live_svc_dir="/run/runit/service"
+ elif [ -d /etc/runit/runsvdir/default ]; then
+ live_svc_dir="/etc/runit/runsvdir/default"
+ else
+ error "Failed to locate live service directory"
+ exit 4
+ fi
+
+ svc_file="${svc_dir}/run"
+
+ info "Installing runit service file."
+ if [ ! -f "${svc_file}" ] && [ "${ENABLE}" = "auto" ]; then
+ ENABLE="enable"
+ fi
+
+ if ! install -D -p -m 0755 -o 0 -g 0 "${SVC_SOURCE}/runit/run" "${svc_file}"; then
+ error "Failed to install service file."
+ exit 4
+ fi
+
+ case ${ENABLE} in
+ enable)
+ if ! ln -s "${svc_dir}" "${live_svc_dir}"; then
+ warning "Failed to enable the Netdata service."
+ fi
+ ;;
+ disable)
+ if ! rm "${live_svc_dir}/netdata"; then
+ warning "Failed to disable the Netdata service."
+ fi
+ ;;
+ esac
}
runit_cmds() {
- error "Detected runit, which we do not currently support."
- exit 3
+ NETDATA_START_CMD="sv start netdata"
+ NETDATA_STOP_CMD="sv stop netdata"
}
# =====================================================================
# WSL support functions
-#
-# Cannot be supported, this exists to provide useful error messages.
_check_wsl() {
# If uname -r contains the string WSL, then it's WSL.
diff --git a/system/runit/run.in b/system/runit/run.in
new file mode 100644
index 0000000000..4ea783cc6c
--- /dev/null
+++ b/system/runit/run.in
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+piddir="@localstatedir_POST@/run/netdata/netdata.pid"
+pidfile="${piddir}/netdata.pid"
+
+cachedir="@localstatedir_POST@/cache/netdata"
+
+command="@sbindir_POST@/netdata"
+command_args="-P ${pidfile} -D"
+
+[ ! -d "${piddir}" ] && mkdir -p "${piddir}"
+[ ! -d "${cachedir}" ] && mkdir -p "${cachedir}"
+chown -R @netdata_user_POST@ "${piddir}"
+chown -R @netdata_user_POST@ "${cachedir}"
+
+exec ${command} ${command_args}