From 8b93deb7b0916ea5caabfb24dbc6420e01054cbe Mon Sep 17 00:00:00 2001 From: "Austin S. Hemmelgarn" Date: Mon, 27 Feb 2023 12:38:25 -0500 Subject: Reorganize system directory to better reflect what files are actually used for. (#14544) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Move systemd-specific system files to their own directory. * Move non-systemd init scripts to individual subdirectories. * Move cron files to their own directory. * Move logrotate config to it’s own directory. * Fix typos in Makefile.am. * Fix Debian package builds. * Fixed issues reported by @andrewm4894. --- system/Makefile.am | 108 +++++++++++++++++++--------- system/cron/netdata-updater-daily.in | 1 + system/freebsd/rc.d/netdata.in | 53 ++++++++++++++ system/initd/init.d/netdata.in | 95 ++++++++++++++++++++++++ system/install-service.sh.in | 18 ++--- system/launchd/netdata.plist.in | 15 ++++ system/logrotate/netdata.in | 12 ++++ system/lsb/init.d/netdata.in | 116 ++++++++++++++++++++++++++++++ system/netdata-freebsd.in | 53 -------------- system/netdata-init-d.in | 95 ------------------------ system/netdata-lsb.in | 116 ------------------------------ system/netdata-openrc.in | 88 ----------------------- system/netdata-updater.service.in | 8 --- system/netdata-updater.timer | 12 ---- system/netdata.crontab.in | 1 - system/netdata.logrotate.in | 12 ---- system/netdata.plist.in | 15 ---- system/netdata.service.in | 80 --------------------- system/netdata.service.v235.in | 42 ----------- system/openrc/init.d/netdata.in | 88 +++++++++++++++++++++++ system/systemd/netdata-updater.service.in | 8 +++ system/systemd/netdata-updater.timer | 12 ++++ system/systemd/netdata.service.in | 80 +++++++++++++++++++++ system/systemd/netdata.service.v235.in | 42 +++++++++++ 24 files changed, 606 insertions(+), 564 deletions(-) create mode 100644 system/cron/netdata-updater-daily.in create mode 100644 system/freebsd/rc.d/netdata.in create mode 100644 system/initd/init.d/netdata.in create mode 100644 system/launchd/netdata.plist.in create mode 100644 system/logrotate/netdata.in create mode 100644 system/lsb/init.d/netdata.in delete mode 100644 system/netdata-freebsd.in delete mode 100644 system/netdata-init-d.in delete mode 100644 system/netdata-lsb.in delete mode 100644 system/netdata-openrc.in delete mode 100644 system/netdata-updater.service.in delete mode 100644 system/netdata-updater.timer delete mode 100644 system/netdata.crontab.in delete mode 100644 system/netdata.logrotate.in delete mode 100644 system/netdata.plist.in delete mode 100644 system/netdata.service.in delete mode 100644 system/netdata.service.v235.in create mode 100644 system/openrc/init.d/netdata.in create mode 100644 system/systemd/netdata-updater.service.in create mode 100644 system/systemd/netdata-updater.timer create mode 100644 system/systemd/netdata.service.in create mode 100644 system/systemd/netdata.service.v235.in (limited to 'system') diff --git a/system/Makefile.am b/system/Makefile.am index 1a1b41e26b..a8836b2b5f 100644 --- a/system/Makefile.am +++ b/system/Makefile.am @@ -3,16 +3,16 @@ 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/init.d/netdata \ + systemd/netdata.service \ + systemd/netdata.service.v235 \ + systemd/netdata-updater.service \ $(NULL) include $(top_srcdir)/build/subst.inc @@ -26,44 +26,86 @@ dist_config_DATA = \ .install-type \ $(NULL) +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 +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) 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_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 \ $(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/init.d/netdata.in \ + systemd/netdata.service.in \ + systemd/netdata.service.v235.in \ + systemd/netdata-updater.service.in \ $(NULL) diff --git a/system/cron/netdata-updater-daily.in b/system/cron/netdata-updater-daily.in new file mode 100644 index 0000000000..8f0527e0e0 --- /dev/null +++ b/system/cron/netdata-updater-daily.in @@ -0,0 +1 @@ +2 57 * * * root @pkglibexecdir_POST@/netdata-updater.sh diff --git a/system/freebsd/rc.d/netdata.in b/system/freebsd/rc.d/netdata.in new file mode 100644 index 0000000000..fd544c86c5 --- /dev/null +++ b/system/freebsd/rc.d/netdata.in @@ -0,0 +1,53 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-3.0-or-later + +. /etc/rc.subr + +name=netdata +rcvar=netdata_enable + +piddir="@localstatedir_POST@/run/netdata" +pidfile="${piddir}/netdata.pid" + +command="@sbindir_POST@/netdata" +command_args="-P ${pidfile}" + +required_files="@configdir_POST@/netdata.conf" + +start_precmd="netdata_prestart" +stop_postcmd="netdata_poststop" + +extra_commands="reloadhealth savedb" + +reloadhealth_cmd="netdata_reloadhealth" +savedb_cmd="netdata_savedb" + +netdata_prestart() +{ + [ ! -d "${piddir}" ] && mkdir -p "${piddir}" + chown @netdata_user_POST@:@netdata_user_POST@ "${piddir}" + return 0 +} + +netdata_poststop() +{ + [ -f "${pidfile}" ] && rm "${pidfile}" + return 0 +} + +netdata_reloadhealth() +{ + p=`cat ${pidfile}` + kill -USR2 ${p} && echo "Sent USR2 (reload health) to pid ${p}" + return 0 +} + +netdata_savedb() +{ + p=`cat ${pidfile}` + kill -USR2 ${p} && echo "Sent USR1 (save db) to pid ${p}" + return 0 +} + +load_rc_config $name +run_rc_command "$1" diff --git a/system/initd/init.d/netdata.in b/system/initd/init.d/netdata.in new file mode 100644 index 0000000000..c0257ffab5 --- /dev/null +++ b/system/initd/init.d/netdata.in @@ -0,0 +1,95 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-3.0-or-later +# +# netdata Real-time performance monitoring, done right +# chkconfig: 345 99 01 +# description: Netdata is a daemon that collects data in real-time (per second) +# and presents a web site to view and analyze them. The presentation +# is also real-time and full of interactive charts that precisely +# render all collected values. +# processname: netdata + +# Source functions +. /etc/rc.d/init.d/functions + +DAEMON="netdata" +DAEMON_PATH=@sbindir_POST@ +PIDFILE_PATH=@localstatedir_POST@/run/netdata +PIDFILE=$PIDFILE_PATH/$DAEMON.pid +DAEMONOPTS="-P $PIDFILE" +STOP_TIMEOUT="60" + +[ -e /etc/sysconfig/$DAEMON ] && . /etc/sysconfig/$DAEMON + +LOCKFILE=/var/lock/subsys/$DAEMON + +service_start() +{ + [ -x $DAEMON_PATH ] || exit 5 + [ ! -d $PIDFILE_PATH ] && mkdir -p $PIDFILE_PATH + chown @netdata_user_POST@:@netdata_user_POST@ $PIDFILE_PATH + echo -n "Starting $DAEMON..." + daemon $DAEMON_PATH/$DAEMON $DAEMONOPTS + RETVAL=$? + echo + [ $RETVAL -eq 0 ] && touch $LOCKFILE + return $RETVAL +} + +service_stop() +{ + printf "%-50s" "Stopping $DAEMON..." + killproc -p ${PIDFILE} -d ${STOP_TIMEOUT} $DAEMON + RETVAL=$? + echo + [ $RETVAL -eq 0 ] && rm -f ${PIDFILE} ${LOCKFILE} + return $RETVAL +} + +condrestart() +{ + if ! service_status > /dev/null; then + RETVAL=$1 + return $RETVAL + fi + + service_stop + service_start +} + +service_status() +{ + status -p ${PIDFILE} $DAEMON_PATH/$DAEMON +} + +service_status_quiet() +{ + status -p ${PIDFILE} $DAEMON_PATH/$DAEMON >/dev/null 2>&1 +} + +case "$1" in +start) + service_status_quiet && exit 0 + service_start +;; +stop) + service_status_quiet || exit 0 + service_stop +;; +restart) + service_stop + service_start +;; +try-restart) + condrestart 0 + ;; +force-reload) + condrestart 7 +;; +status) + service_status +;; +*) + echo "Usage: $0 {start|stop|restart|try-restart|force-reload|status}" + exit 3 +esac diff --git a/system/install-service.sh.in b/system/install-service.sh.in index a014e3d08b..a85f15bd0f 100755 --- a/system/install-service.sh.in +++ b/system/install-service.sh.in @@ -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,10 @@ get_systemd_service_dir() { } install_systemd_service() { - SRCFILE="${SVC_SOURCE}/netdata.service" + SRCFILE="${SVC_SOURCE}/systemd/netdata.service" 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 @@ -341,7 +341,7 @@ 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 } openrc_cmds() { @@ -399,7 +399,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 +454,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() { @@ -552,7 +552,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 +566,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 diff --git a/system/launchd/netdata.plist.in b/system/launchd/netdata.plist.in new file mode 100644 index 0000000000..a969b31775 --- /dev/null +++ b/system/launchd/netdata.plist.in @@ -0,0 +1,15 @@ + + + + + + Label + com.github.netdata + ProgramArguments + + @sbindir_POST@/netdata + + RunAtLoad + + + diff --git a/system/logrotate/netdata.in b/system/logrotate/netdata.in new file mode 100644 index 0000000000..2c4949e5f6 --- /dev/null +++ b/system/logrotate/netdata.in @@ -0,0 +1,12 @@ +@localstatedir_POST@/log/netdata/*.log { + daily + missingok + rotate 14 + compress + delaycompress + notifempty + sharedscripts + postrotate + /bin/kill -HUP `cat /run/netdata/netdata.pid 2>/dev/null` 2>/dev/null || true + endscript +} diff --git a/system/lsb/init.d/netdata.in b/system/lsb/init.d/netdata.in new file mode 100644 index 0000000000..e429ad1c93 --- /dev/null +++ b/system/lsb/init.d/netdata.in @@ -0,0 +1,116 @@ +#!/usr/bin/env bash +# +# Netdata LSB start script +# +# Copyright: +# SPDX-License-Identifier: GPL-3.0-or-later +# +# Author: +# Costa Tsaousis +# Pavlos Emm. Katsoulakis + +### BEGIN INIT INFO +# Provides: netdata +# Required-Start: $local_fs $remote_fs $network $named $time +# Required-Stop: $local_fs $remote_fs $network $named $time +# Should-Start: $local_fs $network $named $remote_fs $time $all +# Should-Stop: $local_fs $network $named $remote_fs $time $all +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Start and stop the netdata real-time monitoring server daemon +# Description: Controls the main netdata monitoring server daemon "netdata". +# and all its plugins. +### END INIT INFO +# +set -e +set -u +${DEBIAN_SCRIPT_DEBUG:+ set -v -x} + +DAEMON="netdata" +DAEMON_PATH=@sbindir_POST@ +PIDFILE_PATH=@localstatedir_POST@/run/netdata +PIDFILE=$PIDFILE_PATH/$DAEMON.pid +DAEMONOPTS="-P $PIDFILE" + +test -x $DAEMON_PATH/$DAEMON || exit 0 + +. /lib/lsb/init-functions + +# Safeguard (relative paths, core dumps..) +cd / +umask 022 + +service_start() { + if [ ! -d $PIDFILE_PATH ]; then + mkdir -p $PIDFILE_PATH + fi + + chown @netdata_user_POST@:@netdata_user_POST@ $PIDFILE_PATH + + log_daemon_msg "Starting real-time performance monitoring" "netdata" + start_daemon -p $PIDFILE $DAEMON_PATH/$DAEMON $DAEMONOPTS + RETVAL=$? + log_end_msg $RETVAL + return $RETVAL +} + +service_stop() { + log_daemon_msg "Stopping real-time performance monitoring" "netdata" + killproc -p ${PIDFILE} $DAEMON_PATH/$DAEMON + RETVAL=$? + log_end_msg $RETVAL + + if [ $RETVAL -eq 0 ]; then + rm -f ${PIDFILE} + fi + return $RETVAL +} + +condrestart() { + if ! service_status > /dev/null; then + RETVAL=$1 + return + fi + + service_stop + service_start +} + +service_status() { + status_of_proc -p $PIDFILE $DAEMON_PATH/$DAEMON netdata +} + + +# +# main() +# + +case "${1:-''}" in + 'start') + service_start + ;; + + 'stop') + service_stop + ;; + + 'restart') + service_stop + service_start + ;; + + 'try-restart') + condrestart 0 + ;; + + 'force-reload') + condrestart 7 + ;; + + 'status') + service_status && exit 0 || exit $? + ;; + *) + echo "Usage: $0 {start|stop|restart|try-restart|force-reload|status}" + exit 1 +esac diff --git a/system/netdata-freebsd.in b/system/netdata-freebsd.in deleted file mode 100644 index fd544c86c5..0000000000 --- a/system/netdata-freebsd.in +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-3.0-or-later - -. /etc/rc.subr - -name=netdata -rcvar=netdata_enable - -piddir="@localstatedir_POST@/run/netdata" -pidfile="${piddir}/netdata.pid" - -command="@sbindir_POST@/netdata" -command_args="-P ${pidfile}" - -required_files="@configdir_POST@/netdata.conf" - -start_precmd="netdata_prestart" -stop_postcmd="netdata_poststop" - -extra_commands="reloadhealth savedb" - -reloadhealth_cmd="netdata_reloadhealth" -savedb_cmd="netdata_savedb" - -netdata_prestart() -{ - [ ! -d "${piddir}" ] && mkdir -p "${piddir}" - chown @netdata_user_POST@:@netdata_user_POST@ "${piddir}" - return 0 -} - -netdata_poststop() -{ - [ -f "${pidfile}" ] && rm "${pidfile}" - return 0 -} - -netdata_reloadhealth() -{ - p=`cat ${pidfile}` - kill -USR2 ${p} && echo "Sent USR2 (reload health) to pid ${p}" - return 0 -} - -netdata_savedb() -{ - p=`cat ${pidfile}` - kill -USR2 ${p} && echo "Sent USR1 (save db) to pid ${p}" - return 0 -} - -load_rc_config $name -run_rc_command "$1" diff --git a/system/netdata-init-d.in b/system/netdata-init-d.in deleted file mode 100644 index c0257ffab5..0000000000 --- a/system/netdata-init-d.in +++ /dev/null @@ -1,95 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-3.0-or-later -# -# netdata Real-time performance monitoring, done right -# chkconfig: 345 99 01 -# description: Netdata is a daemon that collects data in real-time (per second) -# and presents a web site to view and analyze them. The presentation -# is also real-time and full of interactive charts that precisely -# render all collected values. -# processname: netdata - -# Source functions -. /etc/rc.d/init.d/functions - -DAEMON="netdata" -DAEMON_PATH=@sbindir_POST@ -PIDFILE_PATH=@localstatedir_POST@/run/netdata -PIDFILE=$PIDFILE_PATH/$DAEMON.pid -DAEMONOPTS="-P $PIDFILE" -STOP_TIMEOUT="60" - -[ -e /etc/sysconfig/$DAEMON ] && . /etc/sysconfig/$DAEMON - -LOCKFILE=/var/lock/subsys/$DAEMON - -service_start() -{ - [ -x $DAEMON_PATH ] || exit 5 - [ ! -d $PIDFILE_PATH ] && mkdir -p $PIDFILE_PATH - chown @netdata_user_POST@:@netdata_user_POST@ $PIDFILE_PATH - echo -n "Starting $DAEMON..." - daemon $DAEMON_PATH/$DAEMON $DAEMONOPTS - RETVAL=$? - echo - [ $RETVAL -eq 0 ] && touch $LOCKFILE - return $RETVAL -} - -service_stop() -{ - printf "%-50s" "Stopping $DAEMON..." - killproc -p ${PIDFILE} -d ${STOP_TIMEOUT} $DAEMON - RETVAL=$? - echo - [ $RETVAL -eq 0 ] && rm -f ${PIDFILE} ${LOCKFILE} - return $RETVAL -} - -condrestart() -{ - if ! service_status > /dev/null; then - RETVAL=$1 - return $RETVAL - fi - - service_stop - service_start -} - -service_status() -{ - status -p ${PIDFILE} $DAEMON_PATH/$DAEMON -} - -service_status_quiet() -{ - status -p ${PIDFILE} $DAEMON_PATH/$DAEMON >/dev/null 2>&1 -} - -case "$1" in -start) - service_status_quiet && exit 0 - service_start -;; -stop) - service_status_quiet || exit 0 - service_stop -;; -restart) - service_stop - service_start -;; -try-restart) - condrestart 0 - ;; -force-reload) - condrestart 7 -;; -status) - service_status -;; -*) - echo "Usage: $0 {start|stop|restart|try-restart|force-reload|status}" - exit 3 -esac diff --git a/system/netdata-lsb.in b/system/netdata-lsb.in deleted file mode 100644 index e429ad1c93..0000000000 --- a/system/netdata-lsb.in +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env bash -# -# Netdata LSB start script -# -# Copyright: -# SPDX-License-Identifier: GPL-3.0-or-later -# -# Author: -# Costa Tsaousis -# Pavlos Emm. Katsoulakis - -### BEGIN INIT INFO -# Provides: netdata -# Required-Start: $local_fs $remote_fs $network $named $time -# Required-Stop: $local_fs $remote_fs $network $named $time -# Should-Start: $local_fs $network $named $remote_fs $time $all -# Should-Stop: $local_fs $network $named $remote_fs $time $all -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: Start and stop the netdata real-time monitoring server daemon -# Description: Controls the main netdata monitoring server daemon "netdata". -# and all its plugins. -### END INIT INFO -# -set -e -set -u -${DEBIAN_SCRIPT_DEBUG:+ set -v -x} - -DAEMON="netdata" -DAEMON_PATH=@sbindir_POST@ -PIDFILE_PATH=@localstatedir_POST@/run/netdata -PIDFILE=$PIDFILE_PATH/$DAEMON.pid -DAEMONOPTS="-P $PIDFILE" - -test -x $DAEMON_PATH/$DAEMON || exit 0 - -. /lib/lsb/init-functions - -# Safeguard (relative paths, core dumps..) -cd / -umask 022 - -service_start() { - if [ ! -d $PIDFILE_PATH ]; then - mkdir -p $PIDFILE_PATH - fi - - chown @netdata_user_POST@:@netdata_user_POST@ $PIDFILE_PATH - - log_daemon_msg "Starting real-time performance monitoring" "netdata" - start_daemon -p $PIDFILE $DAEMON_PATH/$DAEMON $DAEMONOPTS - RETVAL=$? - log_end_msg $RETVAL - return $RETVAL -} - -service_stop() { - log_daemon_msg "Stopping real-time performance monitoring" "netdata" - killproc -p ${PIDFILE} $DAEMON_PATH/$DAEMON - RETVAL=$? - log_end_msg $RETVAL - - if [ $RETVAL -eq 0 ]; then - rm -f ${PIDFILE} - fi - return $RETVAL -} - -condrestart() { - if ! service_status > /dev/null; then - RETVAL=$1 - return - fi - - service_stop - service_start -} - -service_status() { - status_of_proc -p $PIDFILE $DAEMON_PATH/$DAEMON netdata -} - - -# -# main() -# - -case "${1:-''}" in - 'start') - service_start - ;; - - 'stop') - service_stop - ;; - - 'restart') - service_stop - service_start - ;; - - 'try-restart') - condrestart 0 - ;; - - 'force-reload') - condrestart 7 - ;; - - 'status') - service_status && exit 0 || exit $? - ;; - *) - echo "Usage: $0 {start|stop|restart|try-restart|force-reload|status}" - exit 1 -esac diff --git a/system/netdata-openrc.in b/system/netdata-openrc.in deleted file mode 100644 index 1588789294..0000000000 --- a/system/netdata-openrc.in +++ /dev/null @@ -1,88 +0,0 @@ -#!/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@}" - -# 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}" - -extra_started_commands="reload rotate save" -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 - need net - after apache2 squid nginx mysql named opensips upsd hostapd postfix lm_sensors -} - -start_pre() { - checkpath -o ${NETDATA_OWNER} -d @localstatedir_POST@/cache/netdata @localstatedir_POST@/run/netdata - - if [ -z "${supervisor}" ]; then - pidfile="${NETDATA_PIDFILE}" - fi -} - -run_cmd() { - cmd="${1}" - msg="${2}" - failmsg="${3}" - signal="${4}" - - ebegin "${msg}" - if [ "${NETDATA_USE_NETDATACLI}" = 1 ]; then - "${command_prefix}/netdatacli" "${cmd}" >/dev/null - eend $? "${failmsg}" - elif [ "${supervisor}" = "supervise-daemon" ]; then - supervise-daemon "${RC_SVCNAME}" --signal "${signal}" - eend $? "${failmsg}" - else - start-stop-daemon --signal "${signal}" --pidfile "${pidfile}" - eend $? "${failmsg}" - fi -} - -reload() { - run_cmd reload-health \ - "Reloading Netdata health configuration" \ - "Failed to reload Netdata health configuration" \ - SIGUSR2 -} - -rotate() { - run_cmd reopen-logs \ - "Reopening Netdata log files" \ - "Failed to reopen Netdata log files" \ - SIGHUP -} - -save() { - run_cmd save-database \ - "Saving Netdata database" \ - "Failed to save Netdata database" \ - SIGUSR1 -} diff --git a/system/netdata-updater.service.in b/system/netdata-updater.service.in deleted file mode 100644 index d0bd4994c4..0000000000 --- a/system/netdata-updater.service.in +++ /dev/null @@ -1,8 +0,0 @@ -[Unit] -Description=Daily auto-updates for Netdata -RefuseManualStart=no -RefuseManualStop=yes - -[Service] -Type=oneshot -ExecStart=@pkglibexecdir_POST@/netdata-updater.sh diff --git a/system/netdata-updater.timer b/system/netdata-updater.timer deleted file mode 100644 index 8b36e46ff4..0000000000 --- a/system/netdata-updater.timer +++ /dev/null @@ -1,12 +0,0 @@ -[Unit] -Description=Daily auto-updates for Netdata -RefuseManualStart=no -RefuseManualStop=no - -[Timer] -Persistent=false -OnCalendar=daily -Unit=netdata-updater.service - -[Install] -WantedBy=timers.target diff --git a/system/netdata.crontab.in b/system/netdata.crontab.in deleted file mode 100644 index 8f0527e0e0..0000000000 --- a/system/netdata.crontab.in +++ /dev/null @@ -1 +0,0 @@ -2 57 * * * root @pkglibexecdir_POST@/netdata-updater.sh diff --git a/system/netdata.logrotate.in b/system/netdata.logrotate.in deleted file mode 100644 index 2c4949e5f6..0000000000 --- a/system/netdata.logrotate.in +++ /dev/null @@ -1,12 +0,0 @@ -@localstatedir_POST@/log/netdata/*.log { - daily - missingok - rotate 14 - compress - delaycompress - notifempty - sharedscripts - postrotate - /bin/kill -HUP `cat /run/netdata/netdata.pid 2>/dev/null` 2>/dev/null || true - endscript -} diff --git a/system/netdata.plist.in b/system/netdata.plist.in deleted file mode 100644 index a969b31775..0000000000 --- a/system/netdata.plist.in +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - Label - com.github.netdata - ProgramArguments - - @sbindir_POST@/netdata - - RunAtLoad - - - diff --git a/system/netdata.service.in b/system/netdata.service.in deleted file mode 100644 index 25d95b2b81..0000000000 --- a/system/netdata.service.in +++ /dev/null @@ -1,80 +0,0 @@ -# SPDX-License-Identifier: GPL-3.0-or-later -[Unit] -Description=Real time performance monitoring - -# append here other services you want netdata to wait for them to start -After=network.target httpd.service squid.service nfs-server.service mysqld.service mysql.service named.service postfix.service chronyd.service - -[Service] -Type=simple -User=@netdata_user_POST@ -Group=netdata -RuntimeDirectory=netdata -RuntimeDirectoryMode=0775 -PIDFile=/run/netdata/netdata.pid -ExecStart=@sbindir_POST@/netdata -P /run/netdata/netdata.pid -D -ExecStartPre=/bin/mkdir -p @localstatedir_POST@/cache/netdata -ExecStartPre=/bin/chown -R @netdata_user_POST@ @localstatedir_POST@/cache/netdata -ExecStartPre=/bin/mkdir -p /run/netdata -ExecStartPre=/bin/chown -R @netdata_user_POST@ /run/netdata -PermissionsStartOnly=true - -# saving a big db on slow disks may need some time -TimeoutStopSec=150 - -# restart netdata if it crashes -Restart=on-failure -RestartSec=30 - -# Valid policies: other (the system default) | batch | idle | fifo | rr -# To give netdata the max priority, set CPUSchedulingPolicy=rr and CPUSchedulingPriority=99 -CPUSchedulingPolicy=batch - -# This sets the scheduling priority (for policies: rr and fifo). -# Priority gets values 1 (lowest) to 99 (highest). -#CPUSchedulingPriority=1 - -# For scheduling policy 'other' and 'batch', this sets the lowest niceness of netdata (-20 highest to 19 lowest). -Nice=0 - -# Capabilities -# is required for freeipmi and slabinfo plugins -CapabilityBoundingSet=CAP_DAC_OVERRIDE -# is required for apps plugin -CapabilityBoundingSet=CAP_DAC_READ_SEARCH -# is required for freeipmi plugin -CapabilityBoundingSet=CAP_FOWNER CAP_SYS_RAWIO -# is required for apps, perf and slabinfo plugins -CapabilityBoundingSet=CAP_SETPCAP -# is required for perf plugin -CapabilityBoundingSet=CAP_SYS_ADMIN CAP_PERFMON -# is required for apps plugin -CapabilityBoundingSet=CAP_SYS_PTRACE -# is required for ebpf plugin -CapabilityBoundingSet=CAP_SYS_RESOURCE -# is required for go.d/ping app -CapabilityBoundingSet=CAP_NET_RAW -# is required for cgroups plugin -CapabilityBoundingSet=CAP_SYS_CHROOT -# is required for nfacct plugin (bandwidth accounting) -CapabilityBoundingSet=CAP_NET_ADMIN -# is required for plugins that use sudo -CapabilityBoundingSet=CAP_SETGID CAP_SETUID - -# Sandboxing -ProtectSystem=full -ProtectHome=read-only -# PrivateTmp break netdatacli functionality. See - https://github.com/netdata/netdata/issues/7587 -#PrivateTmp=true -ProtectControlGroups=on -# We whitelist this because it's the standard location to listen on a UNIX socket. -ReadWriteDirectories=/run/netdata -# This is needed to make email-based alert deliver work if Postfix is the email provider on the system. -ReadWriteDirectories=-/var/spool/postfix/maildrop -# LXCFS directories (https://github.com/lxc/lxcfs#lxcfs) -# If we don't set them explicitly, systemd mounts procfs from the host. See https://github.com/netdata/netdata/issues/14238. -BindReadOnlyPaths=-/proc/cpuinfo -/proc/diskstats -/proc/loadavg -/proc/meminfo -BindReadOnlyPaths=-/proc/stat -/proc/swaps -/proc/uptime -/proc/slabinfo - -[Install] -WantedBy=multi-user.target diff --git a/system/netdata.service.v235.in b/system/netdata.service.v235.in deleted file mode 100644 index e3232056fb..0000000000 --- a/system/netdata.service.v235.in +++ /dev/null @@ -1,42 +0,0 @@ -# SPDX-License-Identifier: GPL-3.0-or-later -[Unit] -Description=Real time performance monitoring - -# append here other services you want netdata to wait for them to start -After=network.target httpd.service squid.service nfs-server.service mysqld.service mysql.service named.service postfix.service chronyd.service - -[Service] -Type=simple -User=@netdata_user_POST@ -Group=netdata -RuntimeDirectory=netdata -CacheDirectory=netdata -StateDirectory=netdata -LogsDirectory=netdata -RuntimeDirectoryMode=0775 -StateDirectoryMode=0755 -CacheDirectoryMode=0755 -LogsDirectoryMode=2750 -EnvironmentFile=-/etc/default/netdata -ExecStart=@sbindir_POST@/netdata -D $EXTRA_OPTS - -# saving a big db on slow disks may need some time -TimeoutStopSec=150 - -# restart netdata if it crashes -Restart=on-failure -RestartSec=30 - -# Valid policies: other (the system default) | batch | idle | fifo | rr -# To give netdata the max priority, set CPUSchedulingPolicy=rr and CPUSchedulingPriority=99 -CPUSchedulingPolicy=batch - -# This sets the scheduling priority (for policies: rr and fifo). -# Priority gets values 1 (lowest) to 99 (highest). -#CPUSchedulingPriority=1 - -# For scheduling policy 'other' and 'batch', this sets the lowest niceness of netdata (-20 highest to 19 lowest). -Nice=0 - -[Install] -WantedBy=multi-user.target diff --git a/system/openrc/init.d/netdata.in b/system/openrc/init.d/netdata.in new file mode 100644 index 0000000000..1588789294 --- /dev/null +++ b/system/openrc/init.d/netdata.in @@ -0,0 +1,88 @@ +#!/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@}" + +# 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}" + +extra_started_commands="reload rotate save" +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 + need net + after apache2 squid nginx mysql named opensips upsd hostapd postfix lm_sensors +} + +start_pre() { + checkpath -o ${NETDATA_OWNER} -d @localstatedir_POST@/cache/netdata @localstatedir_POST@/run/netdata + + if [ -z "${supervisor}" ]; then + pidfile="${NETDATA_PIDFILE}" + fi +} + +run_cmd() { + cmd="${1}" + msg="${2}" + failmsg="${3}" + signal="${4}" + + ebegin "${msg}" + if [ "${NETDATA_USE_NETDATACLI}" = 1 ]; then + "${command_prefix}/netdatacli" "${cmd}" >/dev/null + eend $? "${failmsg}" + elif [ "${supervisor}" = "supervise-daemon" ]; then + supervise-daemon "${RC_SVCNAME}" --signal "${signal}" + eend $? "${failmsg}" + else + start-stop-daemon --signal "${signal}" --pidfile "${pidfile}" + eend $? "${failmsg}" + fi +} + +reload() { + run_cmd reload-health \ + "Reloading Netdata health configuration" \ + "Failed to reload Netdata health configuration" \ + SIGUSR2 +} + +rotate() { + run_cmd reopen-logs \ + "Reopening Netdata log files" \ + "Failed to reopen Netdata log files" \ + SIGHUP +} + +save() { + run_cmd save-database \ + "Saving Netdata database" \ + "Failed to save Netdata database" \ + SIGUSR1 +} diff --git a/system/systemd/netdata-updater.service.in b/system/systemd/netdata-updater.service.in new file mode 100644 index 0000000000..d0bd4994c4 --- /dev/null +++ b/system/systemd/netdata-updater.service.in @@ -0,0 +1,8 @@ +[Unit] +Description=Daily auto-updates for Netdata +RefuseManualStart=no +RefuseManualStop=yes + +[Service] +Type=oneshot +ExecStart=@pkglibexecdir_POST@/netdata-updater.sh diff --git a/system/systemd/netdata-updater.timer b/system/systemd/netdata-updater.timer new file mode 100644 index 0000000000..8b36e46ff4 --- /dev/null +++ b/system/systemd/netdata-updater.timer @@ -0,0 +1,12 @@ +[Unit] +Description=Daily auto-updates for Netdata +RefuseManualStart=no +RefuseManualStop=no + +[Timer] +Persistent=false +OnCalendar=daily +Unit=netdata-updater.service + +[Install] +WantedBy=timers.target diff --git a/system/systemd/netdata.service.in b/system/systemd/netdata.service.in new file mode 100644 index 0000000000..25d95b2b81 --- /dev/null +++ b/system/systemd/netdata.service.in @@ -0,0 +1,80 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +[Unit] +Description=Real time performance monitoring + +# append here other services you want netdata to wait for them to start +After=network.target httpd.service squid.service nfs-server.service mysqld.service mysql.service named.service postfix.service chronyd.service + +[Service] +Type=simple +User=@netdata_user_POST@ +Group=netdata +RuntimeDirectory=netdata +RuntimeDirectoryMode=0775 +PIDFile=/run/netdata/netdata.pid +ExecStart=@sbindir_POST@/netdata -P /run/netdata/netdata.pid -D +ExecStartPre=/bin/mkdir -p @localstatedir_POST@/cache/netdata +ExecStartPre=/bin/chown -R @netdata_user_POST@ @localstatedir_POST@/cache/netdata +ExecStartPre=/bin/mkdir -p /run/netdata +ExecStartPre=/bin/chown -R @netdata_user_POST@ /run/netdata +PermissionsStartOnly=true + +# saving a big db on slow disks may need some time +TimeoutStopSec=150 + +# restart netdata if it crashes +Restart=on-failure +RestartSec=30 + +# Valid policies: other (the system default) | batch | idle | fifo | rr +# To give netdata the max priority, set CPUSchedulingPolicy=rr and CPUSchedulingPriority=99 +CPUSchedulingPolicy=batch + +# This sets the scheduling priority (for policies: rr and fifo). +# Priority gets values 1 (lowest) to 99 (highest). +#CPUSchedulingPriority=1 + +# For scheduling policy 'other' and 'batch', this sets the lowest niceness of netdata (-20 highest to 19 lowest). +Nice=0 + +# Capabilities +# is required for freeipmi and slabinfo plugins +CapabilityBoundingSet=CAP_DAC_OVERRIDE +# is required for apps plugin +CapabilityBoundingSet=CAP_DAC_READ_SEARCH +# is required for freeipmi plugin +CapabilityBoundingSet=CAP_FOWNER CAP_SYS_RAWIO +# is required for apps, perf and slabinfo plugins +CapabilityBoundingSet=CAP_SETPCAP +# is required for perf plugin +CapabilityBoundingSet=CAP_SYS_ADMIN CAP_PERFMON +# is required for apps plugin +CapabilityBoundingSet=CAP_SYS_PTRACE +# is required for ebpf plugin +CapabilityBoundingSet=CAP_SYS_RESOURCE +# is required for go.d/ping app +CapabilityBoundingSet=CAP_NET_RAW +# is required for cgroups plugin +CapabilityBoundingSet=CAP_SYS_CHROOT +# is required for nfacct plugin (bandwidth accounting) +CapabilityBoundingSet=CAP_NET_ADMIN +# is required for plugins that use sudo +CapabilityBoundingSet=CAP_SETGID CAP_SETUID + +# Sandboxing +ProtectSystem=full +ProtectHome=read-only +# PrivateTmp break netdatacli functionality. See - https://github.com/netdata/netdata/issues/7587 +#PrivateTmp=true +ProtectControlGroups=on +# We whitelist this because it's the standard location to listen on a UNIX socket. +ReadWriteDirectories=/run/netdata +# This is needed to make email-based alert deliver work if Postfix is the email provider on the system. +ReadWriteDirectories=-/var/spool/postfix/maildrop +# LXCFS directories (https://github.com/lxc/lxcfs#lxcfs) +# If we don't set them explicitly, systemd mounts procfs from the host. See https://github.com/netdata/netdata/issues/14238. +BindReadOnlyPaths=-/proc/cpuinfo -/proc/diskstats -/proc/loadavg -/proc/meminfo +BindReadOnlyPaths=-/proc/stat -/proc/swaps -/proc/uptime -/proc/slabinfo + +[Install] +WantedBy=multi-user.target diff --git a/system/systemd/netdata.service.v235.in b/system/systemd/netdata.service.v235.in new file mode 100644 index 0000000000..e3232056fb --- /dev/null +++ b/system/systemd/netdata.service.v235.in @@ -0,0 +1,42 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +[Unit] +Description=Real time performance monitoring + +# append here other services you want netdata to wait for them to start +After=network.target httpd.service squid.service nfs-server.service mysqld.service mysql.service named.service postfix.service chronyd.service + +[Service] +Type=simple +User=@netdata_user_POST@ +Group=netdata +RuntimeDirectory=netdata +CacheDirectory=netdata +StateDirectory=netdata +LogsDirectory=netdata +RuntimeDirectoryMode=0775 +StateDirectoryMode=0755 +CacheDirectoryMode=0755 +LogsDirectoryMode=2750 +EnvironmentFile=-/etc/default/netdata +ExecStart=@sbindir_POST@/netdata -D $EXTRA_OPTS + +# saving a big db on slow disks may need some time +TimeoutStopSec=150 + +# restart netdata if it crashes +Restart=on-failure +RestartSec=30 + +# Valid policies: other (the system default) | batch | idle | fifo | rr +# To give netdata the max priority, set CPUSchedulingPolicy=rr and CPUSchedulingPriority=99 +CPUSchedulingPolicy=batch + +# This sets the scheduling priority (for policies: rr and fifo). +# Priority gets values 1 (lowest) to 99 (highest). +#CPUSchedulingPriority=1 + +# For scheduling policy 'other' and 'batch', this sets the lowest niceness of netdata (-20 highest to 19 lowest). +Nice=0 + +[Install] +WantedBy=multi-user.target -- cgit v1.2.3