diff options
Diffstat (limited to 'system')
-rw-r--r-- | system/Makefile.am | 131 | ||||
-rw-r--r-- | system/cron/netdata-updater-daily.in (renamed from system/netdata.crontab.in) | 0 | ||||
-rwxr-xr-x | system/edit-config | 16 | ||||
-rw-r--r-- | system/freebsd/rc.d/netdata.in (renamed from system/netdata-freebsd.in) | 0 | ||||
-rw-r--r-- | system/initd/init.d/netdata.in (renamed from system/netdata-init-d.in) | 0 | ||||
-rwxr-xr-x | system/install-service.sh.in | 107 | ||||
-rw-r--r-- | system/launchd/netdata.plist.in (renamed from system/netdata.plist.in) | 0 | ||||
-rw-r--r-- | system/logrotate/netdata.in (renamed from system/netdata.logrotate.in) | 0 | ||||
-rw-r--r-- | system/lsb/init.d/netdata.in (renamed from system/netdata-lsb.in) | 0 | ||||
-rw-r--r-- | system/netdata.conf | 6 | ||||
-rw-r--r-- | system/openrc/conf.d/netdata.in | 24 | ||||
-rw-r--r-- | system/openrc/init.d/netdata.in (renamed from system/netdata-openrc.in) | 38 | ||||
-rw-r--r-- | system/runit/run.in | 16 | ||||
-rw-r--r-- | system/systemd/50-netdata.preset | 1 | ||||
-rw-r--r-- | system/systemd/netdata-updater.service.in (renamed from system/netdata-updater.service.in) | 0 | ||||
-rw-r--r-- | system/systemd/netdata-updater.timer (renamed from system/netdata-updater.timer) | 0 | ||||
-rw-r--r-- | system/systemd/netdata.service.in (renamed from system/netdata.service.in) | 0 | ||||
-rw-r--r-- | system/systemd/netdata.service.v235.in (renamed from system/netdata.service.v235.in) | 0 | ||||
-rw-r--r-- | system/vnodes/vnodes.conf | 23 |
19 files changed, 278 insertions, 84 deletions
diff --git a/system/Makefile.am b/system/Makefile.am index 1a1b41e2..13466639 100644 --- a/system/Makefile.am +++ b/system/Makefile.am @@ -3,16 +3,18 @@ MAINTAINERCLEANFILES = $(srcdir)/Makefile.in CLEANFILES = \ - netdata-openrc \ - netdata.logrotate \ - netdata.service \ - netdata.service.v235 \ - netdata-init-d \ - netdata-lsb \ - netdata-freebsd \ - netdata.plist \ - netdata.crontab \ - netdata-updater.service \ + cron/netdata-updater-daily \ + freebsd/rc.d/netdata \ + initd/init.d/netdata \ + launchd/netdata.plist \ + logrotate/netdata \ + 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 \ $(NULL) include $(top_srcdir)/build/subst.inc @@ -26,44 +28,107 @@ dist_config_DATA = \ .install-type \ $(NULL) +libconfigvnodesdir=$(libconfigdir)/vnodes +libsyscrondir=$(libsysdir)/cron +libsysfreebsddir=$(libsysdir)/freebsd +libsysfreebsdrcddir=$(libsysfreebsddir)/rc.d +libsysinitddir=$(libsysdir)/initd +libsysinitdinitddir=$(libsysinitddir)/init.d +libsyslaunchddir=$(libsysdir)/launchd +libsyslogrotatedir=$(libsysdir)/logrotate +libsyslsbdir=$(libsysdir)/lsb +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 install-exec-local: $(INSTALL) -d $(DESTDIR)$(configdir) $(INSTALL) -d $(DESTDIR)$(libsysdir) + $(INSTALL) -d $(DESTDIR)$(libsyscrondir) + $(INSTALL) -d $(DESTDIR)$(libsysfreebsdrcddir) + $(INSTALL) -d $(DESTDIR)$(libsysinitdinitddir) + $(INSTALL) -d $(DESTDIR)$(libsyslaunchddir) + $(INSTALL) -d $(DESTDIR)$(libsyslogrotatedir) + $(INSTALL) -d $(DESTDIR)$(libsyslsbinitddir) + $(INSTALL) -d $(DESTDIR)$(libsyssystemddir) + $(INSTALL) -d $(DESTDIR)$(libsysopenrcinitddir) + $(INSTALL) -d $(DESTDIR)$(libsysopenrcconfddir) + $(INSTALL) -d $(DESTDIR)$(libsysrunitdir) + $(INSTALL) -d $(DESTDIR)$(libconfigvnodesdir) + +dist_libconfigvnodes_DATA = \ + vnodes/vnodes.conf + $(NULL) libexecnetdatadir=$(libexecdir)/netdata nodist_libexecnetdata_SCRIPTS = \ install-service.sh \ $(NULL) -nodist_libsys_DATA = \ - netdata-openrc \ - netdata.logrotate \ - netdata.service \ - netdata.service.v235 \ - netdata-init-d \ - netdata-lsb \ - netdata-freebsd \ - netdata.plist \ - netdata.crontab \ - netdata-updater.service \ +nodist_libsyscron_DATA = \ + cron/netdata-updater-daily \ + $(NULL) + +nodist_libsysfreebsdrcd_DATA = \ + freebsd/rc.d/netdata \ + $(NULL) + +nodist_libsysinitdinitd_DATA = \ + initd/init.d/netdata \ + $(NULL) + +nodist_libsyslaunchd_DATA = \ + launchd/netdata.plist \ + $(NULL) + +nodist_libsyslogrotate_DATA = \ + logrotate/netdata \ + $(NULL) + +nodist_libsyslsbinitd_DATA = \ + lsb/init.d/netdata \ + $(NULL) + +nodist_libsysopenrcinitd_DATA = \ + openrc/init.d/netdata \ + $(NULL) + +nodist_libsysopenrcconfd_DATA = \ + openrc/conf.d/netdata \ + $(NULL) + +nodist_libsysrunit_DATA = \ + runit/run \ + $(NULL) + +nodist_libsyssystemd_DATA = \ + systemd/netdata.service \ + systemd/netdata.service.v235 \ + systemd/netdata-updater.service \ $(NULL) -dist_libsys_DATA = \ - netdata-updater.timer \ +dist_libsyssystemd_DATA = \ + systemd/netdata-updater.timer \ + systemd/50-netdata.preset $(NULL) dist_noinst_DATA = \ install-service.sh.in \ - netdata-openrc.in \ - netdata.logrotate.in \ - netdata.service.in \ - netdata.service.v235.in \ - netdata-init-d.in \ - netdata-lsb.in \ - netdata-freebsd.in \ - netdata.plist.in \ netdata.conf \ - netdata.crontab.in \ - netdata-updater.service.in \ + cron/netdata-updater-daily.in \ + freebsd/rc.d/netdata.in \ + initd/init.d/netdata.in \ + launchd/netdata.plist.in \ + logrotate/netdata.in \ + 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 \ $(NULL) diff --git a/system/netdata.crontab.in b/system/cron/netdata-updater-daily.in index 8f0527e0..8f0527e0 100644 --- a/system/netdata.crontab.in +++ b/system/cron/netdata-updater-daily.in diff --git a/system/edit-config b/system/edit-config index 754f9374..96ee82d4 100755 --- a/system/edit-config +++ b/system/edit-config @@ -34,10 +34,20 @@ error() { } abspath() { - if [ -d "${1}" ]; then + if [ -d "${1}/" ]; then echo "$(cd "${1}" && /usr/bin/env PWD= pwd -P)/" - else + elif [ -f "${1}" ]; then echo "$(cd "$(dirname "${1}")" && /usr/bin/env PWD= pwd -P)/$(basename "${1}")" + elif echo "${1}" | grep -q '/'; then + if echo "${1}" | grep -q '^/'; then + mkdir -p "$(dirname "${1}")" + echo "$(cd "$(dirname "${1}")" && /usr/bin/env PWD= pwd -P)/$(basename "${1}")" + else + mkdir -p "${script_dir}/$(dirname "${1}")" + echo "${script_dir}/${1}" + fi + else + echo "${script_dir}/${1}" fi } @@ -153,7 +163,7 @@ list_files() { check_directories handle_container - if test -t; then + if test -t && command -v tput > /dev/null 2>&1; then width="$(tput cols)" fi diff --git a/system/netdata-freebsd.in b/system/freebsd/rc.d/netdata.in index fd544c86..fd544c86 100644 --- a/system/netdata-freebsd.in +++ b/system/freebsd/rc.d/netdata.in diff --git a/system/netdata-init-d.in b/system/initd/init.d/netdata.in index c0257ffa..c0257ffa 100644 --- a/system/netdata-init-d.in +++ b/system/initd/init.d/netdata.in diff --git a/system/install-service.sh.in b/system/install-service.sh.in index 59cff0a0..a885a861 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" @@ -102,7 +102,7 @@ valid_types() { } install_generic_service() { - svc_type="${1}" + svc_path="${1}" svc_type_name="${2}" svc_file="${3}" svc_enable_hook="${4}" @@ -113,7 +113,7 @@ install_generic_service() { ENABLE="enable" fi - if ! install -p -m 0755 -o 0 -g 0 "${SVC_SOURCE}/netdata-${svc_type}" "${svc_file}"; then + if ! install -p -m 0755 -o 0 -g 0 "${SVC_SOURCE}/${svc_path}/netdata" "${svc_file}"; then error "Failed to install service file." exit 4 fi @@ -236,10 +236,12 @@ get_systemd_service_dir() { } install_systemd_service() { - SRCFILE="${SVC_SOURCE}/netdata.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}/netdata.service.v235" + SRCFILE="${SVC_SOURCE}/systemd/netdata.service.v235" fi if [ "${ENABLE}" = "auto" ]; then @@ -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." + if ! systemctl "${ENABLE}" netdata; then + warning "Failed to ${ENABLE} Netdata service." fi fi } @@ -290,6 +298,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 @@ -341,7 +352,15 @@ disable_openrc() { } install_openrc_service() { - install_generic_service openrc OpenRC /etc/init.d/netdata enable_openrc disable_openrc + 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() { @@ -399,7 +418,7 @@ disable_lsb() { } install_lsb_service() { - install_generic_service lsb LSB /etc/init.d/netdata enable_lsb disable_lsb + install_generic_service lsb/init.d LSB /etc/init.d/netdata enable_lsb disable_lsb } lsb_cmds() { @@ -454,7 +473,7 @@ disable_initd() { } install_initd_service() { - install_generic_service init-d init.d /etc/init.d/netdata enable_initd disable_initd + install_generic_service initd/init.d init.d /etc/init.d/netdata enable_initd disable_initd } initd_cmds() { @@ -464,8 +483,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 @@ -492,19 +509,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. @@ -552,7 +611,7 @@ disable_freebsd() { } install_freebsd_service() { - install_generic_service freebsd "FreeBSD rc.d" /usr/local/etc/rc.d/netdata enable_freebsd disable_freebsd + install_generic_service freebsd/rc.d "FreeBSD rc.d" /usr/local/etc/rc.d/netdata enable_freebsd disable_freebsd } freebsd_cmds() { @@ -566,7 +625,7 @@ freebsd_cmds() { install_darwin_service() { info "Installing macOS plist file for launchd." - if ! install -C -S -p -m 0644 -o 0 -g 0 system/netdata.plist /Library/LaunchDaemons/com.github.netdata.plist; then + if ! install -C -S -p -m 0644 -o 0 -g 0 system/launchd/netdata.plist /Library/LaunchDaemons/com.github.netdata.plist; then error "Failed to copy plist file." exit 4 fi @@ -633,7 +692,7 @@ detect_linux_svc_type() { install_linux_service() { t="$(detect_linux_svc_type)" - if [ -z "${t}" ]; then + if [ -z "${t}" ] || [ "${t}" = 'detect' ]; then exit 2 fi @@ -643,7 +702,7 @@ install_linux_service() { linux_cmds() { t="$(detect_linux_svc_type)" - if [ -z "${t}" ]; then + if [ -z "${t}" ] || [ "${t}" = 'detect' ]; then exit 2 fi diff --git a/system/netdata.plist.in b/system/launchd/netdata.plist.in index a969b317..a969b317 100644 --- a/system/netdata.plist.in +++ b/system/launchd/netdata.plist.in diff --git a/system/netdata.logrotate.in b/system/logrotate/netdata.in index 2c4949e5..2c4949e5 100644 --- a/system/netdata.logrotate.in +++ b/system/logrotate/netdata.in diff --git a/system/netdata-lsb.in b/system/lsb/init.d/netdata.in index e429ad1c..e429ad1c 100644 --- a/system/netdata-lsb.in +++ b/system/lsb/init.d/netdata.in diff --git a/system/netdata.conf b/system/netdata.conf index 70edb082..94d9ab82 100644 --- a/system/netdata.conf +++ b/system/netdata.conf @@ -1,6 +1,10 @@ # netdata configuration # -# You can download the latest version of this file, using: +# You can get the latest version of this file, using: +# +# netdatacli dumpconfig > /etc/netdata/netdata.conf +# +# You can also download it using: # # wget -O /etc/netdata/netdata.conf http://localhost:19999/netdata.conf # or diff --git a/system/openrc/conf.d/netdata.in b/system/openrc/conf.d/netdata.in new file mode 100644 index 00000000..92f88260 --- /dev/null +++ b/system/openrc/conf.d/netdata.in @@ -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" diff --git a/system/netdata-openrc.in b/system/openrc/init.d/netdata.in index 15887892..74242b3c 100644 --- a/system/netdata-openrc.in +++ b/system/openrc/init.d/netdata.in @@ -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}" diff --git a/system/runit/run.in b/system/runit/run.in new file mode 100644 index 00000000..4ea783cc --- /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} diff --git a/system/systemd/50-netdata.preset b/system/systemd/50-netdata.preset new file mode 100644 index 00000000..fe4e5a19 --- /dev/null +++ b/system/systemd/50-netdata.preset @@ -0,0 +1 @@ +enable netdata.service diff --git a/system/netdata-updater.service.in b/system/systemd/netdata-updater.service.in index d0bd4994..d0bd4994 100644 --- a/system/netdata-updater.service.in +++ b/system/systemd/netdata-updater.service.in diff --git a/system/netdata-updater.timer b/system/systemd/netdata-updater.timer index 8b36e46f..8b36e46f 100644 --- a/system/netdata-updater.timer +++ b/system/systemd/netdata-updater.timer diff --git a/system/netdata.service.in b/system/systemd/netdata.service.in index 25d95b2b..25d95b2b 100644 --- a/system/netdata.service.in +++ b/system/systemd/netdata.service.in diff --git a/system/netdata.service.v235.in b/system/systemd/netdata.service.v235.in index e3232056..e3232056 100644 --- a/system/netdata.service.v235.in +++ b/system/systemd/netdata.service.v235.in diff --git a/system/vnodes/vnodes.conf b/system/vnodes/vnodes.conf new file mode 100644 index 00000000..abcd5784 --- /dev/null +++ b/system/vnodes/vnodes.conf @@ -0,0 +1,23 @@ +## This file is in YAML format. +## +## It contains a list of virtual nodes. Virtual node, defined with the following parameters: +## +## 1. hostname +## The hostname of the virtual node. String. Required. +## 2. guid +## Uniquely identifies the node. String. Required. +## 3. labels +## The virtual node host labels. Dictionary in the form key: value. Optional. +## Special labels that are used to set virtual host system information: +## https://learn.netdata.cloud/docs/improving-netdata---developers/external-plugins#host_label +## +## You can create GUIDs online: https://www.guidgen.com/ +## or generate with the linux command: uuidgen +## +## --------------------------------------------------------------------------------------------------------------------- + +#- hostname: HOSTNAME1 +# guid: GUID1 +# +#- hostname: HOSTNAME2 +# guid: GUID2 |