From: Gunnar Beutner Date: Mon, 4 Feb 2013 11:43:16 +0000 (+0100) Subject: Added init script. X-Git-Tag: v0.0.2~558 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c4293cfa25ba2fb9a167948624745dd62cd90fac;p=icinga2 Added init script. Fixes #3114 --- diff --git a/Makefile.am b/Makefile.am index 645c5ac1e..2c23f0c39 100644 --- a/Makefile.am +++ b/Makefile.am @@ -9,7 +9,8 @@ SUBDIRS = \ components \ icinga-app \ test \ - itl + itl \ + etc #doc icinga2docdir = ${docdir} icinga2doc_DATA = \ diff --git a/components/compat/compatcomponent.cpp b/components/compat/compatcomponent.cpp index 662eeaa3d..fa4aa1b2c 100644 --- a/components/compat/compatcomponent.cpp +++ b/components/compat/compatcomponent.cpp @@ -36,7 +36,7 @@ String CompatComponent::GetStatusPath(void) const { Value statusPath = GetConfig()->Get("status_path"); if (statusPath.IsEmpty()) - return Application::GetLocalStateDir() + "/status.dat"; + return Application::GetLocalStateDir() + "/cache/status.dat"; else return statusPath; } @@ -50,7 +50,7 @@ String CompatComponent::GetObjectsPath(void) const { Value objectsPath = GetConfig()->Get("objects_path"); if (objectsPath.IsEmpty()) - return Application::GetLocalStateDir() + "/objects.cache"; + return Application::GetLocalStateDir() + "/cache/objects.cache"; else return objectsPath; } @@ -64,7 +64,7 @@ String CompatComponent::GetCommandPath(void) const { Value commandPath = GetConfig()->Get("command_path"); if (commandPath.IsEmpty()) - return Application::GetLocalStateDir() + "/icinga.cmd"; + return Application::GetLocalStateDir() + "/run/icinga.cmd"; else return commandPath; } diff --git a/configure.ac b/configure.ac index 283a7e905..c1cc486cb 100644 --- a/configure.ac +++ b/configure.ac @@ -99,8 +99,10 @@ components/delegation/Makefile components/demo/Makefile components/replication/Makefile docs/Doxyfile +etc/Makefile +etc/icinga2/Makefile +etc/init.d/Makefile icinga-app/Makefile -icinga-app/config/Makefile itl/Makefile lib/Makefile lib/base/Makefile @@ -113,7 +115,9 @@ third-party/cJSON/Makefile third-party/mmatch/Makefile third-party/popen-noshell/Makefile ]) -AC_OUTPUT +AC_OUTPUT([ +etc/init.d/icinga2 +]) if ! test -z "$LTDLDEPS"; then ltdl_msg="bundled" diff --git a/etc/Makefile.am b/etc/Makefile.am new file mode 100644 index 000000000..534cbbfe0 --- /dev/null +++ b/etc/Makefile.am @@ -0,0 +1,5 @@ +## Process this file with automake to produce Makefile.in + +SUBDIRS = \ + icinga2 \ + init.d diff --git a/icinga-app/config/Makefile.am b/etc/icinga2/Makefile.am similarity index 100% rename from icinga-app/config/Makefile.am rename to etc/icinga2/Makefile.am diff --git a/etc/icinga2/icinga2.conf.dist b/etc/icinga2/icinga2.conf.dist new file mode 100644 index 000000000..2cc96cf2b --- /dev/null +++ b/etc/icinga2/icinga2.conf.dist @@ -0,0 +1,48 @@ +/** + * Icinga 2 configuration file + * - this is where you define settings for the Icinga application including + * which hosts/services to check. + * + * The docs/icinga2-config.txt file in the source tarball has a detailed + * description of what configuration options are available. + */ + +#include +#include + +/** + * Global configuration settings + */ +local object IcingaApplication "icinga" { + macros = { + plugindir = "/usr/local/icinga/libexec" + } +} + +/** + * The compat component periodically updates the status.dat and objects.cache + * files. These are used by the Icinga 1.x CGIs to display the state of + * hosts and services. + */ +local object Component "compat" { } + +/** + * And finally we define some host that should be checked. + */ +object Host "localhost" { + services = { + "ping4", "ping6", + "http_ip", "ssh", + "load", "processes", + "users", "disk" + }, + + macros = { + address = "127.0.0.1", + address6 = "::1", + }, + + hostchecks = { "ping4", "ping6" }, + + check_interval = 1m +} diff --git a/icinga-app/config/icinga2.conf.win32 b/etc/icinga2/icinga2.conf.win32 similarity index 100% rename from icinga-app/config/icinga2.conf.win32 rename to etc/icinga2/icinga2.conf.win32 diff --git a/etc/init.d/Makefile.am b/etc/init.d/Makefile.am new file mode 100644 index 000000000..b6e62c210 --- /dev/null +++ b/etc/init.d/Makefile.am @@ -0,0 +1,8 @@ +## Process this file with automake to produce Makefile.in + +initdir = ${sysconfdir}/init.d +init_SCRIPTS = \ + icinga2 + +EXTRA_DIST = \ + icinga2.in diff --git a/etc/init.d/icinga2.in b/etc/init.d/icinga2.in new file mode 100644 index 000000000..e2f666e6e --- /dev/null +++ b/etc/init.d/icinga2.in @@ -0,0 +1,122 @@ +#!/bin/bash +# +# chkconfig: 35 90 12 +# description: Icinga 2 +# +### BEGIN INIT INFO +# Provides: icinga2 +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Start Icinga 2 at boot time +# Description: Icinga 2 +### END INIT INFO + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +sbindir=@sbindir@ +sysconfdir=@sysconfdir@ +localstatedir=@localstatedir@ + +DAEMON=$sbindir/icinga2 +ICINGA2_CONFIG_FILE=$sysconfdir/icinga2/icinga2.conf +ICINGA2_PID_FILE=$localstatedir/run/icinga2.pid + +test -x $DAEMON || exit 0 + +if [ ! -e $ICINGA2_CONFIG_FILE ]; then + echo "Config file '$ICINGA2_CONFIG_FILE' does not exist." + exit 1 +fi + +# Get function from functions library +if [ -e /etc/init.d/functions ]; then + . /etc/init.d/functions +fi + +# Start Icinga 2 +start() { + printf "Starting Icinga 2: " + $DAEMON -c $ICINGA2_CONFIG_FILE -d + echo "Done" + echo +} + +# Restart Icinga 2 +stop() { + printf "Stopping Icinga 2: " + if [ ! -e $ICINGA2_PID_FILE ]; then + echo "The PID file '$ICINGA2_PID_FILE' does not exist." + exit 1 + fi + + pid=`cat $ICINGA2_PID_FILE` + + if kill -TERM $pid >/dev/null 2>&1; then + for i in 1 2 3 4 5 6 7 8 9 10; do + if ! kill -CHLD $pid >/dev/null 2&>1; then + break + fi + + printf '.' + + sleep 1 + done + fi + + echo "Done" +} + +# Reload Icinga 2 +reload() { + printf "Reloading Icinga 2: " + if [ ! -e $ICINGA2_PID_FILE ]; then + echo "The PID file '$ICINGA2_PID_FILE' does not exist." + exit 1 + fi + + pid=`cat $ICINGA2_PID_FILE` + + if ! kill -HUP $pid >/dev/null 2>&1; then + echo "Failed - Icinga 2 is not running." + else + echo "Done" + fi +} + +# Print status for Icinga 2 +status() { + printf "Icinga 2 status: " + + pid=`cat $ICINGA2_PID_FILE` + if kill -CHLD $pid >/dev/null 2&>1; then + echo "Running" + else + echo "Not running" + fi +} + +### main logic ### +case "$1" in + start) + start + ;; + stop) + stop + ;; + status) + status FOO + ;; + restart|condrestart) + stop + start + ;; + reload) + reload + ;; + *) + echo $"Usage: $0 {start|stop|restart|reload|status}" + exit 1 +esac +exit 0 diff --git a/icinga-app/Makefile.am b/icinga-app/Makefile.am index 087edcc86..bf8370c2e 100644 --- a/icinga-app/Makefile.am +++ b/icinga-app/Makefile.am @@ -1,8 +1,5 @@ ## Process this file with automake to produce Makefile.in -SUBDIRS = \ - config - sbin_PROGRAMS = \ icinga2 diff --git a/icinga-app/config/icinga2.conf.dist b/icinga-app/config/icinga2.conf.dist deleted file mode 100644 index 62d6a64a4..000000000 --- a/icinga-app/config/icinga2.conf.dist +++ /dev/null @@ -1,185 +0,0 @@ -/** - * Icinga 2 configuration file - * - this is where you define settings for the Icinga application including - * which hosts/services to check. - * - * The docs/icinga2-config.txt file in the source tarball has a detailed - * description of what configuration options are available. - */ - -/** - * Global configuration settings - */ -local object IcingaApplication "icinga" { - pid_path = "./var/run/icinga2.pid", - state_path = "./var/lib/icinga2/icinga2.state", - - macros = { - plugindir = "/usr/local/icinga/libexec" - } -} - -/** - * Advanced logging settings - */ -local object Logger "my-debug-log" { - type = "console", - severity = "debug" -} - -/** - * The checker component takes care of executing service checks. - */ -local object Component "checker" { - -} - -/** - * The delegation component assigns services to checkers. You need to load - * this component even if your Icinga setup only consists of a single instance. - */ -local object Component "delegation" { - -} - -/** - * The compat component periodically updates the status.dat and objects.cache - * files. These are used by the Icinga 1.x CGIs to display the state of - * hosts and services. - */ -local object Component "compat" { - status_path = "./var/cache/icinga2/status.dat", - objects_path = "./var/cache/icinga2/objects.cache", -} - -/** - * The compatido component works as idomod connector to a running ido2db - * daemon, connected via tcp socket only. It will dump config and status - * information periodically for now. By default, this remains disabled. - */ -/* -local object Component "compatido" { - socket_address = "127.0.0.1", - socket_port = "5668", - instance_name = "i2-default", - reconnect_interval = 15, -} -*/ - -/** - * This template defines some basic parameters for services that use - * external plugins for their checks. - */ -abstract object Service "icinga-service" { - methods = { - check = "native::PluginCheck" - } -} - -/** - * The service templates for checks. In an Icinga 1.x environment - * this would be defined as a check command. - */ - -/** - * ping - */ -abstract object Service "ping4" inherits "icinga-service" { - check_command = "$plugindir$/check_ping -H $address$ -w $wrta$,$wpl$% -c $crta$,$cpl$%", - macros += { - wrta = 50, - wpl = 5, - crta = 100, - cpl = 10 - } -} - -abstract object Service "ping6" inherits "icinga-service" { - check_command = "$plugindir$/check_ping -6 -H $address6$ -w $wrta$,$wpl$% -c $crta$,$cpl$%", - macros += { - wrta = 50, - wpl = 5, - crta = 100, - cpl = 10 - } -} - -/** - * http - */ -abstract object Service "http" inherits "icinga-service" { - check_command = "$plugindir$/check_http -H '$address$' -I '$address$'", -} - -/** - * ssh - */ -abstract object Service "ssh" inherits "icinga-service" { - check_command = "$plugindir$/check_ssh '$address$'", -} - -/** - * local checks - */ -abstract object Service "disk space" inherits "icinga-service" { - check_command = "$plugindir$/check_disk -w '$wfree$' -c '$cfree$'", - macros += { - wfree = "20%", - cfree = "10%", - } -} - -abstract object Service "current users" inherits "icinga-service" { - check_command = "$plugindir$/check_users -w '$wgreater$' -c '$cgreater$'", - macros += { - wgreater = 20, - cgreater = 50, - } -} - -abstract object Service "total processes" inherits "icinga-service" { - check_command = "$plugindir$/check_procs -w '$wgreater$' -c '$cgreater$'", - macros += { - wgreater = 250, - cgreater = 400, - } -} - -abstract object Service "current load" inherits "icinga-service" { - check_command = "$plugindir$/check_load --warning='$wload1$,$wload5$,$wload15$' --critical='$cload1$,$cload5$,$cload15$'", - macros += { - wload1 = 5.0, - wload5 = 4.0, - wload15 = 3.0, - cload1 = 10.0, - cload5 = 6.0, - cload15 = 4.0, - } -} - -/** - * demo check - */ -abstract object Service "demo" inherits "icinga-service" { - check_command = "$plugindir$/check_dummy 1 'strawberry. yummy! | i=2'", -} - - -/** - * And finally we define some host that should be checked. - */ -object Host "localhost" { - services = { - "ping4", "ping6", - "http", "ssh", - "current load", "total processes", - "current users", "disk space", - "demo", - }, - macros = { - address = "127.0.0.1", - address6 = "::1", - }, - check_interval = 1m -} - diff --git a/itl/service-common.conf b/itl/service-common.conf index 6a7ff1544..9f82f8b03 100644 --- a/itl/service-common.conf +++ b/itl/service-common.conf @@ -17,48 +17,95 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -abstract object Service "ping" inherits "plugin-service" { - check_command = "$plugindir$/check_ping -H $address$ -w $wrta$,$wpl$% -c $crta$,$cpl$%a -p $packets$ -t $timeout$", +abstract object Service "ping4" inherits "plugin-service" { + check_command = "$plugindir$/check_ping -4 -H $address$ -w $wrta$,$wpl$% -c $crta$,$cpl$%a -p $packets$ -t $timeout$", macros = { wrta = 100, wpl = 5, - + crta = 200, cpl = 15, - + + packets = 5, + timeout = 0 + } +} + +abstract object Service "ping6" inherits "plugin-service" { + check_command = "$plugindir$/check_ping -6 -H $address6$ -w $wrta$,$wpl$% -c $crta$,$cpl$%a -p $packets$ -t $timeout$", + + macros = { + wrta = 100, + wpl = 5, + + crta = 200, + cpl = 15, + packets = 5, timeout = 0 } } abstract object Service "dummy" inherits "plugin-service" { - check_command = "$plugindir$/check_dummy $state$ '$text$'", - - macros = { - state = 0, - text = "Check was successful." - } + check_command = "$plugindir$/check_dummy $state$ '$text$'", + + macros = { + state = 0, + text = "Check was successful." + } +} + +abstract object Service "http_vhost" inherits "plugin-service" { + check_command = "$plugindir$/check_http -H $vhost$" } -abstract object Service "check_http_vhost" inherits "plugin-service" { - check_command = "$plugindir$/check_http -H $vhost$" +abstract object Service "http_ip" inherits "plugin-service" { + check_command = "$plugindir$/check_http -I $address$" } -abstract object Service "check_http_ip" inherits "plugin-service" { - check_command = "$plugindir$/check_http -I $address$" +abstract object Service "ssh" inherits "plugin-service" { + check_command = "$plugindir$/check_ssh $address$" } +abstract object Service "disk" inherits "plugin-service" { + check_command = "$plugindir$/check_disk -w '$wfree$' -c '$cfree$'", + + macros += { + wfree = "20%", + cfree = "10%", + } +} + +abstract object Service "users" inherits "plugin-service" { + check_command = "$plugindir$/check_users -w '$wgreater$' -c '$cgreater$'", + + macros += { + wgreater = 20, + cgreater = 50, + } +} + +abstract object Service "processes" inherits "plugin-service" { + check_command = "$plugindir$/check_procs -w '$wgreater$' -c '$cgreater$'", + + macros += { + wgreater = 250, + cgreater = 400, + } +} + + abstract object Service "load" inherits "plugin-service" { - check_command = "$plugindir$/check_load -w $wload1$,$wload5$,$wload15$ -c $cload1$,$cload5$,$cload15$", - - macros = { - wload1 = 0, - wload5 = 0, - wload15 = 0, - - cload1 = 0, - cload5 = 0, - crload5 = 0 - } + check_command = "$plugindir$/check_load -w $wload1$,$wload5$,$wload15$ -c $cload1$,$cload5$,$cload15$", + + macros = { + wload1 = 5.0, + wload5 = 4.0, + wload15 = 3.0, + + cload1 = 10.0, + cload5 = 6.0, + cload15 = 4.0 + } } diff --git a/lib/config/configcompiler.cpp b/lib/config/configcompiler.cpp index fd9c07298..adb0ef08f 100644 --- a/lib/config/configcompiler.cpp +++ b/lib/config/configcompiler.cpp @@ -118,7 +118,12 @@ String ConfigCompiler::GetPath(void) const */ void ConfigCompiler::HandleInclude(const String& include, bool search, const DebugInfo& debuginfo) { - String path = Utility::DirName(GetPath()) + "/" + include; + String path; + + if (search) + path = include; + else + path = Utility::DirName(GetPath()) + "/" + include; vector types; m_HandleInclude(path, search, &m_ResultObjects, &types, debuginfo);