summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
Diffstat (limited to 'system')
-rw-r--r--system/Makefile.am44
-rwxr-xr-xsystem/edit-config.in101
-rw-r--r--system/netdata-freebsd.in52
-rw-r--r--system/netdata-init-d.in94
-rw-r--r--system/netdata-lsb.in106
-rw-r--r--system/netdata-openrc.in60
-rw-r--r--system/netdata.conf24
-rw-r--r--system/netdata.logrotate.in12
-rw-r--r--system/netdata.plist.in15
-rw-r--r--system/netdata.service.in48
10 files changed, 556 insertions, 0 deletions
diff --git a/system/Makefile.am b/system/Makefile.am
new file mode 100644
index 0000000..b085dca
--- /dev/null
+++ b/system/Makefile.am
@@ -0,0 +1,44 @@
+#
+# Copyright (C) 2015 Alon Bar-Lev <alon.barlev@gmail.com>
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+MAINTAINERCLEANFILES= $(srcdir)/Makefile.in
+CLEANFILES = \
+ edit-config \
+ netdata-openrc \
+ netdata.logrotate \
+ netdata.service \
+ netdata-init-d \
+ netdata-lsb \
+ netdata-freebsd \
+ netdata.plist \
+ $(NULL)
+
+include $(top_srcdir)/build/subst.inc
+SUFFIXES = .in
+
+dist_config_SCRIPTS = \
+ edit-config \
+ $(NULL)
+
+nodist_noinst_DATA = \
+ netdata-openrc \
+ netdata.logrotate \
+ netdata.service \
+ netdata-init-d \
+ netdata-lsb \
+ netdata-freebsd \
+ netdata.plist \
+ $(NULL)
+
+dist_noinst_DATA = \
+ edit-config.in \
+ netdata-openrc.in \
+ netdata.logrotate.in \
+ netdata.service.in \
+ netdata-init-d.in \
+ netdata-lsb.in \
+ netdata-freebsd.in \
+ netdata.plist.in \
+ netdata.conf \
+ $(NULL)
diff --git a/system/edit-config.in b/system/edit-config.in
new file mode 100755
index 0000000..abfd5a4
--- /dev/null
+++ b/system/edit-config.in
@@ -0,0 +1,101 @@
+#!/usr/bin/env sh
+
+[ -f /etc/profile ] && . /etc/profile
+
+file="${1}"
+
+if [ "$(command -v editor)" ] ; then
+ EDITOR="${EDITOR-editor}"
+else
+ EDITOR="${EDITOR-vi}"
+fi
+
+[ -z "${NETDATA_USER_CONFIG_DIR}" ] && NETDATA_USER_CONFIG_DIR="@configdir_POST@"
+[ -z "${NETDATA_STOCK_CONFIG_DIR}" ] && NETDATA_STOCK_CONFIG_DIR="@libconfigdir_POST@"
+
+if [ -z "${file}" ]
+then
+ cat <<USAGE
+
+USAGE:
+ ${0} FILENAME
+
+ Copy and edit the stock config file named: FILENAME
+ if FILENAME is already copied, it will be edited as-is.
+
+ The EDITOR shell variable is used to define the editor to be used.
+
+ Stock config files at: '${NETDATA_STOCK_CONFIG_DIR}'
+ User config files at: '${NETDATA_USER_CONFIG_DIR}'
+
+ Available files in '${NETDATA_STOCK_CONFIG_DIR}' to copy and edit:
+
+USAGE
+
+ cd "${NETDATA_STOCK_CONFIG_DIR}" || exit 1
+ ls >&2 -R *.conf */*.conf
+ exit 1
+
+fi
+
+file_is_in_path() {
+ local file path real
+ file="${1}"
+ path="${2}"
+
+ real="$(readlink -f "${file}")"
+
+ # we don't have working readlink
+ [ -z "${real}" ] && return 0
+
+ if [ ! -z "${real}" ] && [ -z "$(echo "${real}" | grep -E "^${path}.*$")" ]
+ then
+ echo >&2 "File '${file}' is physically at '${real}', which is not in '${path}'. Aborting."
+ exit 1
+ fi
+
+ return 0
+}
+
+edit() {
+ echo >&2 "Editing '${1}' ..."
+
+ # check we can edit
+ file_is_in_path "${1}" "${NETDATA_USER_CONFIG_DIR}" || exit 1
+
+ "${EDITOR}" "${1}"
+ exit $?
+}
+
+copy_and_edit() {
+ # check we can copy
+ file_is_in_path "${NETDATA_STOCK_CONFIG_DIR}/${1}" "${NETDATA_STOCK_CONFIG_DIR}" || exit 1
+
+ if [ ! -f "${NETDATA_USER_CONFIG_DIR}/${1}" ]
+ then
+ echo >&2 "Copying '${NETDATA_STOCK_CONFIG_DIR}/${1}' to '${NETDATA_USER_CONFIG_DIR}/${1}' ... "
+ cp -p "${NETDATA_STOCK_CONFIG_DIR}/${1}" "${NETDATA_USER_CONFIG_DIR}/${1}" || exit 1
+ fi
+
+ edit "${NETDATA_USER_CONFIG_DIR}/${1}"
+}
+
+# make sure it is not absolute filename
+c1="$(echo "${file}" | cut -b 1)"
+if [ "${c1}" = "/" ] || [ "${c1}" = "." ]
+then
+ echo >&2 "Please don't use filenames starting with '/' or '.'"
+ exit 1
+fi
+
+# already exists
+if [ -f "${NETDATA_USER_CONFIG_DIR}/${file}" ]
+then
+ edit "${NETDATA_USER_CONFIG_DIR}/${file}"
+fi
+
+[ -f "${NETDATA_USER_CONFIG_DIR}/${file}" ] && edit "${NETDATA_USER_CONFIG_DIR}/${file}"
+[ -f "${NETDATA_STOCK_CONFIG_DIR}/${file}" ] && copy_and_edit "${file}"
+
+echo >&2 "File '${file}' is not found in '${NETDATA_STOCK_CONFIG_DIR}'"
+exit 1
diff --git a/system/netdata-freebsd.in b/system/netdata-freebsd.in
new file mode 100644
index 0000000..233535b
--- /dev/null
+++ b/system/netdata-freebsd.in
@@ -0,0 +1,52 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+. /etc/rc.subr
+
+name=netdata
+rcvar=netdata_enable
+
+piddir="@localstatedir_POST@/run/netdata"
+pidfile="${pidfile}/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}"
+ 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
new file mode 100644
index 0000000..9ac5101
--- /dev/null
+++ b/system/netdata-init-d.in
@@ -0,0 +1,94 @@
+#!/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
+ 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
new file mode 100644
index 0000000..e623f1e
--- /dev/null
+++ b/system/netdata-lsb.in
@@ -0,0 +1,106 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+### BEGIN INIT INFO
+# Provides: netdata
+# Required-Start: $local_fs $remote_fs $network $named $time apache2 httpd squid nginx mysql named opensips upsd hostapd postfix lm_sensors
+# Required-Stop: $local_fs $remote_fs $network $named $time apache2 httpd squid nginx mysql named opensips upsd hostapd postfix lm_sensors
+# 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
+
+ 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
new file mode 100644
index 0000000..2acf282
--- /dev/null
+++ b/system/netdata-openrc.in
@@ -0,0 +1,60 @@
+#!/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:netdata}"
+
+# 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}"
+
+# Netdata will use these services, only if they
+# are enabled to start.
+: "${NETDATA_START_AFTER_SERVICES:=apache2 squid nginx mysql named opensips upsd hostapd postfix lm_sensors}"
+
+extra_started_commands="reload rotate save"
+pidfile="@localstatedir_POST@/run/netdata/netdata.pid"
+command="@sbindir_POST@/netdata"
+command_args="-P ${pidfile} ${NETDATA_EXTRA_ARGS}"
+start_stop_daemon_args="-u ${NETDATA_OWNER}"
+required_files="/etc/netdata/netdata.conf"
+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 ${NETDATA_START_AFTER_SERVICES}
+}
+
+start_pre() {
+ checkpath -o ${NETDATA_OWNER} -d @localstatedir_POST@/cache/netdata @localstatedir_POST@/run/netdata
+}
+
+reload() {
+ ebegin "Reloading Netdata"
+ start-stop-daemon --signal SIGUSR2 --pidfile "${pidfile}"
+ eend $? "Failed to reload Netdata"
+}
+
+rotate() {
+ ebegin "Logrotating Netdata"
+ start-stop-daemon --signal SIGHUP --pidfile "${pidfile}"
+ eend $? "Failed to logrotate Netdata"
+}
+
+save() {
+ ebegin "Saving Netdata database"
+ start-stop-daemon --signal SIGUSR1 --pidfile "${pidfile}"
+ eend $? "Failed to save Netdata database"
+}
diff --git a/system/netdata.conf b/system/netdata.conf
new file mode 100644
index 0000000..7d7c54f
--- /dev/null
+++ b/system/netdata.conf
@@ -0,0 +1,24 @@
+# netdata configuration
+#
+# You can download the latest version of this file, using:
+#
+# wget -O /etc/netdata/netdata.conf http://localhost:19999/netdata.conf
+# or
+# curl -o /etc/netdata/netdata.conf http://localhost:19999/netdata.conf
+#
+# You can uncomment and change any of the options below.
+# The value shown in the commented settings, is the default value.
+#
+
+[global]
+ run as user = netdata
+
+ # the default database size - 1 hour
+ history = 3600
+
+ # by default do not expose the netdata port
+ bind to = localhost
+
+[web]
+ web files owner = root
+ web files group = netdata
diff --git a/system/netdata.logrotate.in b/system/netdata.logrotate.in
new file mode 100644
index 0000000..a766b6c
--- /dev/null
+++ b/system/netdata.logrotate.in
@@ -0,0 +1,12 @@
+@localstatedir_POST@/log/netdata/*.log {
+ daily
+ missingok
+ rotate 14
+ compress
+ delaycompress
+ notifempty
+ sharedscripts
+ postrotate
+ /bin/kill -HUP `cat @localstatedir_POST@/run/netdata/netdata.pid 2>/dev/null` 2>/dev/null || true
+ endscript
+}
diff --git a/system/netdata.plist.in b/system/netdata.plist.in
new file mode 100644
index 0000000..a969b31
--- /dev/null
+++ b/system/netdata.plist.in
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<!-- SPDX-License-Identifier: GPL-3.0-or-later -->
+<plist version="1.0">
+<dict>
+ <key>Label</key>
+ <string>com.github.netdata</string>
+ <key>ProgramArguments</key>
+ <array>
+ <string>@sbindir_POST@/netdata</string>
+ </array>
+ <key>RunAtLoad</key>
+ <true/>
+</dict>
+</plist>
diff --git a/system/netdata.service.in b/system/netdata.service.in
new file mode 100644
index 0000000..dd0ee3c
--- /dev/null
+++ b/system/netdata.service.in
@@ -0,0 +1,48 @@
+# 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
+Group=netdata
+RuntimeDirectory=netdata
+RuntimeDirectoryMode=0775
+PIDFile=@localstatedir_POST@/run/netdata/netdata.pid
+ExecStart=@sbindir_POST@/netdata -P @localstatedir_POST@/run/netdata/netdata.pid -D -W set global 'process scheduling policy' 'keep' -W set global 'OOM score' 'keep'
+ExecStartPre=/bin/mkdir -p @localstatedir_POST@/cache/netdata
+ExecStartPre=/bin/chown -R netdata:netdata @localstatedir_POST@/cache/netdata
+ExecStartPre=/bin/mkdir -p @localstatedir_POST@/run/netdata
+ExecStartPre=/bin/chown -R netdata:netdata @localstatedir_POST@/run/netdata
+#ExecStopPost=/bin/rm @localstatedir_POST@/run/netdata/netdata.pid
+PermissionsStartOnly=true
+
+# saving a big db on slow disks may need some time
+TimeoutStopSec=60
+
+# restart netdata if it crashes
+Restart=on-failure
+RestartSec=30
+
+# The minimum netdata Out-Of-Memory (OOM) score.
+# netdata (via [global].OOM score in netdata.conf) can only increase the value set here.
+# To decrease it, set the minimum here and set the same or a higher value in netdata.conf.
+# Valid values: -1000 (never kill netdata) to 1000 (always kill netdata).
+OOMScoreAdjust=1000
+
+# Valid policies: other (the system default) | batch | idle | fifo | rr
+# To give netdata the max priority, set CPUSchedulingPolicy=rr and CPUSchedulingPriority=99
+CPUSchedulingPolicy=idle
+
+# 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