summaryrefslogtreecommitdiffstats
path: root/etc/initsystem
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:34:54 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:34:54 +0000
commit0915b3ef56dfac3113cce55a59a5765dc94976be (patch)
treea8fea11d50b4f083e1bf0f90025ece7f0824784a /etc/initsystem
parentInitial commit. (diff)
downloadicinga2-0915b3ef56dfac3113cce55a59a5765dc94976be.tar.xz
icinga2-0915b3ef56dfac3113cce55a59a5765dc94976be.zip
Adding upstream version 2.13.6.upstream/2.13.6upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'etc/initsystem')
-rw-r--r--etc/initsystem/CMakeLists.txt44
-rw-r--r--etc/initsystem/icinga2.init.d.cmake198
-rw-r--r--etc/initsystem/icinga2.service.cmake30
-rw-r--r--etc/initsystem/icinga2.service.limits.conf9
-rw-r--r--etc/initsystem/icinga2.sysconfig.cmake15
-rw-r--r--etc/initsystem/prepare-dirs.cmake52
-rw-r--r--etc/initsystem/safe-reload.cmake52
7 files changed, 400 insertions, 0 deletions
diff --git a/etc/initsystem/CMakeLists.txt b/etc/initsystem/CMakeLists.txt
new file mode 100644
index 0000000..eb0f9f2
--- /dev/null
+++ b/etc/initsystem/CMakeLists.txt
@@ -0,0 +1,44 @@
+# Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+
+
+
+if(NOT WIN32)
+ configure_file(icinga2.sysconfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/initsystem/icinga2.sysconfig @ONLY)
+ get_filename_component(ICINGA2_SYSCONFIGFILE_NAME ${ICINGA2_SYSCONFIGFILE} NAME)
+ get_filename_component(ICINGA2_SYSCONFIGFILE_DIR ${ICINGA2_SYSCONFIGFILE} PATH)
+ install(
+ FILES ${CMAKE_CURRENT_BINARY_DIR}/initsystem/icinga2.sysconfig
+ DESTINATION ${ICINGA2_SYSCONFIGFILE_DIR}
+ RENAME ${ICINGA2_SYSCONFIGFILE_NAME}
+ PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
+ )
+
+ configure_file(prepare-dirs.cmake ${CMAKE_CURRENT_BINARY_DIR}/initsystem/prepare-dirs @ONLY)
+ configure_file(safe-reload.cmake ${CMAKE_CURRENT_BINARY_DIR}/initsystem/safe-reload @ONLY)
+ install(
+ FILES ${CMAKE_CURRENT_BINARY_DIR}/initsystem/prepare-dirs ${CMAKE_CURRENT_BINARY_DIR}/initsystem/safe-reload
+ DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/icinga2
+ PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
+ )
+
+ # required for packaging on Gentoo, see Bug #6498
+ option (INSTALL_SYSTEMD_SERVICE_AND_INITSCRIPT
+ "Force install both the systemd service definition file and the SysV initscript in parallel, regardless of how USE_SYSTEMD is set. Only use this for special packaging purposes and if you know what you are doing" OFF)
+
+ if (NOT USE_SYSTEMD OR INSTALL_SYSTEMD_SERVICE_AND_INITSCRIPT)
+ configure_file(icinga2.init.d.cmake ${CMAKE_CURRENT_BINARY_DIR}/initsystem/icinga2 @ONLY)
+ install(
+ FILES ${CMAKE_CURRENT_BINARY_DIR}/initsystem/icinga2
+ DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/init.d
+ PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
+ )
+ endif()
+
+ if (USE_SYSTEMD OR INSTALL_SYSTEMD_SERVICE_AND_INITSCRIPT)
+ configure_file(icinga2.service.cmake ${CMAKE_CURRENT_BINARY_DIR}/initsystem/icinga2.service @ONLY)
+ install(
+ FILES ${CMAKE_CURRENT_BINARY_DIR}/initsystem/icinga2.service
+ DESTINATION ${DESTDIR}/usr/lib/systemd/system
+ PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
+ )
+ endif()
+endif()
diff --git a/etc/initsystem/icinga2.init.d.cmake b/etc/initsystem/icinga2.init.d.cmake
new file mode 100644
index 0000000..56588a7
--- /dev/null
+++ b/etc/initsystem/icinga2.init.d.cmake
@@ -0,0 +1,198 @@
+#!/bin/sh
+#
+# chkconfig: 35 90 12
+# description: Icinga 2
+#
+### BEGIN INIT INFO
+# Provides: icinga2
+# Required-Start: $remote_fs $syslog $network
+# Required-Stop: $remote_fs $syslog $network
+# Should-Start: mysql postgresql
+# Should-Stop: mysql postgresql
+# Default-Start: 2 3 5
+# Default-Stop: 0 1 6
+# Short-Description: icinga2 host/service/network monitoring and management system
+# Description: Icinga 2 is a monitoring and management system for hosts, services and networks.
+### END INIT INFO
+
+# Get function from functions library
+if [ -f /etc/rc.d/init.d/functions ]; then
+ . /etc/rc.d/init.d/functions
+elif [ -f /etc/init.d/functions ]; then
+ . /etc/init.d/functions
+fi
+
+# load system specific defines
+SYSCONFIGFILE=@ICINGA2_SYSCONFIGFILE@
+if [ -f "$SYSCONFIGFILE" ]; then
+ . "$SYSCONFIGFILE"
+else
+ echo "Couldn't load system specific defines from $SYSCONFIGFILE. Using defaults."
+fi
+
+# Set defaults, to overwrite see "@ICINGA2_SYSCONFIGFILE@"
+
+: "${ICINGA2_USER:="@ICINGA2_USER@"}"
+: "${ICINGA2_GROUP:="@ICINGA2_GROUP@"}"
+: "${ICINGA2_COMMAND_GROUP:="@ICINGA2_COMMAND_GROUP@"}"
+: "${DAEMON:="@CMAKE_INSTALL_FULL_SBINDIR@/icinga2"}"
+: "${ICINGA2_CONFIG_FILE:="@ICINGA2_CONFIGDIR@/icinga2.conf"}"
+: "${ICINGA2_ERROR_LOG:=@ICINGA2_LOGDIR@/error.log}"
+: "${ICINGA2_STARTUP_LOG:=@ICINGA2_LOGDIR@/startup.log}"
+: "${ICINGA2_PID_FILE:="@ICINGA2_INITRUNDIR@/icinga2.pid"}"
+
+# Load extra environment variables
+if [ -f /etc/default/icinga2 ]; then
+ . /etc/default/icinga2
+fi
+
+test -x "$DAEMON" || exit 5
+
+if [ ! -e "$ICINGA2_CONFIG_FILE" ]; then
+ echo "Config file '$ICINGA2_CONFIG_FILE' does not exist."
+ exit 6
+fi
+
+if ! getent passwd "$ICINGA2_USER" >/dev/null 2>&1; then
+ echo "Icinga user '$ICINGA2_USER' does not exist. Exiting."
+ exit 6
+fi
+
+if ! getent group "$ICINGA2_GROUP" >/dev/null 2>&1; then
+ echo "Icinga group '$ICINGA2_GROUP' does not exist. Exiting."
+ exit 6
+fi
+
+if ! getent group "$ICINGA2_COMMAND_GROUP" >/dev/null 2>&1; then
+ echo "Icinga command group '$ICINGA2_COMMAND_GROUP' does not exist. Exiting."
+ exit 6
+fi
+
+# Start Icinga 2
+start() {
+ printf "Starting Icinga 2: "
+ @CMAKE_INSTALL_PREFIX@/lib/icinga2/prepare-dirs "$SYSCONFIGFILE"
+
+ if ! "$DAEMON" daemon -c "$ICINGA2_CONFIG_FILE" -d -e "$ICINGA2_ERROR_LOG" > "$ICINGA2_STARTUP_LOG" 2>&1; then
+ echo "Error starting Icinga. Check '$ICINGA2_STARTUP_LOG' for details."
+ exit 1
+ else
+ echo "Done"
+ fi
+}
+
+# Restart Icinga 2
+stop() {
+ printf "Stopping Icinga 2: "
+
+ if [ ! -e "$ICINGA2_PID_FILE" ]; then
+ echo "The PID file '$ICINGA2_PID_FILE' does not exist."
+ if [ "x$1" = "xnofail" ]; then
+ return
+ else
+ exit 7
+ fi
+ fi
+
+ pid=`cat "$ICINGA2_PID_FILE"`
+
+ if icinga2 internal signal -s SIGINT -p "$pid" >/dev/null 2>&1; then
+ for i in 1 2 3 4 5 6 7 8 9 10; do
+ if ! icinga2 internal signal -s SIGCHLD -p "$pid" >/dev/null 2>&1; then
+ break
+ fi
+
+ printf '.'
+ sleep 3
+ done
+ fi
+
+ if icinga2 internal signal -s SIGCHLD -p "$pid" >/dev/null 2>&1; then
+ icinga2 internal signal -s SIGKILL -p "$pid" >/dev/null 2>&1
+ fi
+
+ echo "Done"
+}
+
+# Reload Icinga 2
+reload() {
+ exec @CMAKE_INSTALL_PREFIX@/lib/icinga2/safe-reload "$SYSCONFIGFILE"
+}
+
+# Check the Icinga 2 configuration
+checkconfig() {
+ printf "Checking configuration: "
+
+ if ! "$DAEMON" daemon -c "$ICINGA2_CONFIG_FILE" -C > "$ICINGA2_STARTUP_LOG" 2>&1; then
+ if [ "x$1" = "x" ]; then
+ cat "$ICINGA2_STARTUP_LOG"
+ echo "Icinga 2 detected configuration errors. Check '$ICINGA2_STARTUP_LOG' for details."
+ exit 1
+ else
+ echo "Not ${1}ing Icinga 2 due to configuration errors. Check '$ICINGA2_STARTUP_LOG' for details."
+ if [ "x$2" = "xfail" ]; then
+ exit 1
+ fi
+ fi
+ fi
+
+ echo "Done"
+ # no arguments requires full output
+ if [ "x$1" = "x" ]; then
+ cat "$ICINGA2_STARTUP_LOG"
+ fi
+}
+
+# Print status for Icinga 2
+status() {
+ printf "Icinga 2 status: "
+
+ if [ ! -e "$ICINGA2_PID_FILE" ]; then
+ echo "Not running"
+ exit 3
+ fi
+
+ pid=`cat "$ICINGA2_PID_FILE"`
+ if icinga2 internal signal -s SIGCHLD -p "$pid" >/dev/null 2>&1; then
+ echo "Running"
+ else
+ echo "Not running"
+ exit 3
+ fi
+}
+
+### main logic ###
+case "$1" in
+ start)
+ checkconfig start fail
+ start
+ ;;
+ stop)
+ stop
+ ;;
+ status)
+ status
+ ;;
+ restart)
+ checkconfig restart fail
+ stop nofail
+ start
+ ;;
+ condrestart)
+ status > /dev/null 2>&1 || exit 0
+ checkconfig restart fail
+ stop nofail
+ start
+ ;;
+ reload)
+ reload
+ ;;
+ checkconfig)
+ checkconfig
+ ;;
+ *)
+ echo "Usage: $0 {start|stop|restart|reload|checkconfig|status}"
+ exit 3
+esac
+
+exit 0
diff --git a/etc/initsystem/icinga2.service.cmake b/etc/initsystem/icinga2.service.cmake
new file mode 100644
index 0000000..ca85930
--- /dev/null
+++ b/etc/initsystem/icinga2.service.cmake
@@ -0,0 +1,30 @@
+[Unit]
+Description=Icinga host/service/network monitoring system
+Requires=network-online.target
+After=syslog.target network-online.target icingadb-redis.service postgresql.service mariadb.service carbon-cache.service carbon-relay.service
+
+[Service]
+Type=notify
+NotifyAccess=all
+Environment="ICINGA2_ERROR_LOG=@ICINGA2_LOGDIR@/error.log"
+EnvironmentFile=@ICINGA2_SYSCONFIGFILE@
+ExecStartPre=@CMAKE_INSTALL_PREFIX@/lib/icinga2/prepare-dirs @ICINGA2_SYSCONFIGFILE@
+ExecStart=@CMAKE_INSTALL_FULL_SBINDIR@/icinga2 daemon --close-stdio -e ${ICINGA2_ERROR_LOG}
+PIDFile=@ICINGA2_INITRUNDIR@/icinga2.pid
+ExecReload=@CMAKE_INSTALL_PREFIX@/lib/icinga2/safe-reload @ICINGA2_SYSCONFIGFILE@
+TimeoutStartSec=30m
+KillMode=mixed
+
+# Systemd >228 enforces a lower process number for services.
+# Depending on the distribution and Systemd version, this must
+# be explicitly raised. Packages will set the needed values
+# into /etc/systemd/system/icinga2.service.d/limits.conf
+#
+# Please check the troubleshooting documentation for further details.
+# The values below can be used as examples for customized service files.
+
+#TasksMax=infinity
+#LimitNPROC=62883
+
+[Install]
+WantedBy=multi-user.target
diff --git a/etc/initsystem/icinga2.service.limits.conf b/etc/initsystem/icinga2.service.limits.conf
new file mode 100644
index 0000000..dea0cde
--- /dev/null
+++ b/etc/initsystem/icinga2.service.limits.conf
@@ -0,0 +1,9 @@
+# Icinga 2 sets Systemd default values to extend OS defaults.
+#
+# Please check the troubleshooting documentation for further details.
+
+[Service]
+TasksMax=infinity
+
+# Uncomment this setting in case of further problems.
+#LimitNPROC=62883
diff --git a/etc/initsystem/icinga2.sysconfig.cmake b/etc/initsystem/icinga2.sysconfig.cmake
new file mode 100644
index 0000000..167c125
--- /dev/null
+++ b/etc/initsystem/icinga2.sysconfig.cmake
@@ -0,0 +1,15 @@
+#This is the default environment Icinga 2 runs with.
+#Make your changes here.
+
+#DAEMON=@CMAKE_INSTALL_FULL_SBINDIR@/icinga2
+#ICINGA2_CONFIG_FILE=@ICINGA2_CONFIGDIR@/icinga2.conf
+#ICINGA2_INIT_RUN_DIR=@ICINGA2_INITRUNDIR@
+#ICINGA2_PID_FILE=@ICINGA2_INITRUNDIR@/icinga2.pid
+#ICINGA2_LOG_DIR=@ICINGA2_LOGDIR@
+#ICINGA2_ERROR_LOG=@ICINGA2_LOGDIR@/error.log
+#ICINGA2_STARTUP_LOG=@ICINGA2_LOGDIR@/startup.log
+#ICINGA2_LOG=@ICINGA2_LOGDIR@/icinga2.log
+#ICINGA2_CACHE_DIR=@ICINGA2_CACHEDIR@
+#ICINGA2_USER=@ICINGA2_USER@
+#ICINGA2_GROUP=@ICINGA2_GROUP@
+#ICINGA2_COMMAND_GROUP=@ICINGA2_COMMAND_GROUP@
diff --git a/etc/initsystem/prepare-dirs.cmake b/etc/initsystem/prepare-dirs.cmake
new file mode 100644
index 0000000..0053b90
--- /dev/null
+++ b/etc/initsystem/prepare-dirs.cmake
@@ -0,0 +1,52 @@
+#!/bin/sh
+#
+# This script prepares directories and files needed for running Icinga2
+#
+
+# Load sysconf on systems where the initsystem does not pass the environment
+if [ "$1" != "" ]; then
+ if [ -r "$1" ]; then
+ . "$1"
+ else
+ echo "Unable to read sysconf from '$1'. Exiting." && exit 6
+ fi
+fi
+
+# Set defaults, to overwrite see "@ICINGA2_SYSCONFIGFILE@"
+
+: "${ICINGA2_USER:="@ICINGA2_USER@"}"
+: "${ICINGA2_GROUP:="@ICINGA2_GROUP@"}"
+: "${ICINGA2_COMMAND_GROUP:="@ICINGA2_COMMAND_GROUP@"}"
+: "${ICINGA2_INIT_RUN_DIR:="@ICINGA2_FULL_INITRUNDIR@"}"
+: "${ICINGA2_LOG_DIR:="@ICINGA2_FULL_LOGDIR@"}"
+: "${ICINGA2_CACHE_DIR:="@ICINGA2_FULL_CACHEDIR@"}"
+
+if ! getent passwd "$ICINGA2_USER" >/dev/null 2>&1; then
+ echo "Icinga user '$ICINGA2_USER' does not exist. Exiting."
+ exit 6
+fi
+
+if ! getent group "$ICINGA2_GROUP" >/dev/null 2>&1; then
+ echo "Icinga group '$ICINGA2_GROUP' does not exist. Exiting."
+ exit 6
+fi
+
+if ! getent group "$ICINGA2_COMMAND_GROUP" >/dev/null 2>&1; then
+ echo "Icinga command group '$ICINGA2_COMMAND_GROUP' does not exist. Exiting."
+ exit 6
+fi
+
+if [ ! -e "$ICINGA2_INIT_RUN_DIR" ]; then
+ mkdir -m 755 "$ICINGA2_INIT_RUN_DIR"
+ mkdir -m 2750 "$ICINGA2_INIT_RUN_DIR"/cmd
+fi
+
+chown -R "$ICINGA2_USER:$ICINGA2_COMMAND_GROUP" "$ICINGA2_INIT_RUN_DIR"
+
+test -e "$ICINGA2_LOG_DIR" || install -m 750 -o "$ICINGA2_USER" -g "$ICINGA2_COMMAND_GROUP" -d "$ICINGA2_LOG_DIR"
+
+if type restorecon >/dev/null 2>&1; then
+ restorecon -R "$ICINGA2_INIT_RUN_DIR"/
+fi
+
+test -e "$ICINGA2_CACHE_DIR" || install -m 750 -o "$ICINGA2_USER" -g "$ICINGA2_COMMAND_GROUP" -d "$ICINGA2_CACHE_DIR"
diff --git a/etc/initsystem/safe-reload.cmake b/etc/initsystem/safe-reload.cmake
new file mode 100644
index 0000000..0cba415
--- /dev/null
+++ b/etc/initsystem/safe-reload.cmake
@@ -0,0 +1,52 @@
+#!/bin/sh
+
+# Load sysconf on systems where the initsystem does not pass the environment
+if [ "$1" != "" ]; then
+ if [ -r "$1" ]; then
+ . "$1"
+ else
+ echo "Unable to read sysconf from '$1'. Exiting."
+ exit 6
+ fi
+fi
+
+# Set defaults, to overwrite see "@ICINGA2_SYSCONFIGFILE@"
+
+: "${ICINGA2_PID_FILE:="@ICINGA2_FULL_INITRUNDIR@/icinga2.pid"}"
+: "${DAEMON:="@CMAKE_INSTALL_FULL_SBINDIR@/icinga2"}"
+
+printf "Validating config files: "
+
+OUTPUTFILE=`mktemp`
+
+if type selinuxenabled >/dev/null 2>&1; then
+ if selinuxenabled; then
+ chcon -t icinga2_tmp_t "$OUTPUTFILE" >/dev/null 2>&1
+ fi
+fi
+
+if ! "$DAEMON" daemon --validate --color > "$OUTPUTFILE"; then
+ echo "Failed"
+
+ cat "$OUTPUTFILE"
+ rm -f "$OUTPUTFILE"
+ exit 1
+fi
+
+echo "Done"
+rm -f "$OUTPUTFILE"
+
+printf "Reloading Icinga 2: "
+
+if [ ! -e "$ICINGA2_PID_FILE" ]; then
+ exit 7
+fi
+
+pid=`cat "$ICINGA2_PID_FILE"`
+if ! kill -HUP "$pid" >/dev/null 2>&1; then
+ echo "Error: Icinga not running"
+ exit 7
+fi
+
+echo "Done"
+exit 0