Added init script.

Fixes #3114
This commit is contained in:
Gunnar Beutner 2013-02-04 12:43:16 +01:00
parent 789fd23d77
commit c4293cfa25
13 changed files with 272 additions and 220 deletions

View File

@ -9,7 +9,8 @@ SUBDIRS = \
components \
icinga-app \
test \
itl
itl \
etc
#doc
icinga2docdir = ${docdir}
icinga2doc_DATA = \

View File

@ -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;
}

View File

@ -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"

5
etc/Makefile.am Normal file
View File

@ -0,0 +1,5 @@
## Process this file with automake to produce Makefile.in
SUBDIRS = \
icinga2 \
init.d

View File

@ -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 <itl/itl.conf>
#include <itl/standalone.conf>
/**
* 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
}

8
etc/init.d/Makefile.am Normal file
View File

@ -0,0 +1,8 @@
## Process this file with automake to produce Makefile.in
initdir = ${sysconfdir}/init.d
init_SCRIPTS = \
icinga2
EXTRA_DIST = \
icinga2.in

122
etc/init.d/icinga2.in Normal file
View File

@ -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

View File

@ -1,8 +1,5 @@
## Process this file with automake to produce Makefile.in
SUBDIRS = \
config
sbin_PROGRAMS = \
icinga2

View File

@ -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
}

View File

@ -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 "check_http_vhost" inherits "plugin-service" {
check_command = "$plugindir$/check_http -H $vhost$"
abstract object Service "http_vhost" inherits "plugin-service" {
check_command = "$plugindir$/check_http -H $vhost$"
}
abstract object Service "check_http_ip" inherits "plugin-service" {
check_command = "$plugindir$/check_http -I $address$"
abstract object Service "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
}
}

View File

@ -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<ConfigType::Ptr> types;
m_HandleInclude(path, search, &m_ResultObjects, &types, debuginfo);