diff --git a/.travis.yml b/.travis.yml index 89b52bdd8..6963d0514 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,16 +36,16 @@ addons: before_script: - if [ "$COVERITY_SCAN_BRANCH" != 1 ]; then - mkdir build; - cd build; + mkdir build && + cd build && cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/tmp/icinga2 -DICINGA2_PLUGINDIR=/tmp/icinga2/sbin; fi script: - if [ "$COVERITY_SCAN_BRANCH" != 1 ]; then - make; - make test; - make install; - /tmp/icinga2/sbin/icinga2 --version; + make && + make test && + make install && + /tmp/icinga2/sbin/icinga2 --version && /tmp/icinga2/sbin/icinga2 daemon -C -DRunAsUser=$(id -u -n) -DRunAsGroup=$(id -g -n); fi diff --git a/CMakeLists.txt b/CMakeLists.txt index e66efb2e8..1af131836 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/INSTALL.md b/INSTALL.md index 6c3b9aa0b..044ea507d 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -1,7 +1,7 @@ # Installing Icinga 2 -The recommended way of installing Icinga 2 is to use packages. The Icinga -project provides both release and development packages for a number +The recommended way of installing Icinga 2 is to use [packages](https://packages.icinga.com). +The Icinga project provides both release and development packages for a number of operating systems. Please check the documentation in the [doc/](doc/) directory for a current list @@ -13,12 +13,13 @@ and will guide you step by step. There are a number of known caveats when installing from source such as incorrect directory and file permissions. So even if you're planning to not use the official packages it is advisable to build your own Debian -or RPM packages. +or RPM packages. You can use the source packages from [packages.icinga.com](https://packages.icinga.com) +for this purpose. -**Disclaimer** - -This information is intended for developers and packagers. It might be incomplete or unclear -in some cases. Make also sure to check our [packaging scripts on GitHub](https://github.com/Icinga/icinga-packaging)! +> **Disclaimer** +> +> This information is intended for developers and packagers. It might be incomplete or unclear +> in some cases. Ensure to check our [packaging scripts on GitHub](https://github.com/Icinga/icinga-packaging) too! # Build Requirements @@ -75,18 +76,16 @@ application using a dist tarball (including notes for distributions): **FreeBSD**: libexecinfo (automatically used when Icinga 2 is installed via port or package) -**RHEL5** ships an ancient flex version. Updated packages are available for -example from the repoforge buildtools repository. - -* x86: https://mirror.hs-esslingen.de/repoforge/redhat/el5/en/i386/buildtools/ -* x86\_64: https://mirror.hs-esslingen.de/repoforge/redhat/el5/en/x86\_64/buildtools/ +**RHEL6**: Requires a newer boost version which is available on packages.icinga.com +with a version suffixed name. ## Runtime user environment -By default Icinga will run as user 'icinga' and group 'icinga'. Additionally the +By default Icinga will run as user `icinga` and group `icinga`. Additionally the external command pipe and livestatus features require a dedicated command group -'icingacmd'. You can choose your own user/group names and pass them to CMake +`icingacmd`. You can choose your own user/group names and pass them to CMake using the `ICINGA2_USER`, `ICINGA2_GROUP` and `ICINGA2_COMMAND_GROUP` variables. + ``` # groupadd icinga # groupadd icingacmd @@ -94,6 +93,7 @@ using the `ICINGA2_USER`, `ICINGA2_GROUP` and `ICINGA2_COMMAND_GROUP` variables. ``` On Alpine (which uses ash busybox) you can run: + ``` # addgroup -S icinga # addgroup -S icingacmd @@ -114,14 +114,17 @@ is running as. Once you have installed all the necessary build requirements you can build Icinga 2 using the following commands: + ``` -$ mkdir build && cd build +$ mkdir release && cd release $ cmake .. -$ make -$ make install +$ cd .. +$ make -C release +$ make install -C release ``` You can specify an alternative installation prefix using `-DCMAKE_INSTALL_PREFIX`: + ``` $ cmake .. -DCMAKE_INSTALL_PREFIX=/tmp/icinga2 ``` @@ -130,20 +133,30 @@ $ 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** -- `ICINGA2_UNITY_BUILD`: Whether to perform a unity build; defaults to `ON` +- `ICINGA2_UNITY_BUILD`: Whether to perform a unity build; defaults to `ON`. Note: This requires additional memory and is not advised for building VMs, Docker for Mac and embedded hardware. - `ICINGA2_LTO_BUILD`: Whether to use link time optimization (LTO); defaults to `OFF` **Init System** @@ -235,6 +248,11 @@ Copy the icinga2.spec file to `rpmbuild/SPEC` or fetch the latest version: curl https://raw.githubusercontent.com/Icinga/rpm-icinga2/master/icinga2.spec -o $HOME/rpmbuild/SPECS/icinga2.spec ``` +> **Note** +> +> The above command builds snapshot packages. Change to the `release` branch +> for release package builds. + Copy the tarball to `rpmbuild/SOURCES` e.g. by using the `spectool` binary provided with `rpmdevtools`: ``` @@ -273,7 +291,7 @@ The following packages are required to build the SELinux policy module: * selinux-policy (selinux-policy on CentOS 6, selinux-policy-devel on CentOS 7) * selinux-policy-doc -#### RHEL/CentOS 5 and 6 +#### RHEL/CentOS 6 The RedHat Developer Toolset is required for building Icinga 2 beforehand. This contains a modern version of flex and a C++ compiler which supports @@ -313,7 +331,7 @@ added before building. > **WARNING:** This information is outdated! Setup your build environment on Debian/Ubuntu, copy the 'debian' directory from -the Debian packaging Git repository (https://github.com/Icinga/pkg-icinga2-debian) +the Debian packaging Git repository (https://github.com/Icinga/deb-icinga2) into your source tree and run the following command: ``` $ dpkg-buildpackage -uc -us diff --git a/cmake/InstallConfig.cmake b/cmake/InstallConfig.cmake index f01357c79..aa39b9dfb 100644 --- a/cmake/InstallConfig.cmake +++ b/cmake/InstallConfig.cmake @@ -15,38 +15,47 @@ # along with this program; if not, write to the Free Software Foundation # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. +# Install $src into directory $dest - usually only used for config files +# +# * similar to install() a non absolute path is prefixed with CMAKE_INSTALL_PREFIX on runtime +# * in case of CPack path with be prefixed with share/skel/ +# * DESTDIR is prefixed as well +# +# also see https://cmake.org/cmake/help/latest/command/install.html function(install_if_not_exists src dest) - set(real_dest "${dest}") if(NOT IS_ABSOLUTE "${src}") set(src "${CMAKE_CURRENT_SOURCE_DIR}/${src}") endif() + get_filename_component(src_name "${src}" NAME) - get_filename_component(basename_dest "${src}" NAME) - string(REPLACE "/" "\\\\" nsis_src "${src}") - string(REPLACE "/" "\\\\" nsis_dest_dir "${real_dest}") - string(REPLACE "/" "\\\\" nsis_dest "${real_dest}/${basename_dest}") + install(CODE " - if(\"\$ENV{DESTDIR}\" STREQUAL \"\") - set(target_dir \${CMAKE_INSTALL_PREFIX}) + set(dest \"${dest}\") + + if (\"\${CMAKE_INSTALL_PREFIX}\" MATCHES .*/_CPack_Packages/.*) + set(dest \"share/skel/\${dest}\") + set(force_overwrite TRUE) else() - set(target_dir \$ENV{DESTDIR}) + set(force_overwrite FALSE) endif() - if(\${CMAKE_INSTALL_PREFIX} MATCHES .*/_CPack_Packages/.* OR NOT EXISTS \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/\${skel_prefix}${dest}/${src_name}\") - message(STATUS \"Installing: \$ENV{DESTDIR}${dest}/${src_name}\") - if(\${CMAKE_INSTALL_PREFIX} MATCHES .*/_CPack_Packages/.*) - set(skel_prefix \"share/skel/\") - else() - set(skel_prefix \"\") - endif() - execute_process(COMMAND \${CMAKE_COMMAND} -E copy \"${src}\" - \"\${target_dir}/\${skel_prefix}${dest}/${src_name}\" + + if(NOT IS_ABSOLUTE \"\${dest}\") + set(dest \"\${CMAKE_INSTALL_PREFIX}/\${dest}\") + endif() + + set(full_dest \"\$ENV{DESTDIR}\${dest}/${src_name}\") + + if(force_overwrite OR NOT EXISTS \"\${full_dest}\") + message(STATUS \"Installing: ${src} into \${full_dest}\") + + execute_process(COMMAND \${CMAKE_COMMAND} -E copy \"${src}\" \"\${full_dest}\" RESULT_VARIABLE copy_result ERROR_VARIABLE error_output) if(copy_result) message(FATAL_ERROR \${error_output}) endif() else() - message(STATUS \"Skipping : \${target_dir}/${dest}/${src_name}\") + message(STATUS \"Skipping : \${full_dest}\") endif() ") endfunction(install_if_not_exists) diff --git a/cmake/SetFullDir.cmake b/cmake/SetFullDir.cmake new file mode 100644 index 000000000..bd63a68bf --- /dev/null +++ b/cmake/SetFullDir.cmake @@ -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) diff --git a/config.h.cmake b/config.h.cmake index c461e029f..16fa190f1 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -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 */ diff --git a/doc/07-agent-based-monitoring.md b/doc/07-agent-based-monitoring.md index e2597a341..48c0d1cf8 100644 --- a/doc/07-agent-based-monitoring.md +++ b/doc/07-agent-based-monitoring.md @@ -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." } - diff --git a/doc/08-advanced-topics.md b/doc/08-advanced-topics.md index 44b41dffb..58ce96310 100644 --- a/doc/08-advanced-topics.md +++ b/doc/08-advanced-topics.md @@ -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 }} diff --git a/doc/09-object-types.md b/doc/09-object-types.md index 34ea958e8..904e31b23 100644 --- a/doc/09-object-types.md +++ b/doc/09-object-types.md @@ -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 @@ -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`. diff --git a/doc/11-cli-commands.md b/doc/11-cli-commands.md index 1b5011683..012fe72f3 100644 --- a/doc/11-cli-commands.md +++ b/doc/11-cli-commands.md @@ -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 @@ -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. - diff --git a/doc/15-troubleshooting.md b/doc/15-troubleshooting.md index d78bc9aa0..e4758921f 100644 --- a/doc/15-troubleshooting.md +++ b/doc/15-troubleshooting.md @@ -237,9 +237,9 @@ include include ``` -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. diff --git a/doc/16-upgrading-icinga-2.md b/doc/16-upgrading-icinga-2.md index 870b09d69..b44fbf51f 100644 --- a/doc/16-upgrading-icinga-2.md +++ b/doc/16-upgrading-icinga-2.md @@ -7,6 +7,36 @@ Specific version upgrades are described below. Please note that version updates are incremental. An upgrade from v2.6 to v2.8 requires to follow the instructions for v2.7 too. +## Upgrading to v2.10 + +### Path Constant Changes + +During package upgrades you may see a notice that the configuration +content of features has changed. This is due to a more general approach +with path constants in v2.10. + +The known constants `SysconfDir` and `LocalStateDir` stay intact and won't +break on upgrade. +If you are using these constants in your own custom command definitions +or other objects, you are advised to revise them and update them according +to the [documentation](17-language-reference.md#icinga-constants). + +Example diff: + +``` +object NotificationCommand "mail-service-notification" { +- command = [ SysconfDir + "/icinga2/scripts/mail-service-notification.sh" ] ++ command = [ ConfigDir + "/scripts/mail-service-notification.sh" ] +``` + +If you have the `ICINGA2_RUN_DIR` environment variable configured in the +sysconfig file, you need to rename it to `ICINGA2_INIT_RUN_DIR`. `ICINGA2_STATE_DIR` +has been removed and this setting has no effect. + +> **Note** +> +> This is important if you rely on the sysconfig configuration in your own scripts. + ## Upgrading to v2.9 ### Deprecation and Removal Notes diff --git a/doc/17-language-reference.md b/doc/17-language-reference.md index 285a9fcb9..1f50f610c 100644 --- a/doc/17-language-reference.md +++ b/doc/17-language-reference.md @@ -386,33 +386,71 @@ once they are set. ### Icinga 2 Specific Constants -Icinga 2 provides a number of special global constants. Some of them can be overridden using the `--define` command line parameter: +Icinga 2 provides a number of special global constants. These include directory paths, global configuration +and runtime parameters for the application version and (build) platform. -Variable |Description +Directory paths: + +Constant | Description +--------------------|------------------- +ConfigDir |**Read-only.** Main configuration directory. Usually set to `/etc/icinga2`. +DataDir |**Read-only.** Runtime data for the Icinga daemon. Usually set to `/var/lib/icinga2`. +LogDir |**Read-only.** Logfiles from the daemon. Usually set to `/var/log/icinga2`. +CacheDir |**Read-only.** Cached status information of the daemon. Usually set to `/var/cache/icinga2`. +SpoolDir |**Read-only.** Spool directory for certain data outputs. Usually set to `/var/spool/icinga2`. +InitRunDir |**Read-only.** Directory for PID files and sockets in daemon mode. Usually set to `/run/icinga2`. +ZonesDir |**Read-only.** Contains the path of the zones.d directory. Defaults to `ConfigDir + "/zones.d"`. + +Global configuration: + +Constant | Description --------------------|------------------- -PrefixDir |**Read-only.** Contains the installation prefix that was specified with cmake -DCMAKE_INSTALL_PREFIX. Defaults to "/usr/local". -SysconfDir |**Read-only.** Contains the path of the sysconf directory. Defaults to PrefixDir + "/etc". -ZonesDir |**Read-only.** Contains the path of the zones.d directory. Defaults to SysconfDir + "/zones.d". -LocalStateDir |**Read-only.** Contains the path of the local state directory. Defaults to PrefixDir + "/var". -RunDir |**Read-only.** Contains the path of the run directory. Defaults to LocalStateDir + "/run". -PkgDataDir |**Read-only.** Contains the path of the package data directory. Defaults to PrefixDir + "/share/icinga2". -StatePath |**Read-write.** Contains the path of the Icinga 2 state file. Defaults to LocalStateDir + "/lib/icinga2/icinga2.state". -ObjectsPath |**Read-write.** Contains the path of the Icinga 2 objects file. Defaults to LocalStateDir + "/cache/icinga2/icinga2.debug". -PidPath |**Read-write.** Contains the path of the Icinga 2 PID file. Defaults to RunDir + "/icinga2/icinga2.pid". Vars |**Read-write.** Contains a dictionary with global custom attributes. Not set by default. NodeName |**Read-write.** Contains the cluster node name. Set to the local hostname by default. RunAsUser |**Read-write.** Defines the user the Icinga 2 daemon is running as. Set in the Icinga 2 sysconfig. RunAsGroup |**Read-write.** Defines the group the Icinga 2 daemon is running as. Set in the Icinga 2 sysconfig. -PlatformName |**Read-only.** The name of the operating system, e.g. "Ubuntu". -PlatformVersion |**Read-only.** The version of the operating system, e.g. "14.04.3 LTS". -PlatformKernel |**Read-only.** The name of the operating system kernel, e.g. "Linux". -PlatformKernelVersion|**Read-only.** The version of the operating system kernel, e.g. "3.13.0-63-generic". -BuildCompilerName |**Read-only.** The name of the compiler Icinga was built with, e.g. "Clang". -BuildCompilerVersion|**Read-only.** The version of the compiler Icinga was built with, e.g. "7.3.0.7030031". -BuildHostName |**Read-only.** The name of the host Icinga was built on, e.g. "acheron". -ApplicationVersion |**Read-only.** The application version, e.g. "2.9.0". -MaxConcurrentChecks |**Read-write**. The number of max checks run simultaneously. Defaults to 512. -Environment |**Read-write**. The name of the Icinga environment. Included in the SNI host name when making outbound connections. Defaults to "production". +MaxConcurrentChecks |**Read-write**. The number of max checks run simultaneously. Defaults to `512`. +Environment |**Read-write**. The name of the Icinga environment. Included in the SNI host name when making outbound connections. Defaults to `production`. + +Application runtime details: + +Constant | Description +--------------------|------------------- +PlatformName |**Read-only.** The name of the operating system, e.g. `Ubuntu`. +PlatformVersion |**Read-only.** The version of the operating system, e.g. `14.04.3 LTS`. +PlatformKernel |**Read-only.** The name of the operating system kernel, e.g. `Linux`. +PlatformKernelVersion|**Read-only.** The version of the operating system kernel, e.g. `3.13.0-63-generic`. +BuildCompilerName |**Read-only.** The name of the compiler Icinga was built with, e.g. `Clang`. +BuildCompilerVersion|**Read-only.** The version of the compiler Icinga was built with, e.g. `7.3.0.7030031`. +BuildHostName |**Read-only.** The name of the host Icinga was built on, e.g. `acheron`. +ApplicationVersion |**Read-only.** The application version, e.g. `2.9.0`. + +Writable constants can be specified on the CLI using the `--define/-D` parameter. + +> **Note for v2.10+** +> +> Default paths which include `/etc` and `/var` as base directory continue to work +> based on the `SysconfDir` and `LocalStateDir` constants respectively. + +In addition to that, the constants below are used to define specific file paths. You should never need +to change them, as they are pre-compiled based on the constants above. + +Variable |Description +--------------------|------------------- +StatePath |**Read-write.** Contains the path of the Icinga 2 state file. Defaults to `DataDir + "/icinga2.state"`. +ObjectsPath |**Read-write.** Contains the path of the Icinga 2 objects file. Defaults to `CacheDir + "/icinga2.debug"`. +PidPath |**Read-write.** Contains the path of the Icinga 2 PID file. Defaults to `InitRunDir + "/icinga2.pid"`. +PkgDataDir |**Read-only.** Contains the path of the package data directory. Defaults to `PrefixDir + "/share/icinga2"`. + +The constants below have been used until Icinga v2.10, and are still intact. You don't need them +for future builds and configuration based on the newly available constants above. + +Variable |Description +--------------------|------------------- +PrefixDir |**Read-only.** Contains the installation prefix that was specified with `cmake -DCMAKE_INSTALL_PREFIX`. `Defaults to "/usr/local"`. +SysconfDir |**Read-only.** Contains the path of the sysconf directory. Defaults to `PrefixDir + "/etc"`. +LocalStateDir |**Read-only.** Contains the path of the local state directory. Defaults to `PrefixDir + "/var"`. +RunDir |**Read-only.** Contains the path of the run directory. Defaults to `LocalStateDir + "/run"`. Advanced runtime constants. Please only use them if advised by support or developers. @@ -733,12 +771,12 @@ You can explicitly access the `this` scope using the `this` keyword: object Host "localhost" { var check_interval = 5m - + /* This explicitly specifies that the attribute should be set * for the host, if we had omitted `this.` the (poorly named) * local variable `check_interval` would have been modified instead. */ - this.check_interval = 1m + this.check_interval = 1m } Similarly the keywords `locals` and `globals` are available to access the local and global scope. @@ -748,7 +786,7 @@ a function is set to whichever object was used to invoke the function. Here's an hm = { h_word = null - + function init(word) { h_word = word } @@ -1024,4 +1062,3 @@ You can escape the `include` keyword by prefixing it with an additional `@` char vars.@include = "some cmdb export field" } - diff --git a/doc/icinga2.8 b/doc/icinga2.8 index 81fd9dba8..f9ea45bb7 100644 --- a/doc/icinga2.8 +++ b/doc/icinga2.8 @@ -69,9 +69,9 @@ Config files are processed in the order they are specified on the command-line. When no configuration file is specified and the .B --no-config is not used, Icinga 2 automatically falls back to using the configuration file -.B SysconfDir + "/icinga2/icinga2.conf" -(where SysconfDir is usually -.BI "/etc" ")." +.B ConfigDir + "/icinga2.conf" +(where ConfigDir is usually +.BI "/etc/icinga2" ")." .TP .B "-z, --noconfig" diff --git a/etc/CMakeLists.txt b/etc/CMakeLists.txt index bffca3016..4c967cc43 100644 --- a/etc/CMakeLists.txt +++ b/etc/CMakeLists.txt @@ -24,55 +24,52 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") endif() if(NOT WIN32) - install_if_not_exists(${CMAKE_CURRENT_BINARY_DIR}/icinga2/constants.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2) - install_if_not_exists(icinga2/icinga2.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2) + install_if_not_exists(${CMAKE_CURRENT_BINARY_DIR}/icinga2/constants.conf ${ICINGA2_CONFIGDIR}) + install_if_not_exists(icinga2/icinga2.conf ${ICINGA2_CONFIGDIR}) else() - install_if_not_exists(${CMAKE_CURRENT_SOURCE_DIR}/icinga2/win32/constants.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2) - install_if_not_exists(icinga2/win32/icinga2.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2) + install_if_not_exists(${CMAKE_CURRENT_SOURCE_DIR}/icinga2/win32/constants.conf ${ICINGA2_CONFIGDIR}) + install_if_not_exists(icinga2/win32/icinga2.conf ${ICINGA2_CONFIGDIR}) endif() -install_if_not_exists(icinga2/zones.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2) -install_if_not_exists(icinga2/conf.d/app.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d) -install_if_not_exists(icinga2/conf.d/commands.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d) -install_if_not_exists(icinga2/conf.d/downtimes.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d) -install_if_not_exists(icinga2/conf.d/groups.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d) +install_if_not_exists(icinga2/zones.conf ${ICINGA2_CONFIGDIR}) +install_if_not_exists(icinga2/conf.d/app.conf ${ICINGA2_CONFIGDIR}/conf.d) +install_if_not_exists(icinga2/conf.d/commands.conf ${ICINGA2_CONFIGDIR}/conf.d) +install_if_not_exists(icinga2/conf.d/downtimes.conf ${ICINGA2_CONFIGDIR}/conf.d) +install_if_not_exists(icinga2/conf.d/groups.conf ${ICINGA2_CONFIGDIR}/conf.d) if(NOT WIN32) - install_if_not_exists(icinga2/conf.d/hosts.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d) - install_if_not_exists(icinga2/conf.d/services.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d) + install_if_not_exists(icinga2/conf.d/hosts.conf ${ICINGA2_CONFIGDIR}/conf.d) + install_if_not_exists(icinga2/conf.d/services.conf ${ICINGA2_CONFIGDIR}/conf.d) else() - install_if_not_exists(icinga2/conf.d/win32/hosts.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d) - install_if_not_exists(icinga2/conf.d/win32/services.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d) + install_if_not_exists(icinga2/conf.d/win32/hosts.conf ${ICINGA2_CONFIGDIR}/conf.d) + install_if_not_exists(icinga2/conf.d/win32/services.conf ${ICINGA2_CONFIGDIR}/conf.d) endif() -install_if_not_exists(icinga2/conf.d/notifications.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d) -install_if_not_exists(icinga2/conf.d/templates.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d) -install_if_not_exists(icinga2/conf.d/timeperiods.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d) -install_if_not_exists(icinga2/conf.d/users.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d) -install_if_not_exists(icinga2/features-available/api.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/features-available) -install_if_not_exists(icinga2/features-available/debuglog.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/features-available) -install_if_not_exists(icinga2/features-available/mainlog.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/features-available) +install_if_not_exists(icinga2/conf.d/notifications.conf ${ICINGA2_CONFIGDIR}/conf.d) +install_if_not_exists(icinga2/conf.d/templates.conf ${ICINGA2_CONFIGDIR}/conf.d) +install_if_not_exists(icinga2/conf.d/timeperiods.conf ${ICINGA2_CONFIGDIR}/conf.d) +install_if_not_exists(icinga2/conf.d/users.conf ${ICINGA2_CONFIGDIR}/conf.d) +install_if_not_exists(icinga2/features-available/api.conf ${ICINGA2_CONFIGDIR}/features-available) +install_if_not_exists(icinga2/features-available/debuglog.conf ${ICINGA2_CONFIGDIR}/features-available) +install_if_not_exists(icinga2/features-available/mainlog.conf ${ICINGA2_CONFIGDIR}/features-available) if(NOT WIN32) - install_if_not_exists(icinga2/features-available/syslog.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/features-available) + install_if_not_exists(icinga2/features-available/syslog.conf ${ICINGA2_CONFIGDIR}/features-available) endif() -install_if_not_exists(icinga2/scripts/mail-host-notification.sh ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/scripts) -install_if_not_exists(icinga2/scripts/mail-service-notification.sh ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/scripts) -install_if_not_exists(icinga2/zones.d/README ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/zones.d) +install_if_not_exists(icinga2/scripts/mail-host-notification.sh ${ICINGA2_CONFIGDIR}/scripts) +install_if_not_exists(icinga2/scripts/mail-service-notification.sh ${ICINGA2_CONFIGDIR}/scripts) +install_if_not_exists(icinga2/zones.d/README ${ICINGA2_CONFIGDIR}/zones.d) if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") - install_if_not_exists(${CMAKE_CURRENT_BINARY_DIR}/logrotate.d/icinga2 ${CMAKE_INSTALL_SYSCONFDIR}/logrotate.d) + install_if_not_exists(${CMAKE_CURRENT_BINARY_DIR}/logrotate.d/icinga2 ${LOGROTATE_DIR}) endif() if(NOT WIN32) - install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_SYSCONFDIR}/icinga2/features-enabled\")") - install(CODE "execute_process(COMMAND \"${CMAKE_COMMAND}\" -E create_symlink ../features-available/mainlog.conf \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_SYSCONFDIR}/icinga2/features-enabled/mainlog.conf\")") + install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_CONFIGDIR}/features-enabled\")") + install(CODE "execute_process(COMMAND \"${CMAKE_COMMAND}\" -E create_symlink ../features-available/mainlog.conf \"\$ENV{DESTDIR}${ICINGA2_FULL_CONFIGDIR}/features-enabled/mainlog.conf\")") - install( - FILES bash_completion.d/icinga2 - DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/bash_completion.d - ) + install(FILES bash_completion.d/icinga2 DESTINATION ${BASHCOMPLETION_DIR}) else() - install_if_not_exists(icinga2/features-enabled/mainlog.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/features-enabled) + install_if_not_exists(icinga2/features-enabled/mainlog.conf ${ICINGA2_CONFIGDIR}/features-enabled) endif() if(${CMAKE_SYSTEM_NAME} MATCHES "(Linux|Solaris|SunOS)") diff --git a/etc/icinga2/conf.d/commands.conf b/etc/icinga2/conf.d/commands.conf index 9c5153811..bd511cebc 100644 --- a/etc/icinga2/conf.d/commands.conf +++ b/etc/icinga2/conf.d/commands.conf @@ -7,7 +7,7 @@ */ object NotificationCommand "mail-host-notification" { - command = [ SysconfDir + "/icinga2/scripts/mail-host-notification.sh" ] + command = [ ConfigDir + "/scripts/mail-host-notification.sh" ] arguments += { "-4" = "$notification_address$" @@ -66,7 +66,7 @@ object NotificationCommand "mail-host-notification" { } object NotificationCommand "mail-service-notification" { - command = [ SysconfDir + "/icinga2/scripts/mail-service-notification.sh" ] + command = [ ConfigDir + "/scripts/mail-service-notification.sh" ] arguments += { "-4" = "$notification_address$" @@ -146,7 +146,7 @@ object NotificationCommand "mail-service-notification" { /* object NotificationCommand "mail-host-notification" { - command = [ SysconfDir + "/icinga2/scripts/mail-host-notification.sh" ] + command = [ ConfigDir + "/scripts/mail-host-notification.sh" ] env = { NOTIFICATIONTYPE = "$notification.type$" @@ -164,7 +164,7 @@ object NotificationCommand "mail-host-notification" { } object NotificationCommand "mail-service-notification" { - command = [ SysconfDir + "/icinga2/scripts/mail-service-notification.sh" ] + command = [ ConfigDir + "/scripts/mail-service-notification.sh" ] env = { NOTIFICATIONTYPE = "$notification.type$" diff --git a/etc/icinga2/features-available/debuglog.conf b/etc/icinga2/features-available/debuglog.conf index 6e8e5813e..e66518fe1 100644 --- a/etc/icinga2/features-available/debuglog.conf +++ b/etc/icinga2/features-available/debuglog.conf @@ -6,6 +6,5 @@ object FileLogger "debug-file" { severity = "debug" - path = LocalStateDir + "/log/icinga2/debug.log" + path = LogDir + "/debug.log" } - diff --git a/etc/icinga2/features-available/mainlog.conf b/etc/icinga2/features-available/mainlog.conf index ded9a7c7d..a3bb19dab 100644 --- a/etc/icinga2/features-available/mainlog.conf +++ b/etc/icinga2/features-available/mainlog.conf @@ -4,6 +4,5 @@ object FileLogger "main-log" { severity = "information" - path = LocalStateDir + "/log/icinga2/icinga2.log" + path = LogDir + "/icinga2.log" } - diff --git a/etc/initsystem/icinga2.init.d.cmake b/etc/initsystem/icinga2.init.d.cmake index f0698726f..ef3f521f2 100644 --- a/etc/initsystem/icinga2.init.d.cmake +++ b/etc/initsystem/icinga2.init.d.cmake @@ -36,10 +36,10 @@ fi : ${ICINGA2_GROUP:="@ICINGA2_GROUP@"} : ${ICINGA2_COMMAND_GROUP:="@ICINGA2_COMMAND_GROUP@"} : ${DAEMON:="@CMAKE_INSTALL_FULL_SBINDIR@/icinga2"} -: ${ICINGA2_CONFIG_FILE:="@CMAKE_INSTALL_FULL_SYSCONFDIR@/icinga2/icinga2.conf"} -: ${ICINGA2_ERROR_LOG:=@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/log/icinga2/error.log} -: ${ICINGA2_STARTUP_LOG:=@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/log/icinga2/startup.log} -: ${ICINGA2_PID_FILE:="@ICINGA2_RUNDIR@/icinga2/icinga2.pid"} +: ${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 @@ -90,7 +90,7 @@ stop() { if ! icinga2 internal signal -s SIGCHLD -p $pid >/dev/null 2>&1; then break fi - + printf '.' sleep 3 done diff --git a/etc/initsystem/icinga2.service.cmake b/etc/initsystem/icinga2.service.cmake index 771c98f7b..94b7dcd2f 100644 --- a/etc/initsystem/icinga2.service.cmake +++ b/etc/initsystem/icinga2.service.cmake @@ -7,7 +7,7 @@ Type=notify EnvironmentFile=@ICINGA2_SYSCONFIGFILE@ ExecStartPre=@CMAKE_INSTALL_PREFIX@/lib/icinga2/prepare-dirs @ICINGA2_SYSCONFIGFILE@ ExecStart=@CMAKE_INSTALL_FULL_SBINDIR@/icinga2 daemon -e ${ICINGA2_ERROR_LOG} -PIDFile=@ICINGA2_RUNDIR@/icinga2/icinga2.pid +PIDFile=@ICINGA2_INITRUNDIR@/icinga2.pid ExecReload=@CMAKE_INSTALL_PREFIX@/lib/icinga2/safe-reload @ICINGA2_SYSCONFIGFILE@ TimeoutStartSec=30m diff --git a/etc/initsystem/icinga2.sysconfig.cmake b/etc/initsystem/icinga2.sysconfig.cmake index d5d7497f1..167c12578 100644 --- a/etc/initsystem/icinga2.sysconfig.cmake +++ b/etc/initsystem/icinga2.sysconfig.cmake @@ -2,15 +2,14 @@ #Make your changes here. #DAEMON=@CMAKE_INSTALL_FULL_SBINDIR@/icinga2 -#ICINGA2_CONFIG_FILE=@CMAKE_INSTALL_FULL_SYSCONFDIR@/icinga2/icinga2.conf -#ICINGA2_RUN_DIR=@ICINGA2_RUNDIR@ -#ICINGA2_STATE_DIR=@CMAKE_INSTALL_FULL_LOCALSTATEDIR@ -#ICINGA2_PID_FILE=@ICINGA2_RUNDIR@/icinga2/icinga2.pid -#ICINGA2_LOG_DIR=@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/log/icinga2 -#ICINGA2_ERROR_LOG=@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/log/icinga2/error.log -#ICINGA2_STARTUP_LOG=@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/log/icinga2/startup.log -#ICINGA2_LOG=@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/log/icinga2/icinga2.log -#ICINGA2_CACHE_DIR=@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/cache/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 index ce155424d..c0d96bdac 100644 --- a/etc/initsystem/prepare-dirs.cmake +++ b/etc/initsystem/prepare-dirs.cmake @@ -17,28 +17,27 @@ fi : ${ICINGA2_USER:="@ICINGA2_USER@"} : ${ICINGA2_GROUP:="@ICINGA2_GROUP@"} : ${ICINGA2_COMMAND_GROUP:="@ICINGA2_COMMAND_GROUP@"} -: ${ICINGA2_RUN_DIR:="@ICINGA2_RUNDIR@"} -: ${ICINGA2_LOG_DIR:="@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/log/icinga2"} -: ${ICINGA2_STATE_DIR:="@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/cache/icinga2"} -: ${ICINGA2_CACHE_DIR:="@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/cache/icinga2"} +: ${ICINGA2_INIT_RUN_DIR:="@ICINGA2_INITRUNDIR@"} +: ${ICINGA2_LOG_DIR:="@ICINGA2_LOGDIR@"} +: ${ICINGA2_CACHE_DIR:="@ICINGA2_CACHEDIR@"} getent passwd $ICINGA2_USER >/dev/null 2>&1 || (echo "Icinga user '$ICINGA2_USER' does not exist. Exiting." && exit 6) getent group $ICINGA2_GROUP >/dev/null 2>&1 || (echo "Icinga group '$ICINGA2_GROUP' does not exist. Exiting." && exit 6) getent group $ICINGA2_COMMAND_GROUP >/dev/null 2>&1 || (echo "Icinga command group '$ICINGA2_COMMAND_GROUP' does not exist. Exiting." && exit 6) -if [ ! -e "$ICINGA2_RUN_DIR"/icinga2 ]; then - mkdir "$ICINGA2_RUN_DIR"/icinga2 - mkdir "$ICINGA2_RUN_DIR"/icinga2/cmd +if [ ! -e "$ICINGA2_INIT_RUN_DIR" ]; then + mkdir "$ICINGA2_INIT_RUN_DIR" + mkdir "$ICINGA2_INIT_RUN_DIR"/cmd fi -chmod 755 "$ICINGA2_RUN_DIR"/icinga2 -chmod 2750 "$ICINGA2_RUN_DIR"/icinga2/cmd -chown -R $ICINGA2_USER:$ICINGA2_COMMAND_GROUP "$ICINGA2_RUN_DIR"/icinga2 +chmod 755 "$ICINGA2_INIT_RUN_DIR" +chmod 2750 "$ICINGA2_INIT_RUN_DIR"/cmd +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_RUN_DIR"/icinga2/ + 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 index c42994a30..a71ae9db5 100644 --- a/etc/initsystem/safe-reload.cmake +++ b/etc/initsystem/safe-reload.cmake @@ -11,7 +11,7 @@ fi # Set defaults, to overwrite see "@ICINGA2_SYSCONFIGFILE@" -: ${ICINGA2_PID_FILE:="@ICINGA2_RUNDIR@/icinga2/icinga2.pid"} +: ${ICINGA2_PID_FILE:="@ICINGA2_INITRUNDIR@/icinga2.pid"} : ${DAEMON:="@CMAKE_INSTALL_FULL_SBINDIR@/icinga2"} printf "Validating config files: " diff --git a/etc/logrotate.d/icinga2.cmake b/etc/logrotate.d/icinga2.cmake index 91d8d23d3..3863f913d 100644 --- a/etc/logrotate.d/icinga2.cmake +++ b/etc/logrotate.d/icinga2.cmake @@ -1,4 +1,4 @@ -@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/log/icinga2/icinga2.log @CMAKE_INSTALL_FULL_LOCALSTATEDIR@/log/icinga2/debug.log { +@ICINGA2_LOGDIR@/icinga2.log @ICINGA2_LOGDIR@/debug.log { daily rotate 7@LOGROTATE_USE_SU@ compress @@ -7,11 +7,11 @@ notifempty create 644 @ICINGA2_USER@ @ICINGA2_GROUP@ postrotate - /bin/kill -USR1 $(cat @ICINGA2_RUNDIR@/icinga2/icinga2.pid 2> /dev/null) 2> /dev/null || true + /bin/kill -USR1 $(cat @ICINGA2_INITRUNDIR@/icinga2.pid 2> /dev/null) 2> /dev/null || true endscript } -@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/log/icinga2/error.log { +@ICINGA2_LOGDIR@/error.log { daily rotate 90@LOGROTATE_USE_SU@ compress @@ -21,4 +21,3 @@ create 644 @ICINGA2_USER@ @ICINGA2_GROUP@ # TODO: figure out how to get Icinga to re-open this log file } - diff --git a/icinga-app/CMakeLists.txt b/icinga-app/CMakeLists.txt index 0d1293279..49286776d 100644 --- a/icinga-app/CMakeLists.txt +++ b/icinga-app/CMakeLists.txt @@ -107,6 +107,6 @@ install( RUNTIME DESTINATION ${InstallPath} ) -install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/icinga2\")") -install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/icinga2\")") -install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_RUNDIR}/icinga2\")") +install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_LOGDIR}\")") +install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_DATADIR}\")") +install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_INITRUNDIR}\")") diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index 404cedf30..3849ca658 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -94,6 +94,70 @@ static std::vector GlobalArgumentCompletion(const String& argument, cons return std::vector(); } +static void HandleLegacyDefines() +{ +#ifdef _WIN32 + String dataPrefix = Utility::GetIcingaDataPath(); +#endif /* _WIN32 */ + + Value localStateDir = Application::GetConst("LocalStateDir"); + + if (!localStateDir.IsEmpty()) { + Log(LogWarning, "icinga-app") + << "Please do not set the deprecated 'LocalStateDir' constant," + << " use the 'DataDir', 'LogDir', 'CacheDir' and 'SpoolDir' constants instead!" + << " For compatibility reasons, these are now set based on the 'LocalStateDir' constant."; + +#ifdef _WIN32 + ScriptGlobal::Set("DataDir", localStateDir + "\\lib\\icinga2"); + ScriptGlobal::Set("LogDir", localStateDir + "\\log\\icinga2"); + ScriptGlobal::Set("CacheDir", localStateDir + "\\cache\\icinga2"); + ScriptGlobal::Set("SpoolDir", localStateDir + "\\spool\\icinga2"); + } else { + ScriptGlobal::Set("LocalStateDir", dataPrefix + "\\var"); +#else /* _WIN32 */ + ScriptGlobal::Set("DataDir", localStateDir + "/lib/icinga2"); + ScriptGlobal::Set("LogDir", localStateDir + "/log/icinga2"); + ScriptGlobal::Set("CacheDir", localStateDir + "/cache/icinga2"); + ScriptGlobal::Set("SpoolDir", localStateDir + "/spool/icinga2"); + } else { + ScriptGlobal::Set("LocalStateDir", ICINGA_LOCALSTATEDIR); +#endif /* _WIN32 */ + } + + Value sysconfDir = Application::GetConst("SysconfDir"); + if (!sysconfDir.IsEmpty()) { + Log(LogWarning, "icinga-app") + << "Please do not set the deprecated 'Sysconfdir' constant, use the 'ConfigDir' constant instead! For compatibility reasons, their value is set based on the 'SysconfDir' constant."; + +#ifdef _WIN32 + ScriptGlobal::Set("ConfigDir", sysconfDir + "\\icinga2"); + } else { + ScriptGlobal::Set("SysconfDir", dataPrefix + "\\etc"); +#else /* _WIN32 */ + ScriptGlobal::Set("ConfigDir", sysconfDir + "/icinga2"); + } else { + ScriptGlobal::Set("SysconfDir", ICINGA_SYSCONFDIR); +#endif /* _WIN32 */ + } + + Value runDir = Application::GetConst("RunDir"); + if (!runDir.IsEmpty()) { + Log(LogWarning, "icinga-app") + << "Please do not set the deprecated 'RunDir' constant, use the 'InitRunDir' constant instead! For compatiblity reasons, their value is set based on the 'RunDir' constant."; + +#ifdef _WIN32 + ScriptGlobal::Set("InitRunDir", runDir + "\\icinga2"); + } else { + ScriptGlobal::Set("RunDir", dataPrefix + "\\var\\run"); +#else /* _WIN32 */ + ScriptGlobal::Set("InitRunDir", runDir + "/icinga2"); + } else { + ScriptGlobal::Set("RunDir", ICINGA_RUNDIR); +#endif /* _WIN32 */ + } +} + static int Main() { int argc = Application::GetArgC(); @@ -128,31 +192,49 @@ static int Main() #ifdef _WIN32 bool builtinPaths = true; + /* Programm install location, C:/Program Files/Icinga2 */ String binaryPrefix = Utility::GetIcingaInstallPath(); + /* Returns the datapath for daemons, %PROGRAMDATA%/icinga2 */ String dataPrefix = Utility::GetIcingaDataPath(); if (!binaryPrefix.IsEmpty() && !dataPrefix.IsEmpty()) { - Application::DeclarePrefixDir(binaryPrefix); - Application::DeclareSysconfDir(dataPrefix + "\\etc"); - Application::DeclareRunDir(dataPrefix + "\\var\\run"); - Application::DeclareLocalStateDir(dataPrefix + "\\var"); - Application::DeclarePkgDataDir(binaryPrefix + "\\share\\icinga2"); - Application::DeclareIncludeConfDir(binaryPrefix + "\\share\\icinga2\\include"); + Application::DeclareConst("PrefixDir", binaryPrefix); + Application::DeclareConst("ProgramData", dataPrefix); + + Application::DeclareConst("ConfigDir", dataPrefix + "\\etc\\icinga2"); + + Application::DeclareConst("DataDir", dataPrefix + "\\var\\lib\\icinga2"); + Application::DeclareConst("LogDir", dataPrefix + "\\var\\log\\icinga2"); + Application::DeclareConst("CacheDir", dataPrefix + "\\var\\cache\\icinga2"); + Application::DeclareConst("SpoolDir", dataPrefix + "\\var\\spool\\icinga2"); + + /* Internal constants. */ + Application::DeclareConst("PkgDataDir", binaryPrefix + "\\share\\icinga2"); + Application::DeclareConst("IncludeConfDir", binaryPrefix + "\\share\\icinga2\\include"); } else { Log(LogWarning, "icinga-app", "Registry key could not be read. Falling back to built-in paths."); #endif /* _WIN32 */ - Application::DeclarePrefixDir(ICINGA_PREFIX); - Application::DeclareSysconfDir(ICINGA_SYSCONFDIR); - Application::DeclareRunDir(ICINGA_RUNDIR); - Application::DeclareLocalStateDir(ICINGA_LOCALSTATEDIR); - Application::DeclarePkgDataDir(ICINGA_PKGDATADIR); - Application::DeclareIncludeConfDir(ICINGA_INCLUDECONFDIR); + Application::DeclareConst("ConfigDir", ICINGA_CONFIGDIR); + + Application::DeclareConst("DataDir", ICINGA_DATADIR); + Application::DeclareConst("LogDir", ICINGA_LOGDIR); + Application::DeclareConst("CacheDir", ICINGA_CACHEDIR); + Application::DeclareConst("SpoolDir", ICINGA_SPOOLDIR); + + Application::DeclareConst("PrefixDir", ICINGA_PREFIX); + + /* Internal constants. */ + Application::DeclareConst("PkgDataDir", ICINGA_PKGDATADIR); + Application::DeclareConst("IncludeConfDir", ICINGA_INCLUDECONFDIR); + + Application::DeclareConst("InitRunDir", ICINGA_INITRUNDIR); + #ifdef _WIN32 } #endif /* _WIN32 */ - Application::DeclareZonesDir(Application::GetSysconfDir() + "/icinga2/zones.d"); + Application::DeclareConst("ZonesDir", Application::GetConst("ConfigDir") + "/zones.d"); String icingaUser = Utility::GetFromEnvironment("ICINGA2_USER"); if (icingaUser.IsEmpty()) @@ -162,17 +244,17 @@ static int Main() if (icingaGroup.IsEmpty()) icingaGroup = ICINGA_GROUP; - Application::DeclareRunAsUser(icingaUser); - Application::DeclareRunAsGroup(icingaGroup); + Application::DeclareConst("RunAsUser", icingaUser); + Application::DeclareConst("RunAsGroup", icingaGroup); if (!autocomplete) { #ifdef RLIMIT_NOFILE String rLimitFiles = Utility::GetFromEnvironment("ICINGA2_RLIMIT_FILES"); if (rLimitFiles.IsEmpty()) - Application::DeclareRLimitFiles(Application::GetDefaultRLimitFiles()); + Application::DeclareConst("RLimitFiles", Application::GetDefaultRLimitFiles()); else { try { - Application::DeclareRLimitFiles(Convert::ToLong(rLimitFiles)); + Application::DeclareConst("RLimitFiles", Convert::ToLong(rLimitFiles)); } catch (const std::invalid_argument& ex) { std::cout << "Error setting \"ICINGA2_RLIMIT_FILES\": " << ex.what() << '\n'; @@ -184,10 +266,10 @@ static int Main() #ifdef RLIMIT_NPROC String rLimitProcesses = Utility::GetFromEnvironment("ICINGA2_RLIMIT_PROCESSES"); if (rLimitProcesses.IsEmpty()) - Application::DeclareRLimitProcesses(Application::GetDefaultRLimitProcesses()); + Application::DeclareConst("RLimitProcesses", Application::GetDefaultRLimitProcesses()); else { try { - Application::DeclareRLimitProcesses(Convert::ToLong(rLimitProcesses)); + Application::DeclareConst("RLimitProcesses", Convert::ToLong(rLimitProcesses)); } catch (const std::invalid_argument& ex) { std::cout << "Error setting \"ICINGA2_RLIMIT_PROCESSES\": " << ex.what() << '\n'; @@ -199,10 +281,10 @@ static int Main() #ifdef RLIMIT_STACK String rLimitStack = Utility::GetFromEnvironment("ICINGA2_RLIMIT_STACK"); if (rLimitStack.IsEmpty()) - Application::DeclareRLimitStack(Application::GetDefaultRLimitStack()); + Application::DeclareConst("RLimitStack", Application::GetDefaultRLimitStack()); else { try { - Application::DeclareRLimitStack(Convert::ToLong(rLimitStack)); + Application::DeclareConst("RLimitStack", Convert::ToLong(rLimitStack)); } catch (const std::invalid_argument& ex) { std::cout << "Error setting \"ICINGA2_RLIMIT_STACK\": " << ex.what() << '\n'; @@ -212,8 +294,8 @@ static int Main() #endif /* RLIMIT_STACK */ } - Application::DeclareConcurrency(std::thread::hardware_concurrency()); - Application::DeclareMaxConcurrentChecks(Application::GetDefaultMaxConcurrentChecks()); + Application::DeclareConst("Concurrency", std::thread::hardware_concurrency()); + Application::DeclareConst("MaxConcurrentChecks", Application::GetDefaultMaxConcurrentChecks()); ScriptGlobal::Set("Environment", "production"); @@ -277,7 +359,10 @@ static int Main() GetUserName(username, &usernameLen); std::ifstream userFile; - userFile.open(Application::GetSysconfDir() + "/icinga2/user"); + + /* The implicit string assignment is needed for Windows builds. */ + String configDir = Application::GetConst("ConfigDir"); + userFile.open(configDir + "/user"); if (userFile && command && !Application::IsProcessElevated()) { std::string userLine; @@ -361,16 +446,19 @@ static int Main() } } + /* Ensure that all defined constants work in the way we expect them. */ + HandleLegacyDefines(); + if (vm.count("script-debugger")) Application::SetScriptDebuggerEnabled(true); - Application::DeclareStatePath(Application::GetLocalStateDir() + "/lib/icinga2/icinga2.state"); - Application::DeclareModAttrPath(Application::GetLocalStateDir() + "/lib/icinga2/modified-attributes.conf"); - Application::DeclareObjectsPath(Application::GetLocalStateDir() + "/cache/icinga2/icinga2.debug"); - Application::DeclareVarsPath(Application::GetLocalStateDir() + "/cache/icinga2/icinga2.vars"); - Application::DeclarePidPath(Application::GetRunDir() + "/icinga2/icinga2.pid"); + Application::DeclareConst("StatePath", Application::GetConst("DataDir") + "/icinga2.state"); + Application::DeclareConst("ModAttrPath", Application::GetConst("DataDir") + "/modified-attributes.conf"); + Application::DeclareConst("ObjectsPath", Application::GetConst("CacheDir") + "/icinga2.debug"); + Application::DeclareConst("VarsPath", Application::GetConst("CacheDir") + "/icinga2.vars"); + Application::DeclareConst("PidPath", Application::GetConst("InitRunDir") + "/icinga2.pid"); - ConfigCompiler::AddIncludeSearchDir(Application::GetIncludeConfDir()); + ConfigCompiler::AddIncludeSearchDir(Application::GetConst("IncludeConfDir")); if (!autocomplete && vm.count("include")) { for (const String& includePath : vm["include"].as >()) { @@ -480,8 +568,8 @@ static int Main() return 0; } } else if (command && command->GetImpersonationLevel() == ImpersonateIcinga) { - String group = Application::GetRunAsGroup(); - String user = Application::GetRunAsUser(); + String group = Application::GetConst("RunAsGroup"); + String user = Application::GetConst("RunAsUser"); errno = 0; struct group *gr = getgrnam(group.CStr()); diff --git a/itl/CMakeLists.txt b/itl/CMakeLists.txt index 75b2e7289..6d70ad9f1 100644 --- a/itl/CMakeLists.txt +++ b/itl/CMakeLists.txt @@ -19,5 +19,5 @@ add_subdirectory(plugins-contrib.d) install( FILES itl command-icinga.conf hangman plugins command-plugins.conf manubulon command-plugins-manubulon.conf windows-plugins command-plugins-windows.conf nscp command-nscp-local.conf plugins-contrib - DESTINATION ${CMAKE_INSTALL_DATADIR}/icinga2/include + DESTINATION ${ICINGA2_INCLUDEDIR} ) diff --git a/itl/plugins-contrib.d/CMakeLists.txt b/itl/plugins-contrib.d/CMakeLists.txt index 099ea2485..5d60a1b70 100644 --- a/itl/plugins-contrib.d/CMakeLists.txt +++ b/itl/plugins-contrib.d/CMakeLists.txt @@ -17,5 +17,5 @@ install( FILES databases.conf hardware.conf icingacli.conf ipmi.conf logmanagement.conf metrics.conf network-components.conf network-services.conf operating-system.conf raid-controller.conf smart-attributes.conf storage.conf virtualization.conf vmware.conf web.conf - DESTINATION ${CMAKE_INSTALL_DATADIR}/icinga2/include/plugins-contrib.d + DESTINATION ${ICINGA2_INCLUDEDIR}/plugins-contrib.d ) diff --git a/itl/plugins-contrib.d/databases.conf b/itl/plugins-contrib.d/databases.conf index e1fbbfc9d..23397ba49 100644 --- a/itl/plugins-contrib.d/databases.conf +++ b/itl/plugins-contrib.d/databases.conf @@ -519,7 +519,7 @@ object CheckCommand "oracle_health" { vars.oracle_home = "/usr/lib/oracle/11.2/client64/lib" vars.oracle_ld_library_path = "/usr/lib/oracle/11.2/client64/lib" - vars.oracle_tns_admin = SysconfDir + "/icinga2/plugin-configs" + vars.oracle_tns_admin = ConfigDir + "/plugin-configs" } object CheckCommand "postgres" { diff --git a/itl/plugins-contrib.d/smart-attributes.conf b/itl/plugins-contrib.d/smart-attributes.conf index 25e3333dd..e668bd3cc 100644 --- a/itl/plugins-contrib.d/smart-attributes.conf +++ b/itl/plugins-contrib.d/smart-attributes.conf @@ -20,5 +20,5 @@ object CheckCommand "smart-attributes" { } } - vars.smart_attributes_config_path = SysconfDir + "/icinga2/plugins-config/check_smartdb.json" + vars.smart_attributes_config_path = ConfigDir + "/plugins-config/check_smartdb.json" } diff --git a/lib/base/CMakeLists.txt b/lib/base/CMakeLists.txt index d86f676d2..c16cda028 100644 --- a/lib/base/CMakeLists.txt +++ b/lib/base/CMakeLists.txt @@ -122,7 +122,7 @@ set_target_properties ( FOLDER Lib ) -install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/cache/icinga2\")") -install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/icinga2/crash\")") +install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_CACHEDIR}\")") +install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_LOGDIR}/crash\")") set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}" PARENT_SCOPE) diff --git a/lib/base/application.cpp b/lib/base/application.cpp index 4287c7687..bc8ec1bd4 100644 --- a/lib/base/application.cpp +++ b/lib/base/application.cpp @@ -168,7 +168,7 @@ void Application::SetResourceLimits() rlimit rl; # ifdef RLIMIT_NOFILE - rlim_t fileLimit = GetRLimitFiles(); + rlim_t fileLimit = GetConst("RLimitFiles"); if (fileLimit != 0) { if (fileLimit < GetDefaultRLimitFiles()) { @@ -189,7 +189,7 @@ void Application::SetResourceLimits() } # ifdef RLIMIT_NPROC - rlim_t processLimit = GetRLimitProcesses(); + rlim_t processLimit = GetConst("RLimitProcesses"); if (processLimit != 0) { if (processLimit < GetDefaultRLimitProcesses()) { @@ -228,7 +228,7 @@ void Application::SetResourceLimits() rlim_t stackLimit; - stackLimit = GetRLimitStack(); + stackLimit = GetConst("RLimitStack"); if (stackLimit != 0) { if (stackLimit < GetDefaultRLimitStack()) { @@ -538,34 +538,42 @@ String Application::GetExePath(const String& argv0) */ void Application::DisplayInfoMessage(std::ostream& os, bool skipVersion) { - os << "Application information:" << "\n"; - + /* icinga-app prints its own version information, stack traces need it here. */ if (!skipVersion) - os << " Application version: " << GetAppVersion() << "\n"; + os << " Application version: " << GetAppVersion() << "\n\n"; - os << " Installation root: " << GetPrefixDir() << "\n" - << " Sysconf directory: " << GetSysconfDir() << "\n" - << " Run directory: " << GetRunDir() << "\n" - << " Local state directory: " << GetLocalStateDir() << "\n" - << " Package data directory: " << GetPkgDataDir() << "\n" - << " State path: " << GetStatePath() << "\n" - << " Modified attributes path: " << GetModAttrPath() << "\n" - << " Objects path: " << GetObjectsPath() << "\n" - << " Vars path: " << GetVarsPath() << "\n" - << " PID path: " << GetPidPath() << "\n"; - - os << "\n" - << "System information:" << "\n" + os << "System information:\n" << " Platform: " << Utility::GetPlatformName() << "\n" << " Platform version: " << Utility::GetPlatformVersion() << "\n" << " Kernel: " << Utility::GetPlatformKernel() << "\n" << " Kernel version: " << Utility::GetPlatformKernelVersion() << "\n" << " Architecture: " << Utility::GetPlatformArchitecture() << "\n"; - os << "\n" - << "Build information:" << "\n" + os << "\nBuild information:\n" << " Compiler: " << ScriptGlobal::Get("BuildCompilerName") << " " << ScriptGlobal::Get("BuildCompilerVersion") << "\n" << " Build host: " << ScriptGlobal::Get("BuildHostName") << "\n"; + + os << "\nApplication information:\n" + << "\nGeneral paths:\n" + << " Config directory: " << GetConst("ConfigDir") << "\n" + << " Data directory: " << GetConst("DataDir") << "\n" + << " Log directory: " << GetConst("LogDir") << "\n" + << " Cache directory: " << GetConst("CacheDir") << "\n" + << " Spool directory: " << GetConst("SpoolDir") << "\n" + << " Run directory: " << GetConst("InitRunDir") << "\n" + << "\nOld paths (deprecated):\n" + << " Installation root: " << GetConst("PrefixDir") << "\n" + << " Sysconf directory: " << GetConst("SysconfDir") << "\n" + << " Run directory (base): " << GetConst("RunDir") << "\n" + << " Local state directory: " << GetConst("LocalStateDir") << "\n" + << "\nInternal paths:\n" + << " Package data directory: " << GetConst("PkgDataDir") << "\n" + << " State path: " << GetConst("StatePath") << "\n" + << " Modified attributes path: " << GetConst("ModAttrPath") << "\n" + << " Objects path: " << GetConst("ObjectsPath") << "\n" + << " Vars path: " << GetConst("VarsPath") << "\n" + << " PID path: " << GetConst("PidPath") << "\n"; + } /** @@ -582,7 +590,7 @@ void Application::DisplayBugMessage(std::ostream& os) String Application::GetCrashReportFilename() { - return GetLocalStateDir() + "/log/icinga2/crash/report." + Convert::ToString(Utility::GetTime()); + return GetConst("LogDir") + "/crash/report." + Convert::ToString(Utility::GetTime()); } @@ -732,7 +740,7 @@ void Application::SigUsr2Handler(int) */ Application::Ptr instance = GetInstance(); try { - instance->UpdatePidFile(GetPidPath(), m_ReloadProcess); + instance->UpdatePidFile(GetConst("PidPath"), m_ReloadProcess); } catch (const std::exception&) { /* abort restart */ Log(LogCritical, "Application", "Cannot update PID file. Aborting restart operation."); @@ -1004,10 +1012,10 @@ int Application::Run() #endif /* _WIN32 */ try { - UpdatePidFile(GetPidPath()); + UpdatePidFile(GetConst("PidPath")); } catch (const std::exception&) { Log(LogCritical, "Application") - << "Cannot update PID file '" << GetPidPath() << "'. Aborting."; + << "Cannot update PID file '" << GetConst("PidPath") << "'. Aborting."; return EXIT_FAILURE; } @@ -1089,7 +1097,7 @@ void Application::ClosePidFile(bool unlink) if (m_PidFile) { if (unlink) { - String pidpath = GetPidPath(); + String pidpath = GetConst("PidPath"); ::unlink(pidpath.CStr()); } @@ -1157,310 +1165,37 @@ pid_t Application::ReadPidFile(const String& filename) return runningpid; } - /** - * Retrieves the path of the installation prefix. + * Declares a const with ScriptGlobal * - * @returns The path. + * @param name The const name. + * @param value The new value. */ -String Application::GetPrefixDir() +void Application::DeclareConst(const String& name, const Value& value) { - return ScriptGlobal::Get("PrefixDir"); + if (!ScriptGlobal::Exists(name)) + ScriptGlobal::Set(name, value); } /** - * Sets the path for the installation prefix. + * Returns the value of a const from ScriptGlobal * - * @param path The new path. + * @param name The const name. */ -void Application::DeclarePrefixDir(const String& path) +Value Application::GetConst(const String& name) { - if (!ScriptGlobal::Exists("PrefixDir")) - ScriptGlobal::Set("PrefixDir", path); + return GetConst(name, Empty); } /** - * Retrives the path of the sysconf dir. + * Returns the value of a const from ScriptGlobal with default value * - * @returns The path. + * @param name The const name. + * @param def The default value. */ -String Application::GetSysconfDir() +Value Application::GetConst(const String& name, Value defaultValue) { - return ScriptGlobal::Get("SysconfDir"); -} - -/** - * Sets the path of the sysconf dir. - * - * @param path The new path. - */ -void Application::DeclareSysconfDir(const String& path) -{ - if (!ScriptGlobal::Exists("SysconfDir")) - ScriptGlobal::Set("SysconfDir", path); -} - -/** - * Retrieves the path for the run dir. - * - * @returns The path. - */ -String Application::GetRunDir() -{ - return ScriptGlobal::Get("RunDir"); -} - -/** - * Sets the path of the run dir. - * - * @param path The new path. - */ -void Application::DeclareRunDir(const String& path) -{ - if (!ScriptGlobal::Exists("RunDir")) - ScriptGlobal::Set("RunDir", path); -} - -/** - * Retrieves the path for the local state dir. - * - * @returns The path. - */ -String Application::GetLocalStateDir() -{ - return ScriptGlobal::Get("LocalStateDir"); -} - -/** - * Sets the path for the local state dir. - * - * @param path The new path. - */ -void Application::DeclareLocalStateDir(const String& path) -{ - if (!ScriptGlobal::Exists("LocalStateDir")) - ScriptGlobal::Set("LocalStateDir", path); -} - -/** - * Retrieves the path for the local state dir. - * - * @returns The path. - */ -String Application::GetZonesDir() -{ - return ScriptGlobal::Get("ZonesDir", &Empty); -} - -/** - * Sets the path of the zones dir. - * - * @param path The new path. - */ -void Application::DeclareZonesDir(const String& path) -{ - if (!ScriptGlobal::Exists("ZonesDir")) - ScriptGlobal::Set("ZonesDir", path); -} - -/** - * Retrieves the path for the package data dir. - * - * @returns The path. - */ -String Application::GetPkgDataDir() -{ - String defaultValue = ""; - return ScriptGlobal::Get("PkgDataDir", &Empty); -} - -/** - * Sets the path for the package data dir. - * - * @param path The new path. - */ -void Application::DeclarePkgDataDir(const String& path) -{ - if (!ScriptGlobal::Exists("PkgDataDir")) - ScriptGlobal::Set("PkgDataDir", path); -} - -/** - * Retrieves the path for the include conf dir. - * - * @returns The path. - */ -String Application::GetIncludeConfDir() -{ - return ScriptGlobal::Get("IncludeConfDir", &Empty); -} - -/** - * Sets the path for the package data dir. - * - * @param path The new path. - */ -void Application::DeclareIncludeConfDir(const String& path) -{ - if (!ScriptGlobal::Exists("IncludeConfDir")) - ScriptGlobal::Set("IncludeConfDir", path); -} - -/** - * Retrieves the path for the state file. - * - * @returns The path. - */ -String Application::GetStatePath() -{ - return ScriptGlobal::Get("StatePath", &Empty); -} - -/** - * Sets the path for the state file. - * - * @param path The new path. - */ -void Application::DeclareStatePath(const String& path) -{ - if (!ScriptGlobal::Exists("StatePath")) - ScriptGlobal::Set("StatePath", path); -} - -/** - * Retrieves the path for the modified attributes file. - * - * @returns The path. - */ -String Application::GetModAttrPath() -{ - return ScriptGlobal::Get("ModAttrPath", &Empty); -} - -/** - * Sets the path for the modified attributes file. - * - * @param path The new path. - */ -void Application::DeclareModAttrPath(const String& path) -{ - if (!ScriptGlobal::Exists("ModAttrPath")) - ScriptGlobal::Set("ModAttrPath", path); -} - -/** - * Retrieves the path for the objects file. - * - * @returns The path. - */ -String Application::GetObjectsPath() -{ - return ScriptGlobal::Get("ObjectsPath", &Empty); -} - -/** - * Sets the path for the objects file. - * - * @param path The new path. - */ -void Application::DeclareObjectsPath(const String& path) -{ - if (!ScriptGlobal::Exists("ObjectsPath")) - ScriptGlobal::Set("ObjectsPath", path); -} - -/** -* Retrieves the path for the vars file. -* -* @returns The path. -*/ -String Application::GetVarsPath() -{ - return ScriptGlobal::Get("VarsPath", &Empty); -} - -/** -* Sets the path for the vars file. -* -* @param path The new path. -*/ -void Application::DeclareVarsPath(const String& path) -{ - if (!ScriptGlobal::Exists("VarsPath")) - ScriptGlobal::Set("VarsPath", path); -} - -/** - * Retrieves the path for the PID file. - * - * @returns The path. - */ -String Application::GetPidPath() -{ - return ScriptGlobal::Get("PidPath", &Empty); -} - -/** - * Sets the path for the PID file. - * - * @param path The new path. - */ -void Application::DeclarePidPath(const String& path) -{ - if (!ScriptGlobal::Exists("PidPath")) - ScriptGlobal::Set("PidPath", path); -} - -/** - * Retrieves the name of the user. - * - * @returns The name. - */ -String Application::GetRunAsUser() -{ - return ScriptGlobal::Get("RunAsUser"); -} - -/** - * Sets the name of the user. - * - * @param path The new user name. - */ -void Application::DeclareRunAsUser(const String& user) -{ - if (!ScriptGlobal::Exists("RunAsUser")) - ScriptGlobal::Set("RunAsUser", user); -} - -/** - * Retrieves the name of the group. - * - * @returns The name. - */ -String Application::GetRunAsGroup() -{ - return ScriptGlobal::Get("RunAsGroup"); -} - -/** - * Sets the name of the group. - * - * @param path The new group name. - */ -void Application::DeclareRunAsGroup(const String& group) -{ - if (!ScriptGlobal::Exists("RunAsGroup")) - ScriptGlobal::Set("RunAsGroup", group); -} - -/** - * Retrieves the file rlimit. - * - * @returns The limit. - */ -int Application::GetRLimitFiles() -{ - return ScriptGlobal::Get("RLimitFiles"); + return ScriptGlobal::Get(name, &defaultValue); } int Application::GetDefaultRLimitFiles() @@ -1468,80 +1203,16 @@ int Application::GetDefaultRLimitFiles() return 16 * 1024; } -/** - * Sets the file rlimit. - * - * @param path The new file rlimit. - */ -void Application::DeclareRLimitFiles(int limit) -{ - if (!ScriptGlobal::Exists("RLimitFiles")) - ScriptGlobal::Set("RLimitFiles", limit); -} - -/** - * Retrieves the process rlimit. - * - * @returns The limit. - */ -int Application::GetRLimitProcesses() -{ - return ScriptGlobal::Get("RLimitProcesses"); -} - int Application::GetDefaultRLimitProcesses() { return 16 * 1024; } -/** - * Sets the process rlimit. - * - * @param path The new process rlimit. - */ -void Application::DeclareRLimitProcesses(int limit) -{ - if (!ScriptGlobal::Exists("RLimitProcesses")) - ScriptGlobal::Set("RLimitProcesses", limit); -} - -/** - * Retrieves the stack rlimit. - * - * @returns The limit. - */ -int Application::GetRLimitStack() -{ - return ScriptGlobal::Get("RLimitStack"); -} - int Application::GetDefaultRLimitStack() { return 256 * 1024; } -/** - * Sets the stack rlimit. - * - * @param path The new stack rlimit. - */ -void Application::DeclareRLimitStack(int limit) -{ - if (!ScriptGlobal::Exists("RLimitStack")) - ScriptGlobal::Set("RLimitStack", limit); -} - -/** - * Sets the concurrency level. - * - * @param path The new concurrency level. - */ -void Application::DeclareConcurrency(int ncpus) -{ - if (!ScriptGlobal::Exists("Concurrency")) - ScriptGlobal::Set("Concurrency", ncpus); -} - /** * Retrieves the concurrency level. * @@ -1563,17 +1234,6 @@ void Application::SetMaxConcurrentChecks(int maxChecks) ScriptGlobal::Set("MaxConcurrentChecks", maxChecks); } -/** - * Sets the max concurrent checks. - * - * @param maxChecks The new limit. - */ -void Application::DeclareMaxConcurrentChecks(int maxChecks) -{ - if (!ScriptGlobal::Exists("MaxConcurrentChecks")) - ScriptGlobal::Set("MaxConcurrentChecks", maxChecks); -} - /** * Retrieves the max concurrent checks. * diff --git a/lib/base/application.hpp b/lib/base/application.hpp index 7722d25f4..dbb14c38d 100644 --- a/lib/base/application.hpp +++ b/lib/base/application.hpp @@ -85,70 +85,21 @@ public: static String GetExePath(const String& argv0); - static String GetPrefixDir(); - static void DeclarePrefixDir(const String& path); - - static String GetSysconfDir(); - static void DeclareSysconfDir(const String& path); - - static String GetZonesDir(); - static void DeclareZonesDir(const String& path); - - static String GetRunDir(); - static void DeclareRunDir(const String& path); - - static String GetLocalStateDir(); - static void DeclareLocalStateDir(const String& path); - - static String GetPkgDataDir(); - static void DeclarePkgDataDir(const String& path); - - static String GetIncludeConfDir(); - static void DeclareIncludeConfDir(const String& path); - - static String GetStatePath(void); - static void DeclareStatePath(const String& path); - - static String GetModAttrPath(); - static void DeclareModAttrPath(const String& path); - - static String GetObjectsPath(); - static void DeclareObjectsPath(const String& path); - - static String GetVarsPath(); - static void DeclareVarsPath(const String& path); - - static String GetPidPath(); - static void DeclarePidPath(const String& path); - - static String GetRunAsUser(); - static void DeclareRunAsUser(const String& user); - - static String GetRunAsGroup(); - static void DeclareRunAsGroup(const String& group); + static void DeclareConst(const String& name, const Value& value); + static Value GetConst(const String& name); + static Value GetConst(const String& name, Value defaultValue); #ifdef _WIN32 static bool IsProcessElevated(); #endif /* _WIN32 */ - static int GetRLimitFiles(); static int GetDefaultRLimitFiles(); - static void DeclareRLimitFiles(int limit); - - static int GetRLimitProcesses(); static int GetDefaultRLimitProcesses(); - static void DeclareRLimitProcesses(int limit); - - static int GetRLimitStack(); static int GetDefaultRLimitStack(); - static void DeclareRLimitStack(int limit); static int GetConcurrency(); - static void DeclareConcurrency(int ncpus); - static int GetMaxConcurrentChecks(); static int GetDefaultMaxConcurrentChecks(); - static void DeclareMaxConcurrentChecks(int maxChecks); static void SetMaxConcurrentChecks(int maxChecks); static ThreadPool& GetTP(); diff --git a/lib/base/tlsutility.cpp b/lib/base/tlsutility.cpp index c3fe07bd9..42fc92921 100644 --- a/lib/base/tlsutility.cpp +++ b/lib/base/tlsutility.cpp @@ -535,7 +535,7 @@ std::shared_ptr CreateCert(EVP_PKEY *pubkey, X509_NAME *subject, X509_NAME String GetIcingaCADir() { - return Application::GetLocalStateDir() + "/lib/icinga2/ca"; + return Application::GetConst("DataDir") + "/ca"; } std::shared_ptr CreateCertIcingaCA(EVP_PKEY *pubkey, X509_NAME *subject) diff --git a/lib/checker/CMakeLists.txt b/lib/checker/CMakeLists.txt index 8f3de0b1b..65bca61bb 100644 --- a/lib/checker/CMakeLists.txt +++ b/lib/checker/CMakeLists.txt @@ -36,14 +36,14 @@ set_target_properties ( install_if_not_exists( ${PROJECT_SOURCE_DIR}/etc/icinga2/features-available/checker.conf - ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/features-available + ${ICINGA2_CONFIGDIR}/features-available ) if(NOT WIN32) - install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_SYSCONFDIR}/icinga2/features-enabled\")") - install(CODE "execute_process(COMMAND \"${CMAKE_COMMAND}\" -E create_symlink ../features-available/checker.conf \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_SYSCONFDIR}/icinga2/features-enabled/checker.conf\")") + install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_CONFIGDIR}/features-enabled\")") + install(CODE "execute_process(COMMAND \"${CMAKE_COMMAND}\" -E create_symlink ../features-available/checker.conf \"\$ENV{DESTDIR}${ICINGA2_FULL_CONFIGDIR}/features-enabled/checker.conf\")") else() - install_if_not_exists(${PROJECT_SOURCE_DIR}/etc/icinga2/features-enabled/checker.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/features-enabled) + install_if_not_exists(${PROJECT_SOURCE_DIR}/etc/icinga2/features-enabled/checker.conf ${ICINGA2_CONFIGDIR}/features-enabled) endif() set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}" PARENT_SCOPE) diff --git a/lib/cli/apisetuputility.cpp b/lib/cli/apisetuputility.cpp index 1b60a2c1a..a7739227c 100644 --- a/lib/cli/apisetuputility.cpp +++ b/lib/cli/apisetuputility.cpp @@ -40,7 +40,7 @@ using namespace icinga; String ApiSetupUtility::GetConfdPath() { - return Application::GetSysconfDir() + "/icinga2/conf.d"; + return Application::GetConst("ConfigDir") + "/conf.d"; } String ApiSetupUtility::GetApiUsersConfPath() diff --git a/lib/cli/daemoncommand.cpp b/lib/cli/daemoncommand.cpp index ba2dade47..ba20eb823 100644 --- a/lib/cli/daemoncommand.cpp +++ b/lib/cli/daemoncommand.cpp @@ -72,7 +72,7 @@ static bool Daemonize() do { Utility::Sleep(0.1); - readpid = Application::ReadPidFile(Application::GetPidPath()); + readpid = Application::ReadPidFile(Application::GetConst("PidPath")); ret = waitpid(pid, &status, WNOHANG); } while (readpid != pid && ret == 0); @@ -193,7 +193,7 @@ int DaemonCommand::Run(const po::variables_map& vm, const std::vector 0) { Log(LogCritical, "cli") << "Another instance of Icinga already running with PID " << runningpid; @@ -204,14 +204,17 @@ int DaemonCommand::Run(const po::variables_map& vm, const std::vector configs; if (vm.count("config") > 0) configs = vm["config"].as >(); - else if (!vm.count("no-config")) - configs.push_back(Application::GetSysconfDir() + "/icinga2/icinga2.conf"); + else if (!vm.count("no-config")) { + /* The implicit string assignment is needed for Windows builds. */ + String configDir = Application::GetConst("ConfigDir"); + configs.push_back(configDir + "/icinga2.conf"); + } Log(LogInformation, "cli", "Loading configuration file(s)."); std::vector newItems; - if (!DaemonUtility::LoadConfigFiles(configs, newItems, Application::GetObjectsPath(), Application::GetVarsPath())) + if (!DaemonUtility::LoadConfigFiles(configs, newItems, Application::GetConst("ObjectsPath"), Application::GetConst("VarsPath"))) return EXIT_FAILURE; if (vm.count("validate")) { @@ -253,7 +256,7 @@ int DaemonCommand::Run(const po::variables_map& vm, const std::vector& configs, * unfortunately moving it there is somewhat non-trivial. */ success = true; - String zonesEtcDir = Application::GetZonesDir(); + String zonesEtcDir = Application::GetConst("ZonesDir"); if (!zonesEtcDir.IsEmpty() && Utility::PathExists(zonesEtcDir)) Utility::Glob(zonesEtcDir + "/*", std::bind(&IncludeZoneDirRecursive, _1, "_etc", std::ref(success)), GlobDirectory); @@ -130,7 +130,7 @@ bool DaemonUtility::ValidateConfigFiles(const std::vector& configs, /* Load package config files - they may contain additional zones which * are authoritative on this node and are checked in HasZoneConfigAuthority(). */ - String packagesVarDir = Application::GetLocalStateDir() + "/lib/icinga2/api/packages"; + String packagesVarDir = Application::GetConst("DataDir") + "/api/packages"; if (Utility::PathExists(packagesVarDir)) Utility::Glob(packagesVarDir + "/*", std::bind(&IncludePackage, _1, std::ref(success)), GlobDirectory); @@ -138,7 +138,7 @@ bool DaemonUtility::ValidateConfigFiles(const std::vector& configs, return false; /* Load cluster synchronized configuration files */ - String zonesVarDir = Application::GetLocalStateDir() + "/lib/icinga2/api/zones"; + String zonesVarDir = Application::GetConst("DataDir") + "/api/zones"; if (Utility::PathExists(zonesVarDir)) Utility::Glob(zonesVarDir + "/*", std::bind(&IncludeNonLocalZone, _1, "_cluster", std::ref(success)), GlobDirectory); diff --git a/lib/cli/featureutility.cpp b/lib/cli/featureutility.cpp index 9056b60fe..e01834c70 100644 --- a/lib/cli/featureutility.cpp +++ b/lib/cli/featureutility.cpp @@ -31,12 +31,12 @@ using namespace icinga; String FeatureUtility::GetFeaturesAvailablePath() { - return Application::GetSysconfDir() + "/icinga2/features-available"; + return Application::GetConst("ConfigDir") + "/features-available"; } String FeatureUtility::GetFeaturesEnabledPath() { - return Application::GetSysconfDir() + "/icinga2/features-enabled"; + return Application::GetConst("ConfigDir") + "/features-enabled"; } std::vector FeatureUtility::GetFieldCompletionSuggestions(const String& word, bool enable) diff --git a/lib/cli/nodesetupcommand.cpp b/lib/cli/nodesetupcommand.cpp index d0289b4fb..652f70f28 100644 --- a/lib/cli/nodesetupcommand.cpp +++ b/lib/cli/nodesetupcommand.cpp @@ -410,7 +410,7 @@ int NodeSetupCommand::SetupNode(const boost::program_options::variables_map& vm, } else { /* We cannot retrieve the parent certificate. * Tell the user to manually copy the ca.crt file - * into LocalStateDir + "/lib/icinga2/certs" + * into DataDir + "/certs" */ Log(LogWarning, "cli") << "\nNo connection to the parent node was specified.\n\n" diff --git a/lib/cli/nodeutility.cpp b/lib/cli/nodeutility.cpp index eb9080b97..259988259 100644 --- a/lib/cli/nodeutility.cpp +++ b/lib/cli/nodeutility.cpp @@ -43,12 +43,12 @@ using namespace icinga; String NodeUtility::GetConstantsConfPath() { - return Application::GetSysconfDir() + "/icinga2/constants.conf"; + return Application::GetConst("ConfigDir") + "/constants.conf"; } String NodeUtility::GetZonesConfPath() { - return Application::GetSysconfDir() + "/icinga2/zones.conf"; + return Application::GetConst("ConfigDir") + "/zones.conf"; } /* @@ -274,7 +274,7 @@ void NodeUtility::SerializeObject(std::ostream& fp, const Dictionary::Ptr& objec */ bool NodeUtility::UpdateConfiguration(const String& value, bool include, bool recursive) { - String configurationFile = Application::GetSysconfDir() + "/icinga2/icinga2.conf"; + String configurationFile = Application::GetConst("ConfigDir") + "/icinga2.conf"; Log(LogInformation, "cli") << "Updating '" << value << "' include in '" << configurationFile << "'."; diff --git a/lib/cli/nodewizardcommand.cpp b/lib/cli/nodewizardcommand.cpp index b5e143730..11e035aa7 100644 --- a/lib/cli/nodewizardcommand.cpp +++ b/lib/cli/nodewizardcommand.cpp @@ -392,7 +392,7 @@ wizard_ticket: } else { /* We cannot retrieve the parent certificate. * Tell the user to manually copy the ca.crt file - * into LocalStateDir + "/lib/icinga2/certs" + * into DataDir + "/certs" */ std::cout << ConsoleColorTag(Console_Bold) @@ -850,7 +850,7 @@ wizard_global_zone_loop_start: } /* Include api-users.conf */ - String apiUsersFilePath = Application::GetSysconfDir() + "/icinga2/conf.d/api-users.conf"; + String apiUsersFilePath = Application::GetConst("ConfigDir") + "/conf.d/api-users.conf"; std::cout << ConsoleColorTag(Console_Bold | Console_ForegroundGreen) << "Checking if the api-users.conf file exists...\n" diff --git a/lib/cli/objectlistcommand.cpp b/lib/cli/objectlistcommand.cpp index f5e46448c..f5c347eed 100644 --- a/lib/cli/objectlistcommand.cpp +++ b/lib/cli/objectlistcommand.cpp @@ -67,11 +67,11 @@ void ObjectListCommand::InitParameters(boost::program_options::options_descripti */ int ObjectListCommand::Run(const boost::program_options::variables_map& vm, const std::vector& ap) const { - String objectfile = Application::GetObjectsPath(); + String objectfile = Application::GetConst("ObjectsPath"); if (!Utility::PathExists(objectfile)) { Log(LogCritical, "cli") - << "Cannot open objects file '" << Application::GetObjectsPath() << "'."; + << "Cannot open objects file '" << Application::GetConst("ObjectsPath") << "'."; Log(LogCritical, "cli", "Run 'icinga2 daemon -C' to validate config and generate the cache file."); return 1; } diff --git a/lib/cli/troubleshootcommand.cpp b/lib/cli/troubleshootcommand.cpp index aabd9e41a..2770b5588 100644 --- a/lib/cli/troubleshootcommand.cpp +++ b/lib/cli/troubleshootcommand.cpp @@ -147,16 +147,26 @@ bool TroubleshootCommand::GeneralInfo(InfoLog& log, const boost::program_options //Application::DisplayInfoMessage() but formatted InfoLogLine(log) - << "\tApplication version: " << Application::GetAppVersion() << '\n' - << "\tInstallation root: " << Application::GetPrefixDir() << '\n' - << "\tSysconf directory: " << Application::GetSysconfDir() << '\n' - << "\tRun directory: " << Application::GetRunDir() << '\n' - << "\tLocal state directory: " << Application::GetLocalStateDir() << '\n' - << "\tPackage data directory: " << Application::GetPkgDataDir() << '\n' - << "\tState path: " << Application::GetStatePath() << '\n' - << "\tObjects path: " << Application::GetObjectsPath() << '\n' - << "\tVars path: " << Application::GetVarsPath() << '\n' - << "\tPID path: " << Application::GetPidPath() << '\n'; + << "\tApplication version: " << Application::GetConst("AppVersion") << '\n' + << "\t\n" + << "\tConfig directory: " << Application::GetConst("ConfigDir") << "\n" + << "\tData directory: " << Application::GetConst("DataDir") << "\n" + << "\tLog directory: " << Application::GetConst("LogDir") << "\n" + << "\tCache directory: " << Application::GetConst("CacheDir") << "\n" + << "\tRun directory: " << Application::GetConst("InitRunDir") << "\n" + << "\t\n" + << "Old paths (deprecated):\n" + << "\tInstallation root: " << Application::GetConst("PrefixDir") << '\n' + << "\tSysconf directory: " << Application::GetConst("SysconfDir") << '\n' + << "\tRun directory: " << Application::GetConst("RunDir") << '\n' + << "\tLocal state directory: " << Application::GetConst("LocalStateDir") << '\n' + << "\t\n" + << "Internal paths:\n" + << "\tPackage data directory: " << Application::GetConst("PkgDataDir") << '\n' + << "\tState path: " << Application::GetConst("StatePath") << '\n' + << "\tObjects path: " << Application::GetConst("ObjectsPath") << '\n' + << "\tVars path: " << Application::GetConst("VarsPath") << '\n' + << "\tPID path: " << Application::GetConst("PidPath") << '\n'; InfoLogLine(log) << '\n'; @@ -176,7 +186,7 @@ bool TroubleshootCommand::ObjectInfo(InfoLog& log, const boost::program_options: InfoLogLine(log, Console_ForegroundBlue) << std::string(14, '=') << " OBJECT INFORMATION " << std::string(14, '=') << "\n\n"; - String objectfile = Application::GetObjectsPath(); + String objectfile = Application::GetConst("ObjectsPath"); std::set configs; if (!Utility::PathExists(objectfile)) { @@ -252,14 +262,14 @@ bool TroubleshootCommand::ConfigInfo(InfoLog& log, const boost::program_options: InfoLogLine(log) << "A collection of important configuration files follows, please make sure to remove any sensitive data such as credentials, internal company names, etc\n"; - if (!PrintFile(log, Application::GetSysconfDir() + "/icinga2/icinga2.conf")) { + if (!PrintFile(log, Application::GetConst("ConfigDir") + "/icinga2.conf")) { InfoLogLine(log, 0, LogWarning) << "icinga2.conf not found, therefore skipping validation.\n" << "If you are using an icinga2.conf somewhere but the default path please validate it via 'icinga2 daemon -C -c \"path\to/icinga2.conf\"'\n" << "and provide it with your support request.\n"; } - if (!PrintFile(log, Application::GetSysconfDir() + "/icinga2/zones.conf")) { + if (!PrintFile(log, Application::GetConst("ConfigDir") + "/zones.conf")) { InfoLogLine(log, 0, LogWarning) << "zones.conf not found.\n" << "If you are using a zones.conf somewhere but the default path please provide it with your support request\n"; @@ -370,7 +380,7 @@ void TroubleshootCommand::GetLatestReport(const String& filename, time_t& bestTi bool TroubleshootCommand::PrintCrashReports(InfoLog& log) { - String spath = Application::GetLocalStateDir() + "/log/icinga2/crash/report.*"; + String spath = Application::GetConst("LogDir") + "/crash/report.*"; time_t bestTimestamp = 0; String bestFilename; @@ -383,7 +393,7 @@ bool TroubleshootCommand::PrintCrashReports(InfoLog& log) if (int const * err = boost::get_error_info(ex)) { if (*err != 3) {//Error code for path does not exist InfoLogLine(log, 0, LogWarning) - << Application::GetLocalStateDir() << "/log/icinga2/crash/ does not exist\n"; + << Application::GetConst("LogDir") + "/crash/ does not exist\n"; return false; } @@ -396,7 +406,7 @@ bool TroubleshootCommand::PrintCrashReports(InfoLog& log) #else catch (...) { InfoLogLine(log, 0, LogWarning) << "Error printing crash reports.\n" - << "Does " << Application::GetLocalStateDir() << "/log/icinga2/crash/ exist?\n"; + << "Does " << Application::GetConst("LogDir") + "/crash/ exist?\n"; return false; } @@ -404,7 +414,7 @@ bool TroubleshootCommand::PrintCrashReports(InfoLog& log) if (!bestTimestamp) InfoLogLine(log, Console_ForegroundYellow) - << "No crash logs found in " << Application::GetLocalStateDir().CStr() << "/log/icinga2/crash/\n\n"; + << "No crash logs found in " << Application::GetConst("LogDir") << "/crash/\n\n"; else { InfoLogLine(log) << "Latest crash report is from " << Utility::FormatDateTime("%Y-%m-%d %H:%M:%S", Utility::GetTime()) << '\n' @@ -444,7 +454,9 @@ bool TroubleshootCommand::PrintFile(InfoLog& log, const String& path) bool TroubleshootCommand::CheckConfig() { - return DaemonUtility::ValidateConfigFiles({ Application::GetSysconfDir() + "/icinga2/icinga2.conf" }, Application::GetObjectsPath()); + String configDir = Application::GetConst("ConfigDir"); + String objectsPath = Application::GetConst("ObjectsPath"); + return DaemonUtility::ValidateConfigFiles({ configDir + "/icinga2.conf" }, objectsPath); } //print is supposed allow the user to print the object file @@ -610,10 +622,10 @@ void TroubleshootCommand::InitParameters(boost::program_options::options_descrip int TroubleshootCommand::Run(const boost::program_options::variables_map& vm, const std::vector& ap) const { #ifdef _WIN32 //Dislikes ':' in filenames - String path = Application::GetLocalStateDir() + "/log/icinga2/troubleshooting-" + String path = Application::GetConst("LogDir") + "/troubleshooting-" + Utility::FormatDateTime("%Y-%m-%d_%H-%M-%S", Utility::GetTime()) + ".log"; #else - String path = Application::GetLocalStateDir() + "/log/icinga2/troubleshooting-" + String path = Application::GetConst("LogDir") + "/troubleshooting-" + Utility::FormatDateTime("%Y-%m-%d_%H:%M:%S", Utility::GetTime()) + ".log"; #endif /*_WIN32*/ diff --git a/lib/cli/variablegetcommand.cpp b/lib/cli/variablegetcommand.cpp index 76fa634aa..855770148 100644 --- a/lib/cli/variablegetcommand.cpp +++ b/lib/cli/variablegetcommand.cpp @@ -75,7 +75,7 @@ int VariableGetCommand::Run(const boost::program_options::variables_map& vm, con return 0; } - String varsfile = Application::GetVarsPath(); + String varsfile = Application::GetConst("VarsPath"); if (!Utility::PathExists(varsfile)) { Log(LogCritical, "cli") diff --git a/lib/cli/variablelistcommand.cpp b/lib/cli/variablelistcommand.cpp index 9aff1cbea..9ebbadf11 100644 --- a/lib/cli/variablelistcommand.cpp +++ b/lib/cli/variablelistcommand.cpp @@ -53,7 +53,7 @@ String VariableListCommand::GetShortDescription() const */ int VariableListCommand::Run(const boost::program_options::variables_map& vm, const std::vector& ap) const { - String varsfile = Application::GetVarsPath(); + String varsfile = Application::GetConst("VarsPath"); if (!Utility::PathExists(varsfile)) { Log(LogCritical, "cli") diff --git a/lib/cli/variableutility.cpp b/lib/cli/variableutility.cpp index 9044a9e9b..ed9bd770d 100644 --- a/lib/cli/variableutility.cpp +++ b/lib/cli/variableutility.cpp @@ -31,7 +31,7 @@ using namespace icinga; Value VariableUtility::GetVariable(const String& name) { - String varsfile = Application::GetVarsPath(); + String varsfile = Application::GetConst("VarsPath"); std::fstream fp; fp.open(varsfile.CStr(), std::ios_base::in); @@ -61,7 +61,7 @@ Value VariableUtility::GetVariable(const String& name) void VariableUtility::PrintVariables(std::ostream& outfp) { - String varsfile = Application::GetVarsPath(); + String varsfile = Application::GetConst("VarsPath"); std::fstream fp; fp.open(varsfile.CStr(), std::ios_base::in); diff --git a/lib/compat/CMakeLists.txt b/lib/compat/CMakeLists.txt index df4a3e0eb..be33add0b 100644 --- a/lib/compat/CMakeLists.txt +++ b/lib/compat/CMakeLists.txt @@ -42,21 +42,21 @@ set_target_properties ( install_if_not_exists( ${PROJECT_SOURCE_DIR}/etc/icinga2/features-available/command.conf - ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/features-available + ${ICINGA2_CONFIGDIR}/features-available ) install_if_not_exists( ${PROJECT_SOURCE_DIR}/etc/icinga2/features-available/compatlog.conf - ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/features-available + ${ICINGA2_CONFIGDIR}/features-available ) install_if_not_exists( ${PROJECT_SOURCE_DIR}/etc/icinga2/features-available/statusdata.conf - ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/features-available + ${ICINGA2_CONFIGDIR}/features-available ) -install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/icinga2/compat/archives\")") -install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/spool/icinga2\")") -install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_RUNDIR}/icinga2/cmd\")") +install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_LOGDIR}/compat/archives\")") +install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_SPOOLDIR}\")") +install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_INITRUNDIR}/cmd\")") set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}" PARENT_SCOPE) diff --git a/lib/compat/checkresultreader.ti b/lib/compat/checkresultreader.ti index 18b3d0ac4..cc558a553 100644 --- a/lib/compat/checkresultreader.ti +++ b/lib/compat/checkresultreader.ti @@ -30,7 +30,7 @@ class CheckResultReader : ConfigObject activation_priority 100; [config] String spool_dir { - default {{{ return Application::GetLocalStateDir() + "/lib/icinga2/spool/checkresults/"; }}} + default {{{ return Application::GetConst("DataDir") + "/spool/checkresults/"; }}} }; }; diff --git a/lib/compat/compatlogger.ti b/lib/compat/compatlogger.ti index 322236cd8..4066a72bd 100644 --- a/lib/compat/compatlogger.ti +++ b/lib/compat/compatlogger.ti @@ -30,7 +30,7 @@ class CompatLogger : ConfigObject activation_priority 100; [config] String log_dir { - default {{{ return Application::GetLocalStateDir() + "/log/icinga2/compat"; }}} + default {{{ return Application::GetConst("LogDir") + "/compat"; }}} }; [config] String rotation_method { default {{{ return "HOURLY"; }}} diff --git a/lib/compat/externalcommandlistener.ti b/lib/compat/externalcommandlistener.ti index baffb7f51..697b3a0c4 100644 --- a/lib/compat/externalcommandlistener.ti +++ b/lib/compat/externalcommandlistener.ti @@ -30,7 +30,7 @@ class ExternalCommandListener : ConfigObject activation_priority 100; [config] String command_path { - default {{{ return Application::GetRunDir() + "/icinga2/cmd/icinga2.cmd"; }}} + default {{{ return Application::GetConst("InitRunDir") + "/cmd/icinga2.cmd"; }}} }; }; diff --git a/lib/compat/statusdatawriter.cpp b/lib/compat/statusdatawriter.cpp index 407a14d9a..e5a4578ac 100644 --- a/lib/compat/statusdatawriter.cpp +++ b/lib/compat/statusdatawriter.cpp @@ -559,7 +559,7 @@ void StatusDataWriter::UpdateObjectsCache() { CONTEXT("Writing objects.cache file"); - String objectsPath = GetObjectsPath(); + String objectsPath = Application::GetConst("ObjectsPath"); std::fstream objectfp; String tempObjectsPath = Utility::CreateTempFile(objectsPath + ".XXXXXX", 0644, objectfp); diff --git a/lib/compat/statusdatawriter.ti b/lib/compat/statusdatawriter.ti index 5ac2969a9..846834f31 100644 --- a/lib/compat/statusdatawriter.ti +++ b/lib/compat/statusdatawriter.ti @@ -30,10 +30,10 @@ class StatusDataWriter : ConfigObject activation_priority 100; [config] String status_path { - default {{{ return Application::GetLocalStateDir() + "/cache/icinga2/status.dat"; }}} + default {{{ return Application::GetConst("CacheDir") + "/status.dat"; }}} }; [config] String objects_path { - default {{{ return Application::GetLocalStateDir() + "/cache/icinga2/objects.cache"; }}} + default {{{ return Application::GetConst("CacheDir") + "/objects.cache"; }}} }; [config] double update_interval { default {{{ return 15; }}} diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp index e20612860..af2afd017 100644 --- a/lib/config/configitem.cpp +++ b/lib/config/configitem.cpp @@ -577,8 +577,8 @@ bool ConfigItem::ActivateItems(WorkQueue& upq, const std::vector expression = ConfigCompiler::CompileFile(Application::GetModAttrPath()); + if (Utility::PathExists(Application::GetConst("ModAttrPath"))) { + std::unique_ptr expression = ConfigCompiler::CompileFile(Application::GetConst("ModAttrPath")); if (expression) { try { diff --git a/lib/db_ido_mysql/CMakeLists.txt b/lib/db_ido_mysql/CMakeLists.txt index 1587cbf19..30e180f65 100644 --- a/lib/db_ido_mysql/CMakeLists.txt +++ b/lib/db_ido_mysql/CMakeLists.txt @@ -38,7 +38,7 @@ set_target_properties ( install_if_not_exists( ${PROJECT_SOURCE_DIR}/etc/icinga2/features-available/ido-mysql.conf - ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/features-available + ${ICINGA2_CONFIGDIR}/features-available ) install( diff --git a/lib/db_ido_pgsql/CMakeLists.txt b/lib/db_ido_pgsql/CMakeLists.txt index 35f15fab5..b34736e66 100644 --- a/lib/db_ido_pgsql/CMakeLists.txt +++ b/lib/db_ido_pgsql/CMakeLists.txt @@ -38,7 +38,7 @@ set_target_properties ( install_if_not_exists( ${PROJECT_SOURCE_DIR}/etc/icinga2/features-available/ido-pgsql.conf - ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/features-available + ${ICINGA2_CONFIGDIR}/features-available ) install( diff --git a/lib/icinga/icingaapplication.cpp b/lib/icinga/icingaapplication.cpp index 454c78d6d..6ac00aa60 100644 --- a/lib/icinga/icingaapplication.cpp +++ b/lib/icinga/icingaapplication.cpp @@ -156,13 +156,13 @@ static void PersistModAttrHelper(std::fstream& fp, ConfigObject::Ptr& previousOb void IcingaApplication::DumpProgramState() { - ConfigObject::DumpObjects(GetStatePath()); + ConfigObject::DumpObjects(GetConst("StatePath")); DumpModifiedAttributes(); } void IcingaApplication::DumpModifiedAttributes() { - String path = GetModAttrPath(); + String path = GetConst("ModAttrPath"); std::fstream fp; String tempFilename = Utility::CreateTempFile(path + ".XXXXXX", 0644, fp); diff --git a/lib/icinga/icingaapplication.hpp b/lib/icinga/icingaapplication.hpp index 51216a02c..eac7f5903 100644 --- a/lib/icinga/icingaapplication.hpp +++ b/lib/icinga/icingaapplication.hpp @@ -46,8 +46,6 @@ public: static IcingaApplication::Ptr GetInstance(); - String GetPidPath() const; - bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, Value *result) const override; String GetNodeName() const; diff --git a/lib/livestatus/CMakeLists.txt b/lib/livestatus/CMakeLists.txt index e93e2624b..9b657645f 100644 --- a/lib/livestatus/CMakeLists.txt +++ b/lib/livestatus/CMakeLists.txt @@ -72,9 +72,9 @@ set_target_properties ( install_if_not_exists( ${PROJECT_SOURCE_DIR}/etc/icinga2/features-available/livestatus.conf - ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/features-available + ${ICINGA2_CONFIGDIR}/features-available ) -install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_RUNDIR}/icinga2/cmd\")") +install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_INITRUNDIR}/cmd\")") set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}" PARENT_SCOPE) diff --git a/lib/livestatus/livestatuslistener.ti b/lib/livestatus/livestatuslistener.ti index 0742a6fb5..1a4729d5e 100644 --- a/lib/livestatus/livestatuslistener.ti +++ b/lib/livestatus/livestatuslistener.ti @@ -32,7 +32,7 @@ class LivestatusListener : ConfigObject { default {{{ return "unix"; }}} }; [config] String socket_path { - default {{{ return Application::GetRunDir() + "/icinga2/cmd/livestatus"; }}} + default {{{ return Application::GetConst("InitRunDir") + "/cmd/livestatus"; }}} }; [config] String bind_host { default {{{ return "127.0.0.1"; }}} @@ -41,7 +41,7 @@ class LivestatusListener : ConfigObject { default {{{ return "6558"; }}} }; [config] String compat_log_path { - default {{{ return Application::GetLocalStateDir() + "/log/icinga2/compat"; }}} + default {{{ return Application::GetConst("LogDir") + "/compat"; }}} }; }; diff --git a/lib/notification/CMakeLists.txt b/lib/notification/CMakeLists.txt index 6c5940b9a..91207ad6d 100644 --- a/lib/notification/CMakeLists.txt +++ b/lib/notification/CMakeLists.txt @@ -36,14 +36,14 @@ set_target_properties ( install_if_not_exists( ${PROJECT_SOURCE_DIR}/etc/icinga2/features-available/notification.conf - ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/features-available + ${ICINGA2_CONFIGDIR}/features-available ) if(NOT WIN32) - install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_SYSCONFDIR}/icinga2/features-enabled\")") - install(CODE "execute_process(COMMAND \"${CMAKE_COMMAND}\" -E create_symlink ../features-available/notification.conf \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_SYSCONFDIR}/icinga2/features-enabled/notification.conf\")") + install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_CONFIGDIR}/features-enabled\")") + install(CODE "execute_process(COMMAND \"${CMAKE_COMMAND}\" -E create_symlink ../features-available/notification.conf \"\$ENV{DESTDIR}${ICINGA2_FULL_CONFIGDIR}/features-enabled/notification.conf\")") else() - install_if_not_exists(${PROJECT_SOURCE_DIR}/etc/icinga2/features-enabled/notification.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/features-enabled) + install_if_not_exists(${PROJECT_SOURCE_DIR}/etc/icinga2/features-enabled/notification.conf ${ICINGA2_CONFIGDIR}/features-enabled) endif() set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}" PARENT_SCOPE) diff --git a/lib/perfdata/CMakeLists.txt b/lib/perfdata/CMakeLists.txt index 7b0780414..06a9f7336 100644 --- a/lib/perfdata/CMakeLists.txt +++ b/lib/perfdata/CMakeLists.txt @@ -46,35 +46,35 @@ set_target_properties ( install_if_not_exists( ${PROJECT_SOURCE_DIR}/etc/icinga2/features-available/gelf.conf - ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/features-available + ${ICINGA2_CONFIGDIR}/features-available ) install_if_not_exists( ${PROJECT_SOURCE_DIR}/etc/icinga2/features-available/graphite.conf - ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/features-available + ${ICINGA2_CONFIGDIR}/features-available ) install_if_not_exists( ${PROJECT_SOURCE_DIR}/etc/icinga2/features-available/influxdb.conf - ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/features-available + ${ICINGA2_CONFIGDIR}/features-available ) install_if_not_exists( ${PROJECT_SOURCE_DIR}/etc/icinga2/features-available/elasticsearch.conf - ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/features-available + ${ICINGA2_CONFIGDIR}/features-available ) install_if_not_exists( ${PROJECT_SOURCE_DIR}/etc/icinga2/features-available/opentsdb.conf - ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/features-available + ${ICINGA2_CONFIGDIR}/features-available ) install_if_not_exists( ${PROJECT_SOURCE_DIR}/etc/icinga2/features-available/perfdata.conf - ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/features-available + ${ICINGA2_CONFIGDIR}/features-available ) -install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/spool/icinga2/perfdata\")") -install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/spool/icinga2/tmp\")") +install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_SPOOLDIR}/perfdata\")") +install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_SPOOLDIR}/tmp\")") set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}" PARENT_SCOPE) diff --git a/lib/perfdata/perfdatawriter.ti b/lib/perfdata/perfdatawriter.ti index c0988f339..4b6560291 100644 --- a/lib/perfdata/perfdatawriter.ti +++ b/lib/perfdata/perfdatawriter.ti @@ -30,16 +30,16 @@ class PerfdataWriter : ConfigObject activation_priority 100; [config] String host_perfdata_path { - default {{{ return Application::GetLocalStateDir() + "/spool/icinga2/perfdata/host-perfdata"; }}} + default {{{ return Application::GetConst("SpoolDir") + "/perfdata/host-perfdata"; }}} }; [config] String service_perfdata_path { - default {{{ return Application::GetLocalStateDir() + "/spool/icinga2/perfdata/service-perfdata"; }}} + default {{{ return Application::GetConst("SpoolDir") + "/perfdata/service-perfdata"; }}} }; [config] String host_temp_path { - default {{{ return Application::GetLocalStateDir() + "/spool/icinga2/tmp/host-perfdata"; }}} + default {{{ return Application::GetConst("SpoolDir") + "/tmp/host-perfdata"; }}} }; [config] String service_temp_path { - default {{{ return Application::GetLocalStateDir() + "/spool/icinga2/tmp/service-perfdata"; }}} + default {{{ return Application::GetConst("SpoolDir") + "/tmp/service-perfdata"; }}} }; [config] String host_format_template { default {{{ diff --git a/lib/remote/CMakeLists.txt b/lib/remote/CMakeLists.txt index bb9593c56..61b6523ff 100644 --- a/lib/remote/CMakeLists.txt +++ b/lib/remote/CMakeLists.txt @@ -76,10 +76,10 @@ set_target_properties ( FOLDER Lib ) -#install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/icinga2/api\")") -install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/icinga2/api/log\")") -install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/icinga2/api/zones\")") -install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/icinga2/certs\")") -install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/icinga2/certificate-requests\")") +#install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_DATADIR}/api\")") +install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_DATADIR}/api/log\")") +install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_DATADIR}/api/zones\")") +install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_DATADIR}/certs\")") +install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_DATADIR}/certificate-requests\")") diff --git a/lib/remote/apilistener-filesync.cpp b/lib/remote/apilistener-filesync.cpp index 30a79a35f..0c8987237 100644 --- a/lib/remote/apilistener-filesync.cpp +++ b/lib/remote/apilistener-filesync.cpp @@ -202,7 +202,7 @@ void ApiListener::SyncZoneDir(const Zone::Ptr& zone) const if (sumUpdates == 0) return; - String oldDir = Application::GetLocalStateDir() + "/lib/icinga2/api/zones/" + zone->GetName(); + String oldDir = Application::GetConst("DataDir") + "/api/zones/" + zone->GetName(); Log(LogInformation, "ApiListener") << "Copying " << sumUpdates << " zone configuration files for zone '" << zone->GetName() << "' to '" << oldDir << "'."; @@ -240,7 +240,7 @@ void ApiListener::SendConfigUpdate(const JsonRpcConnection::Ptr& aclient) Dictionary::Ptr configUpdateV1 = new Dictionary(); Dictionary::Ptr configUpdateV2 = new Dictionary(); - String zonesDir = Application::GetLocalStateDir() + "/lib/icinga2/api/zones"; + String zonesDir = Application::GetConst("DataDir") + "/api/zones"; for (const Zone::Ptr& zone : ConfigType::GetObjectsByType()) { String zoneDir = zonesDir + "/" + zone->GetName(); @@ -315,7 +315,7 @@ Value ApiListener::ConfigUpdateHandler(const MessageOrigin::Ptr& origin, const D continue; } - String oldDir = Application::GetLocalStateDir() + "/lib/icinga2/api/zones/" + zone->GetName(); + String oldDir = Application::GetConst("DataDir") + "/api/zones/" + zone->GetName(); Utility::MkDirP(oldDir, 0700); diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index c1546710d..c7ba834b4 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -56,22 +56,22 @@ ApiListener::ApiListener() String ApiListener::GetApiDir() { - return Application::GetLocalStateDir() + "/lib/icinga2/api/"; + return Application::GetConst("DataDir") + "/api/"; } String ApiListener::GetCertsDir() { - return Application::GetLocalStateDir() + "/lib/icinga2/certs/"; + return Application::GetConst("DataDir") + "/certs/"; } String ApiListener::GetCaDir() { - return Application::GetLocalStateDir() + "/lib/icinga2/ca/"; + return Application::GetConst("DataDir") + "/ca/"; } String ApiListener::GetCertificateRequestsDir() { - return Application::GetLocalStateDir() + "/lib/icinga2/certificate-requests/"; + return Application::GetConst("DataDir") + "/certificate-requests/"; } String ApiListener::GetDefaultCertPath() diff --git a/lib/remote/configpackageutility.cpp b/lib/remote/configpackageutility.cpp index 56ed57f7b..19b1022e8 100644 --- a/lib/remote/configpackageutility.cpp +++ b/lib/remote/configpackageutility.cpp @@ -30,7 +30,7 @@ using namespace icinga; String ConfigPackageUtility::GetPackageDir() { - return Application::GetLocalStateDir() + "/lib/icinga2/api/packages"; + return Application::GetConst("DataDir") + "/api/packages"; } void ConfigPackageUtility::CreatePackage(const String& name)