Skip to content
Permalink
Browse files

Improve path handling in cmake and daemon

  • Loading branch information...
lazyfrosch authored and gunnarbeutner committed Jul 31, 2018
1 parent a7a0122 commit 9fbc40615a747b2d5236ed499b0eca9c6d24e2ef
Showing with 498 additions and 708 deletions.
  1. +27 −3 CMakeLists.txt
  2. +13 −3 INSTALL.md
  3. +26 −0 cmake/SetFullDir.cmake
  4. +14 −7 config.h.cmake
  5. +1 −2 doc/07-agent-based-monitoring.md
  6. +1 −1 doc/08-advanced-topics.md
  7. +14 −14 doc/09-object-types.md
  8. +1 −2 doc/11-cli-commands.md
  9. +3 −3 doc/15-troubleshooting.md
  10. +42 −23 doc/17-language-reference.md
  11. +3 −3 doc/icinga2.8
  12. +29 −32 etc/CMakeLists.txt
  13. +4 −4 etc/icinga2/conf.d/commands.conf
  14. +1 −2 etc/icinga2/features-available/debuglog.conf
  15. +1 −2 etc/icinga2/features-available/mainlog.conf
  16. +5 −5 etc/initsystem/icinga2.init.d.cmake
  17. +1 −1 etc/initsystem/icinga2.service.cmake
  18. +8 −9 etc/initsystem/icinga2.sysconfig.cmake
  19. +10 −11 etc/initsystem/prepare-dirs.cmake
  20. +1 −1 etc/initsystem/safe-reload.cmake
  21. +3 −4 etc/logrotate.d/icinga2.cmake
  22. +3 −3 icinga-app/CMakeLists.txt
  23. +119 −32 icinga-app/icinga.cpp
  24. +1 −1 itl/CMakeLists.txt
  25. +1 −1 itl/plugins-contrib.d/CMakeLists.txt
  26. +1 −1 itl/plugins-contrib.d/databases.conf
  27. +1 −1 itl/plugins-contrib.d/smart-attributes.conf
  28. +2 −2 lib/base/CMakeLists.txt
  29. +45 −381 lib/base/application.cpp
  30. +3 −52 lib/base/application.hpp
  31. +1 −1 lib/base/tlsutility.cpp
  32. +4 −4 lib/checker/CMakeLists.txt
  33. +1 −1 lib/cli/apisetuputility.cpp
  34. +8 −6 lib/cli/daemoncommand.cpp
  35. +3 −3 lib/cli/daemonutility.cpp
  36. +2 −2 lib/cli/featureutility.cpp
  37. +1 −1 lib/cli/nodesetupcommand.cpp
  38. +3 −3 lib/cli/nodeutility.cpp
  39. +2 −2 lib/cli/nodewizardcommand.cpp
  40. +2 −2 lib/cli/objectlistcommand.cpp
  41. +32 −20 lib/cli/troubleshootcommand.cpp
  42. +1 −1 lib/cli/variablegetcommand.cpp
  43. +1 −1 lib/cli/variablelistcommand.cpp
  44. +2 −2 lib/cli/variableutility.cpp
  45. +6 −6 lib/compat/CMakeLists.txt
  46. +1 −1 lib/compat/checkresultreader.ti
  47. +1 −1 lib/compat/compatlogger.ti
  48. +1 −1 lib/compat/externalcommandlistener.ti
  49. +1 −1 lib/compat/statusdatawriter.cpp
  50. +2 −2 lib/compat/statusdatawriter.ti
  51. +2 −2 lib/config/configitem.cpp
  52. +1 −1 lib/db_ido_mysql/CMakeLists.txt
  53. +1 −1 lib/db_ido_pgsql/CMakeLists.txt
  54. +2 −2 lib/icinga/icingaapplication.cpp
  55. +0 −2 lib/icinga/icingaapplication.hpp
  56. +2 −2 lib/livestatus/CMakeLists.txt
  57. +2 −2 lib/livestatus/livestatuslistener.ti
  58. +4 −4 lib/notification/CMakeLists.txt
  59. +8 −8 lib/perfdata/CMakeLists.txt
  60. +4 −4 lib/perfdata/perfdatawriter.ti
  61. +5 −5 lib/remote/CMakeLists.txt
  62. +3 −3 lib/remote/apilistener-filesync.cpp
  63. +4 −4 lib/remote/apilistener.cpp
  64. +1 −1 lib/remote/configpackageutility.cpp
@@ -47,19 +47,43 @@ string(REPLACE "Version: " "" ICINGA2_VERSION ${VERSION_LINE})

include(GNUInstallDirs)
include(InstallConfig)
include(SetFullDir)

set(ICINGA2_USER "icinga" CACHE STRING "Icinga 2 user")
set(ICINGA2_GROUP "icinga" CACHE STRING "Icinga 2 group")
set(ICINGA2_COMMAND_GROUP "icingacmd" CACHE STRING "Icinga 2 command group")
set(ICINGA2_RUNDIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/run" CACHE STRING "/run directory")
set(ICINGA2_PLUGINDIR "/usr/lib/nagios/plugins" CACHE STRING "Path for the check plugins")
set(ICINGA2_GIT_VERSION_INFO ON CACHE BOOL "Whether to use git describe")
set(ICINGA2_UNITY_BUILD ON CACHE BOOL "Whether to perform a unity build")
set(ICINGA2_LTO_BUILD OFF CACHE BOOL "Whether to use LTO")

if(NOT WIN32)
set(ICINGA2_SYSCONFIGFILE "${CMAKE_INSTALL_FULL_SYSCONFDIR}/sysconfig/icinga2" CACHE PATH "where to store configuation for the init system, defaults to /etc/sysconfig/icinga2")
set(ICINGA2_CONFIGDIR "${CMAKE_INSTALL_SYSCONFDIR}/icinga2" CACHE FILEPATH "Main config directory, e.g. /etc/icinga2")
set(ICINGA2_CACHEDIR "${CMAKE_INSTALL_LOCALSTATEDIR}/cache/icinga2" CACHE FILEPATH "Directory for cache files, e.g. /var/cache/icinga2")
set(ICINGA2_DATADIR "${CMAKE_INSTALL_LOCALSTATEDIR}/lib/icinga2" CACHE FILEPATH "Data directory for the daemon, e.g. /var/lib/icinga2")
set(ICINGA2_LOGDIR "${CMAKE_INSTALL_LOCALSTATEDIR}/log/icinga2" CACHE FILEPATH "Logging directory, e.g. /var/log/icinga2")
set(ICINGA2_SPOOLDIR "${CMAKE_INSTALL_LOCALSTATEDIR}/spool/icinga2" CACHE FILEPATH "Spooling directory, e.g. /var/spool/icinga2")
set(ICINGA2_RUNDIR "${CMAKE_INSTALL_LOCALSTATEDIR}/run" CACHE STRING "/run directory (deprecated, please use ICINGA2_INITRUNDIR)")
set(ICINGA2_INITRUNDIR "${ICINGA2_RUNDIR}/icinga2" CACHE FILEPATH "Runtime data for the init system, e.g. /run/icinga2")

set(ICINGA2_PKGDATADIR "${CMAKE_INSTALL_DATADIR}/icinga2" CACHE FILEPATH "Installed data, e.g. /usr/share/icinga2")
set(ICINGA2_INCLUDEDIR "${ICINGA2_PKGDATADIR}/include" CACHE FILEPATH "Include directory for the ITL, e.g. /usr/share/icinga2/include")

# ensure absolute paths
set_full_dir(ICINGA2_FULL_CONFIGDIR "${ICINGA2_CONFIGDIR}")
set_full_dir(ICINGA2_FULL_CACHEDIR "${ICINGA2_CACHEDIR}")
set_full_dir(ICINGA2_FULL_DATADIR "${ICINGA2_DATADIR}")
set_full_dir(ICINGA2_FULL_LOGDIR "${ICINGA2_LOGDIR}")
set_full_dir(ICINGA2_FULL_SPOOLDIR "${ICINGA2_SPOOLDIR}")
set_full_dir(ICINGA2_FULL_RUNDIR "${ICINGA2_RUNDIR}")
set_full_dir(ICINGA2_FULL_INITRUNDIR "${ICINGA2_INITRUNDIR}")
set_full_dir(ICINGA2_FULL_PKGDATADIR "${ICINGA2_PKGDATADIR}")
set_full_dir(ICINGA2_FULL_INCLUDEDIR "${ICINGA2_INCLUDEDIR}")

set(LOGROTATE_DIR "${CMAKE_INSTALL_SYSCONFDIR}/logrotate.d" CACHE STRING "Location of logrotate configs, e.g. /etc/logrotate.d")
set(BASHCOMPLETION_DIR "${CMAKE_INSTALL_SYSCONFDIR}/bash_completion.d" CACHE STRING "Location of bash_completion files, e.g. /etc/bash_completion.d")

if(NOT WIN32)
set(ICINGA2_SYSCONFIGFILE "${CMAKE_INSTALL_SYSCONFDIR}/sysconfig/icinga2" CACHE PATH "where to store configuation for the init system, defaults to /etc/sysconfig/icinga2")
endif()

site_name(ICINGA2_BUILD_HOST_NAME)
@@ -130,16 +130,26 @@ $ cmake .. -DCMAKE_INSTALL_PREFIX=/tmp/icinga2

In addition to `CMAKE_INSTALL_PREFIX` here are most of the supported Icinga-specific cmake variables.

For all variables regarding defaults paths on in CMake, see
[GNUInstallDirs](https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html).

Also see `CMakeLists.txt` for details.

**System Environment**
- `CMAKE_INSTALL_SYSCONFDIR`: The configuration directory; defaults to `CMAKE_INSTALL_PREFIX/etc`
- `CMAKE_INSTALL_LOCALSTATEDIR`: The state directory; defaults to `CMAKE_INSTALL_PREFIX/var`
- `ICINGA2_CONFIGDIR`: Main config directory; defaults to `CMAKE_INSTALL_SYSCONFDIR/icinga2` usually `/etc/icinga2`
- `ICINGA2_CACHEDIR`: Directory for cache files; defaults to `CMAKE_INSTALL_LOCALSTATEDIR/cache/icinga2` usually `/var/cache/icinga2`
- `ICINGA2_DATADIR`: Data directory for the daemon; defaults to `CMAKE_INSTALL_LOCALSTATEDIR/lib/icinga2` usually `/var/lib/icinga2`
- `ICINGA2_LOGDIR`: Logfiles of the daemon; defaults to `CMAKE_INSTALL_LOCALSTATEDIR/log/icinga2 usually `/var/log/icinga2`
- `ICINGA2_SPOOLDIR`: Spooling directory ; defaults to `CMAKE_INSTALL_LOCALSTATEDIR/spool/icinga2` usually `/var/spool/icinga2`
- `ICINGA2_INITRUNDIR`: Runtime data for the init system; defaults to `CMAKE_INSTALL_LOCALSTATEDIR/run/icinga2` usually `/run/icinga2`
- `ICINGA2_GIT_VERSION_INFO`: Whether to use Git to determine the version number; defaults to `ON`
- `ICINGA2_USER`: The user Icinga 2 should run as; defaults to `icinga`
- `ICINGA2_GROUP`: The group Icinga 2 should run as; defaults to `icinga`
- `ICINGA2_COMMAND_GROUP`: The command group Icinga 2 should use; defaults to `icingacmd`
- `ICINGA2_RUNDIR`: The location of the "run" directory; defaults to `CMAKE_INSTALL_LOCALSTATEDIR/run`
- `CMAKE_INSTALL_SYSCONFDIR`: The configuration directory; defaults to `CMAKE_INSTALL_PREFIX/etc`
- `ICINGA2_SYSCONFIGFILE`: Where to put the config file the initscript/systemd pulls it's dirs from;
defaults to `CMAKE_INSTALL_PREFIX/etc/sysconfig/icinga2`
- `CMAKE_INSTALL_LOCALSTATEDIR`: The state directory; defaults to `CMAKE_INSTALL_PREFIX/var`
- `ICINGA2_PLUGINDIR`: The path for the Monitoring Plugins project binaries; defaults to `/usr/lib/nagios/plugins`

**Build Optimization**
@@ -0,0 +1,26 @@
# Icinga 2
# Copyright (C) 2018 Icinga Development Team (https://www.icinga.com)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.

# Ensures a directory is absolute by prefixing CMAKE_INSTALL_PREFIX if it is not
# similar to CMAKE_INSTALL_FULL_... https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html
function(set_full_dir var path)
if(NOT IS_ABSOLUTE "${path}")
message(STATUS "Prefixing in ${var} \"${path}\" with ${CMAKE_INSTALL_PREFIX}")
set(path "${CMAKE_INSTALL_PREFIX}/${path}")
endif()
set(${var} "${path}" PARENT_SCOPE)
endfunction(set_full_dir)
@@ -13,17 +13,24 @@

#cmakedefine ICINGA2_UNITY_BUILD

#define ICINGA_PREFIX "${CMAKE_INSTALL_PREFIX}"
#define ICINGA_SYSCONFDIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}"
#define ICINGA_RUNDIR "${ICINGA2_RUNDIR}"
#define ICINGA_LOCALSTATEDIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}"
#define ICINGA_PKGDATADIR "${CMAKE_INSTALL_FULL_DATADIR}/icinga2"
#define ICINGA_INCLUDECONFDIR "${CMAKE_INSTALL_FULL_DATADIR}/icinga2/include"
#define ICINGA_CONFIGDIR "${ICINGA2_FULL_CONFIGDIR}"
#define ICINGA_DATADIR "${ICINGA2_FULL_DATADIR}"
#define ICINGA_LOGDIR "${ICINGA2_FULL_LOGDIR}"
#define ICINGA_CACHEDIR "${ICINGA2_FULL_CACHEDIR}"
#define ICINGA_SPOOLDIR "${ICINGA2_FULL_SPOOLDIR}"
#define ICINGA_INITRUNDIR "${ICINGA2_FULL_INITRUNDIR}"
#define ICINGA_INCLUDECONFDIR "${ICINGA2_FULL_INCLUDEDIR}"
#define ICINGA_USER "${ICINGA2_USER}"
#define ICINGA_GROUP "${ICINGA2_GROUP}"
#define ICINGA_SYSCONFIGFILE "${ICINGA2_SYSCONFIGFILE}"
#define ICINGA_BUILD_HOST_NAME "${ICINGA2_BUILD_HOST_NAME}"
#define ICINGA_BUILD_COMPILER_NAME "${ICINGA2_BUILD_COMPILER_NAME}"
#define ICINGA_BUILD_COMPILER_VERSION "${ICINGA2_BUILD_COMPILER_VERSION}"

// Deprecated options?
#define ICINGA_PKGDATADIR "${ICINGA2_FULL_PKGDATADIR}"
#define ICINGA_PREFIX "${CMAKE_INSTALL_PREFIX}"
#define ICINGA_SYSCONFDIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}"
#define ICINGA_RUNDIR "${ICINGA2_FULL_RUNDIR}"
#define ICINGA_LOCALSTATEDIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}"

#endif /* CONFIG_H */
@@ -211,7 +211,7 @@ match your Icinga convention.
Add an `EventCommand` configuration object for the passive service auto reset event.

object EventCommand "coldstart-reset-event" {
command = [ SysconfDir + "/icinga2/conf.d/custom/scripts/coldstart_reset_event.sh" ]
command = [ ConfigDir + "/conf.d/custom/scripts/coldstart_reset_event.sh" ]

arguments = {
"-i" = "$service.state_id$"
@@ -356,4 +356,3 @@ passive update with the state and text from the second and third varbind:
vars.dummy_state = 2
vars.dummy_text = "No passive check result received."
}
@@ -990,7 +990,7 @@ You can omit the `log()` calls, they only help debugging.
log("Running command")
log(mailscript)
var cmd = [ SysconfDir + "/icinga2/scripts/" + mailscript ]
var cmd = [ ConfigDir + "/scripts/" + mailscript ]
log(LogCritical, "me", cmd)
return cmd
}}
@@ -76,12 +76,12 @@ The ApiListener type expects its certificate files to be in the following locati

Type | Location
---------------------|-------------------------------------
Private key | `LocalStateDir + "/lib/icinga2/certs/" + NodeName + ".key"`
Certificate file | `LocalStateDir + "/lib/icinga2/certs/" + NodeName + ".crt"`
CA certificate file | `LocalStateDir + "/lib/icinga2/certs/ca.crt"`
Private key | `DataDir + "/certs/" + NodeName + ".key"`
Certificate file | `DataDir + "/certs/" + NodeName + ".crt"`
CA certificate file | `DataDir + "/certs/ca.crt"`

If the deprecated attributes `cert_path`, `key_path` and/or `ca_path` are specified Icinga 2
copies those files to the new location in `LocalStateDir + "/lib/icinga2/certs"` unless the
copies those files to the new location in `DataDir + "/certs"` unless the
file(s) there are newer.

Please check the [upgrading chapter](16-upgrading-icinga-2.md#upgrading-to-2-8-certificate-paths) for more details.
@@ -273,7 +273,7 @@ Configuration Attributes:

Name | Type | Description
--------------------------|-----------------------|----------------------------------
spool\_dir | String | **Optional.** The directory which contains the check result files. Defaults to LocalStateDir + "/lib/icinga2/spool/checkresults/".
spool\_dir | String | **Optional.** The directory which contains the check result files. Defaults to DataDir + "/spool/checkresults/".

## Comment <a id="objecttype-comment"></a>

@@ -322,7 +322,7 @@ Configuration Attributes:

Name | Type | Description
--------------------------|-----------------------|----------------------------------
log\_dir | String | **Optional.** Path to the compat log directory. Defaults to LocalStateDir + "/log/icinga2/compat".
log\_dir | String | **Optional.** Path to the compat log directory. Defaults to LogDir + "/compat".
rotation\_method | String | **Optional.** Specifies when to rotate log files. Can be one of "HOURLY", "DAILY", "WEEKLY" or "MONTHLY". Defaults to "HOURLY".


@@ -1084,7 +1084,7 @@ Configuration Attributes:
bind\_host | String | **Optional.** Only valid when `socket_type` is set to `tcp`. Host address to listen on for connections. Defaults to `127.0.0.1`.
bind\_port | Number | **Optional.** Only valid when `socket_type` is set to `tcp`. Port to listen on for connections. Defaults to `6558`.
socket\_path | String | **Optional.** Only valid when `socket_type` is set to `unix`. Specifies the path to the UNIX socket file. Defaults to RunDir + "/icinga2/cmd/livestatus".
compat\_log\_path | String | **Optional.** Path to Icinga 1.x log files. Required for historical table queries. Requires `CompatLogger` feature enabled. Defaults to LocalStateDir + "/log/icinga2/compat"
compat\_log\_path | String | **Optional.** Path to Icinga 1.x log files. Required for historical table queries. Requires `CompatLogger` feature enabled. Defaults to LogDir + "/compat"

> **Note**
>
@@ -1179,7 +1179,7 @@ Example:

```
object NotificationCommand "mail-service-notification" {
command = [ SysconfDir + "/icinga2/scripts/mail-service-notification.sh" ]
command = [ ConfigDir + "/scripts/mail-service-notification.sh" ]
arguments += {
"-4" = {
@@ -1329,10 +1329,10 @@ Configuration Attributes:

Name | Type | Description
--------------------------|-----------------------|----------------------------------
host\_perfdata\_path | String | **Optional.** Path to the host performance data file. Defaults to LocalStateDir + "/spool/icinga2/perfdata/host-perfdata".
service\_perfdata\_path | String | **Optional.** Path to the service performance data file. Defaults to LocalStateDir + "/spool/icinga2/perfdata/service-perfdata".
host\_temp\_path | String | **Optional.** Path to the temporary host file. Defaults to LocalStateDir + "/spool/icinga2/tmp/host-perfdata".
service\_temp\_path | String | **Optional.** Path to the temporary service file. Defaults to LocalStateDir + "/spool/icinga2/tmp/service-perfdata".
host\_perfdata\_path | String | **Optional.** Path to the host performance data file. Defaults to SpoolDir + "/perfdata/host-perfdata".
service\_perfdata\_path | String | **Optional.** Path to the service performance data file. Defaults to SpoolDir + "/perfdata/service-perfdata".
host\_temp\_path | String | **Optional.** Path to the temporary host file. Defaults to SpoolDir + "/tmp/host-perfdata".
service\_temp\_path | String | **Optional.** Path to the temporary service file. Defaults to SpoolDir + "/tmp/service-perfdata".
host\_format\_template | String | **Optional.** Host Format template for the performance data file. Defaults to a template that's suitable for use with PNP4Nagios.
service\_format\_template | String | **Optional.** Service Format template for the performance data file. Defaults to a template that's suitable for use with PNP4Nagios.
rotation\_interval | Duration | **Optional.** Rotation interval for the files specified in `{host,service}_perfdata_path`. Defaults to `30s`.
@@ -1534,8 +1534,8 @@ Configuration Attributes:

Name | Type | Description
--------------------------|-----------------------|----------------------------------
status\_path | String | **Optional.** Path to the `status.dat` file. Defaults to LocalStateDir + "/cache/icinga2/status.dat".
objects\_path | String | **Optional.** Path to the `objects.cache` file. Defaults to LocalStateDir + "/cache/icinga2/objects.cache".
status\_path | String | **Optional.** Path to the `status.dat` file. Defaults to CacheDir + "/status.dat".
objects\_path | String | **Optional.** Path to the `objects.cache` file. Defaults to CacheDir + "/objects.cache".
update\_interval | Duration | **Optional.** The interval in which the status files are updated. Defaults to `15s`.


@@ -402,7 +402,7 @@ Configuration files are processed in the order they're specified on the command-

When no configuration file is specified and the `--no-config` is not used
Icinga 2 automatically falls back to using the configuration file
`SysconfDir + "/icinga2/icinga2.conf"` (where SysconfDir is usually `/etc`).
`ConfigDir + "/icinga2.conf"` (where ConfigDir is usually `/etc/icinga2`).

### Validation <a id="cli-command-daemon-validation"></a>

@@ -730,4 +730,3 @@ safely reload the Icinga 2 daemon.
The `reload` action will send the `SIGHUP` signal to the Icinga 2 daemon
which will validate the configuration in a separate process and not stop
the other events like check execution, notifications, etc.

@@ -237,9 +237,9 @@ include <itl>
include <plugins>
```

in the [icinga2.conf](04-configuring-icinga-2.md#icinga2-conf) configuration file. These files are not considered configuration files and will be overridden
on upgrade, so please send modifications as proposed patches upstream. The default include path is set to
`LocalStateDir + "/share/icinga2/includes"`.
in the [icinga2.conf](04-configuring-icinga-2.md#icinga2-conf) configuration file. These files are not considered
configuration files and will be overridden on upgrade, so please send modifications as proposed patches upstream.
The default include path is set to `/usr/share/icinga2/includes` with the constant `IncludeConfDir`.

You should add your own command definitions to a new file in `conf.d/` called `commands.conf`
or similar.

0 comments on commit 9fbc406

Please sign in to comment.
You can’t perform that action at this time.