From: Gunnar Beutner Date: Tue, 22 Jul 2014 11:18:41 +0000 (+0200) Subject: Make location of the /run directory configurable X-Git-Tag: v2.0.2~56 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a49a598eef5bdf7bfeefb5fc971971eab5fd18f1;p=icinga2 Make location of the /run directory configurable fixes #6627 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 24e3778fb..449f42f25 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,10 +31,13 @@ endif() file(STRINGS icinga2.spec VERSION_LINE REGEX "^Version: ") string(REPLACE "Version: " "" ICINGA2_VERSION ${VERSION_LINE}) +include(GNUInstallDirs) + set(ICINGA2_USER "icinga" CACHE STRING "Icinga 2 user") set(ICINGA2_GROUP "icinga" CACHE STRING "Icinga 2 group") set(ICINGA2_COMMAND_USER "icinga" CACHE STRING "Icinga 2 command user") 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_PLUGIN_PATH "/usr/lib/nagios/plugins" CACHE STRING "Path for the check plugins") set(ICINGA2_GIT_VERSION_INFO ON CACHE BOOL "Whether to use git describe") @@ -121,7 +124,6 @@ if(HAVE_LIBEXECINFO) set(HAVE_BACKTRACE_SYMBOLS TRUE) endif() -include(GNUInstallDirs) configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h ESCAPE_QUOTES) install( diff --git a/INSTALL b/INSTALL index 06f530529..a3e0245f2 100644 --- a/INSTALL +++ b/INSTALL @@ -127,6 +127,7 @@ variables are supported: - ICINGA2_GIT_VERSION_INFO: Whether to use Git to determine the version number; defaults to "ON" - ICINGA2_COMMAND_GROUP: The command group Icinga 2 should use; defaults to "icingacmd" - ICINGA2_PLUGIN_PATH: The path for the Monitoring Plugins project binaries; defaults to "/usr/lib/nagios/plugins" +- 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 diff --git a/components/compat/CMakeLists.txt b/components/compat/CMakeLists.txt index 9e555ea61..2efab5f20 100644 --- a/components/compat/CMakeLists.txt +++ b/components/compat/CMakeLists.txt @@ -37,5 +37,5 @@ install(TARGETS compat RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR} LIBRARY DEST 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}/cache/icinga2\")") install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/spool/icinga2\")") -install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/run/icinga2/cmd\")") +install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_RUNDIR}/icinga2/cmd\")") diff --git a/components/compat/externalcommandlistener.ti b/components/compat/externalcommandlistener.ti index 7ef94e73c..2a634b4d0 100644 --- a/components/compat/externalcommandlistener.ti +++ b/components/compat/externalcommandlistener.ti @@ -7,7 +7,7 @@ namespace icinga class ExternalCommandListener : DynamicObject { [config] String command_path { - default {{{ return Application::GetLocalStateDir() + "/run/icinga2/cmd/icinga2.cmd"; }}} + default {{{ return Application::GetRunDir() + "/icinga2/cmd/icinga2.cmd"; }}} }; }; diff --git a/components/livestatus/livestatuslistener.ti b/components/livestatus/livestatuslistener.ti index 61d85b9e9..0bd8e9489 100644 --- a/components/livestatus/livestatuslistener.ti +++ b/components/livestatus/livestatuslistener.ti @@ -9,7 +9,7 @@ class LivestatusListener : DynamicObject { default {{{ return "unix"; }}} }; [config] String socket_path { - default {{{ return Application::GetLocalStateDir() + "/run/icinga2/cmd/livestatus"; }}} + default {{{ return Application::GetRunDir() + "/icinga2/cmd/livestatus"; }}} }; [config] String bind_host { default {{{ return "127.0.0.1"; }}} diff --git a/config.h.cmake b/config.h.cmake index 71e42eee7..cde13a173 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -9,6 +9,7 @@ #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" diff --git a/debian/rules b/debian/rules index d7a5d84da..2a6e20d04 100755 --- a/debian/rules +++ b/debian/rules @@ -22,6 +22,7 @@ override_dh_auto_configure: dh_auto_configure -- \ -DCMAKE_INSTALL_LOCALSTATEDIR=/var \ -DCMAKE_INSTALL_SYSCONFDIR=/etc \ + -DICINGA2_RUNDIR=/run \ -DICINGA2_USER=nagios \ -DICINGA2_GROUP=nagios \ -DICINGA2_COMMAND_USER=nagios \ diff --git a/doc/3-monitoring-basics.md b/doc/3-monitoring-basics.md index 4c3c1e6ae..3fe30520d 100644 --- a/doc/3-monitoring-basics.md +++ b/doc/3-monitoring-basics.md @@ -934,7 +934,7 @@ information in the check output (`-o`). PluginDir + "/process_check_result", "-H", "$host.name$", "-S", "$service.name$", - "-c", LocalStateDir + "/run/icinga2/cmd/icinga2.cmd", + "-c", RunDir + "/icinga2/cmd/icinga2.cmd", "-r", "0", "-o", "Event Handler triggered in state '$service.state$' with output '$service.output$'." ] diff --git a/doc/6-configuring-icinga-2.md b/doc/6-configuring-icinga-2.md index 1440e1b28..d6ae9bafd 100644 --- a/doc/6-configuring-icinga-2.md +++ b/doc/6-configuring-icinga-2.md @@ -10,6 +10,7 @@ PrefixDir |**Read-only.** Contains the installation prefix that was sp 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". PidPath |**Read-write.** Contains the path of the Icinga 2 PID file. Defaults to LocalStateDir + "/run/icinga2/icinga2.pid". @@ -1435,7 +1436,7 @@ Attributes: socket\_type |**Optional.** Specifies the socket type. Can be either "tcp" or "unix". Defaults to "unix". bind\_host |**Optional.** Only valid when socket\_type is "tcp". Host address to listen on for connections. Defaults to "127.0.0.1". bind\_port |**Optional.** Only valid when `socket_type` is "tcp". Port to listen on for connections. Defaults to 6558. - socket\_path |**Optional.** Only valid when `socket_type` is "unix". Specifies the path to the UNIX socket file. Defaults to LocalStateDir + "/run/icinga2/cmd/livestatus". + socket\_path |**Optional.** Only valid when `socket_type` is "unix". Specifies the path to the UNIX socket file. Defaults to RunDir + "/icinga2/cmd/livestatus". compat\_log\_path |**Optional.** Required for historical table queries. Requires `CompatLogger` feature enabled. Defaults to LocalStateDir + "/log/icinga2/compat" > **Note** @@ -1481,7 +1482,7 @@ Attributes: Name |Description ----------------|---------------- - command\_path |**Optional.** Path to the command pipe. Defaults to LocalStateDir + "/run/icinga2/cmd/icinga2.cmd". + command\_path |**Optional.** Path to the command pipe. Defaults to RunDir + "/icinga2/cmd/icinga2.cmd". ### CompatLogger diff --git a/etc/initsystem/icinga2-prepare-dirs b/etc/initsystem/icinga2-prepare-dirs index 8d55ac077..89aaa6416 100644 --- a/etc/initsystem/icinga2-prepare-dirs +++ b/etc/initsystem/icinga2-prepare-dirs @@ -28,6 +28,6 @@ if [ -f $ICINGA2_LOG ]; then chown $ICINGA2_USER:$ICINGA2_COMMAND_GROUP $ICINGA2_LOG fi -mkdir -p $ICINGA2_STATE_DIR/run/icinga2/cmd -chown $ICINGA2_USER:$ICINGA2_COMMAND_GROUP $ICINGA2_STATE_DIR/run/icinga2/cmd -chmod 2755 $ICINGA2_STATE_DIR/run/icinga2/cmd +mkdir -p $ICINGA2_RUN_DIR/icinga2/cmd +chown $ICINGA2_USER:$ICINGA2_COMMAND_GROUP $ICINGA2_RUN_DIR/icinga2/cmd +chmod 2755 $ICINGA2_RUN_DIR/icinga2/cmd diff --git a/etc/initsystem/icinga2.service.cmake b/etc/initsystem/icinga2.service.cmake index e15c0040f..815d57338 100644 --- a/etc/initsystem/icinga2.service.cmake +++ b/etc/initsystem/icinga2.service.cmake @@ -7,7 +7,7 @@ Type=forking EnvironmentFile=@ICINGA2_SYSCONFIGFILE@ ExecStartPre=@CMAKE_INSTALL_FULL_SBINDIR@/icinga2-prepare-dirs @ICINGA2_SYSCONFIGFILE@ ExecStart=@CMAKE_INSTALL_FULL_SBINDIR@/icinga2 -c ${ICINGA2_CONFIG_FILE} -d -e ${ICINGA2_ERROR_LOG} -u ${ICINGA2_USER} -g ${ICINGA2_GROUP} -PIDFile=@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/run/icinga2/icinga2.pid +PIDFile=@ICINGA2_RUNDIR@/icinga2/icinga2.pid ExecReload=/bin/kill -HUP $MAINPID [Install] diff --git a/etc/initsystem/icinga2.sysconfig.cmake b/etc/initsystem/icinga2.sysconfig.cmake index 4348b4d46..8b65b8017 100644 --- a/etc/initsystem/icinga2.sysconfig.cmake +++ b/etc/initsystem/icinga2.sysconfig.cmake @@ -1,7 +1,8 @@ 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=@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/run/icinga2/icinga2.pid +ICINGA2_PID_FILE=$ICINGA2_RUN_DIR/icinga2/icinga2.pid 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 diff --git a/icinga-app/CMakeLists.txt b/icinga-app/CMakeLists.txt index ee6eceff6..e729e07cf 100644 --- a/icinga-app/CMakeLists.txt +++ b/icinga-app/CMakeLists.txt @@ -40,4 +40,4 @@ install( 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}${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/run/icinga2\")") +install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_RUNDIR}/icinga2\")") diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index 513d8c211..93d8ec3a6 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -300,6 +300,7 @@ int Main(void) String prefix = (char *)pvData; Application::DeclarePrefixDir(prefix); Application::DeclareSysconfDir(prefix + "\\etc"); + Application::DeclareRunDir(prefix + "\\var\\run"); Application::DeclareLocalStateDir(prefix + "\\var"); Application::DeclarePkgDataDir(prefix + "\\share\\icinga2"); Application::DeclareIncludeConfDir(prefix + "\\share\\icinga2\\include"); @@ -316,6 +317,7 @@ int Main(void) #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); @@ -380,7 +382,7 @@ int Main(void) } Application::DeclareStatePath(Application::GetLocalStateDir() + "/lib/icinga2/icinga2.state"); - Application::DeclarePidPath(Application::GetLocalStateDir() + "/run/icinga2/icinga2.pid"); + Application::DeclarePidPath(Application::GetRunDir() + "/icinga2/icinga2.pid"); #ifndef _WIN32 if (g_AppParams.count("group")) { diff --git a/lib/base/application.cpp b/lib/base/application.cpp index 0d47989a7..a42cafcd6 100644 --- a/lib/base/application.cpp +++ b/lib/base/application.cpp @@ -459,6 +459,7 @@ void Application::DisplayVersionMessage(void) << "* Application version: " << GetVersion() << std::endl << "* Installation root: " << GetPrefixDir() << std::endl << "* Sysconf directory: " << GetSysconfDir() << std::endl + << "* Run directory: " << GetRunDir() << std::endl << "* Local state directory: " << GetLocalStateDir() << std::endl << "* Package data directory: " << GetPkgDataDir() << std::endl << "* State path: " << GetStatePath() << std::endl @@ -841,6 +842,26 @@ void Application::DeclareSysconfDir(const String& path) ScriptVariable::Set("SysconfDir", path, false); } +/** + * Retrieves the path for the run dir. + * + * @returns The path. + */ +String Application::GetRunDir(void) +{ + return ScriptVariable::Get("RunDir"); +} + +/** + * Sets the path of the run dir. + * + * @param path The new path. + */ +void Application::DeclareRunDir(const String& path) +{ + ScriptVariable::Set("RunDir", path, false); +} + /** * Retrieves the path for the local state dir. * @@ -852,13 +873,13 @@ String Application::GetLocalStateDir(void) } /** - * Sets the path of the zones dir. + * Sets the path for the local state dir. * * @param path The new path. */ -void Application::DeclareZonesDir(const String& path) +void Application::DeclareLocalStateDir(const String& path) { - ScriptVariable::Set("ZonesDir", path, false); + ScriptVariable::Set("LocalStateDir", path, false); } /** @@ -872,13 +893,13 @@ String Application::GetZonesDir(void) } /** - * Sets the path for the local state dir. + * Sets the path of the zones dir. * * @param path The new path. */ -void Application::DeclareLocalStateDir(const String& path) +void Application::DeclareZonesDir(const String& path) { - ScriptVariable::Set("LocalStateDir", path, false); + ScriptVariable::Set("ZonesDir", path, false); } /** diff --git a/lib/base/application.hpp b/lib/base/application.hpp index 1a221ebec..c132ae196 100644 --- a/lib/base/application.hpp +++ b/lib/base/application.hpp @@ -87,6 +87,9 @@ public: static String GetZonesDir(void); static void DeclareZonesDir(const String& path); + static String GetRunDir(void); + static void DeclareRunDir(const String& path); + static String GetLocalStateDir(void); static void DeclareLocalStateDir(const String& path);