diff --git a/doc/11-cli-commands.md b/doc/11-cli-commands.md
index 2324ab764..457656cb0 100644
--- a/doc/11-cli-commands.md
+++ b/doc/11-cli-commands.md
@@ -430,6 +430,7 @@ Command options:
-c [ --config ] arg parse a configuration file
-z [ --no-config ] start without a configuration file
-C [ --validate ] exit after validating the configuration
+ --dump-objects write icinga2.debug cache file for icinga2 object list
-e [ --errorlog ] arg log fatal errors to the specified log file (only
works in combination with --daemonize or
--close-stdio)
@@ -520,10 +521,9 @@ attributes. The command also shows where each of the attributes was modified and
provides debug information for further configuration problem analysis.
That way you can also identify which objects have been created from your [apply rules](17-language-reference.md#apply).
-Runtime modifications via the [REST API](12-icinga2-api.md#icinga2-api-config-objects)
-are not immediately updated. Furthermore there is a known issue with
+Configuration modifications are not immediately updated. Furthermore there is a known issue with
[group assign expressions](17-language-reference.md#group-assign) which are not reflected in the host object output.
-You need to restart Icinga 2 in order to update the `icinga2.debug` cache file.
+You need to run `icinga2 daemon -C --dump-objects` in order to update the `icinga2.debug` cache file.
More information can be found in the [troubleshooting](15-troubleshooting.md#troubleshooting-list-configuration-objects) section.
diff --git a/doc/15-troubleshooting.md b/doc/15-troubleshooting.md
index 12817e940..0baef6bc5 100644
--- a/doc/15-troubleshooting.md
+++ b/doc/15-troubleshooting.md
@@ -256,10 +256,9 @@ Found 1 Service objects.
[2014-10-15 14:27:19 +0200] information/cli: Parsed 175 objects.
```
-Runtime modifications via the [REST API](12-icinga2-api.md#icinga2-api-config-objects)
-are not immediately updated. Furthermore there is a known issue with
+Configuration modifications are not immediately updated. Furthermore there is a known issue with
[group assign expressions](17-language-reference.md#group-assign) which are not reflected in the host object output.
-You need to restart Icinga 2 in order to update the `icinga2.debug` cache file.
+You need to `icinga2 daemon -C --dump-objects` in order to update the `icinga2.debug` cache file.
### Apply rules do not match
diff --git a/lib/cli/daemoncommand.cpp b/lib/cli/daemoncommand.cpp
index a03976191..b92ab79a7 100644
--- a/lib/cli/daemoncommand.cpp
+++ b/lib/cli/daemoncommand.cpp
@@ -176,6 +176,7 @@ void DaemonCommand::InitParameters(boost::program_options::options_description&
("config,c", po::value >(), "parse a configuration file")
("no-config,z", "start without a configuration file")
("validate,C", "exit after validating the configuration")
+ ("dump-objects", "write icinga2.debug cache file for icinga2 object list")
("errorlog,e", po::value(), "log fatal errors to the specified log file (only works in combination with --daemonize or --close-stdio)")
#ifndef _WIN32
("daemonize,d", "detach from the controlling terminal")
@@ -218,6 +219,8 @@ static double GetDebugWorkerDelay()
}
#endif /* I2_DEBUG */
+static String l_ObjectsPath;
+
/**
* Do the actual work (config loading, ...)
*
@@ -248,7 +251,7 @@ int RunWorker(const std::vector& configs, bool closeConsoleLog = fa
{
std::vector newItems;
- if (!DaemonUtility::LoadConfigFiles(configs, newItems, Configuration::ObjectsPath, Configuration::VarsPath)) {
+ if (!DaemonUtility::LoadConfigFiles(configs, newItems, l_ObjectsPath, Configuration::VarsPath)) {
Log(LogCritical, "cli", "Config validation failed. Re-run with 'icinga2 daemon -C' after fixing the config.");
NotifyStatus("Config validation failed.");
return EXIT_FAILURE;
@@ -626,12 +629,21 @@ int DaemonCommand::Run(const po::variables_map& vm, const std::vector newItems;
- if (!DaemonUtility::LoadConfigFiles(configs, newItems, Configuration::ObjectsPath, Configuration::VarsPath)) {
+ if (!DaemonUtility::LoadConfigFiles(configs, newItems, l_ObjectsPath, Configuration::VarsPath)) {
Log(LogCritical, "cli", "Config validation failed. Re-run with 'icinga2 daemon -C' after fixing the config.");
return EXIT_FAILURE;
}
diff --git a/lib/cli/objectlistcommand.cpp b/lib/cli/objectlistcommand.cpp
index f931d8c25..4fb4c4a92 100644
--- a/lib/cli/objectlistcommand.cpp
+++ b/lib/cli/objectlistcommand.cpp
@@ -55,7 +55,7 @@ int ObjectListCommand::Run(const boost::program_options::variables_map& vm, cons
if (!Utility::PathExists(objectfile)) {
Log(LogCritical, "cli")
<< "Cannot open objects file '" << Configuration::ObjectsPath << "'.";
- Log(LogCritical, "cli", "Run 'icinga2 daemon -C' to validate config and generate the cache file.");
+ Log(LogCritical, "cli", "Run 'icinga2 daemon -C --dump-objects' to validate config and generate the cache file.");
return 1;
}
diff --git a/lib/config/configcompilercontext.cpp b/lib/config/configcompilercontext.cpp
index 666fe560e..35781a4e3 100644
--- a/lib/config/configcompilercontext.cpp
+++ b/lib/config/configcompilercontext.cpp
@@ -48,6 +48,9 @@ void ConfigCompilerContext::WriteObject(const Dictionary::Ptr& object)
void ConfigCompilerContext::CancelObjectsFile()
{
+ if (!m_ObjectsFP)
+ return;
+
delete m_ObjectsFP;
m_ObjectsFP = nullptr;
@@ -60,6 +63,9 @@ void ConfigCompilerContext::CancelObjectsFile()
void ConfigCompilerContext::FinishObjectsFile()
{
+ if (!m_ObjectsFP)
+ return;
+
delete m_ObjectsFP;
m_ObjectsFP = nullptr;
diff --git a/lib/config/configcompilercontext.hpp b/lib/config/configcompilercontext.hpp
index f02e26869..fa75fba51 100644
--- a/lib/config/configcompilercontext.hpp
+++ b/lib/config/configcompilercontext.hpp
@@ -22,6 +22,11 @@ public:
void CancelObjectsFile();
void FinishObjectsFile();
+ inline bool IsOpen() const noexcept
+ {
+ return m_ObjectsFP;
+ }
+
static ConfigCompilerContext *GetInstance();
private:
diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp
index d61509457..6dc61d8cb 100644
--- a/lib/config/configitem.cpp
+++ b/lib/config/configitem.cpp
@@ -285,25 +285,26 @@ ConfigObject::Ptr ConfigItem::Commit(bool discard)
BOOST_THROW_EXCEPTION(ValidationError(dobj, ex.GetPath(), "Circular references are not allowed"));
}
- Dictionary::Ptr persistentItem = new Dictionary({
- { "type", type->GetName() },
- { "name", GetName() },
- { "properties", serializedObject },
- { "debug_hints", dhint },
- { "debug_info", new Array({
- m_DebugInfo.Path,
- m_DebugInfo.FirstLine,
- m_DebugInfo.FirstColumn,
- m_DebugInfo.LastLine,
- m_DebugInfo.LastColumn,
- }) }
- });
+ if (ConfigCompilerContext::GetInstance()->IsOpen()) {
+ Dictionary::Ptr persistentItem = new Dictionary({
+ { "type", type->GetName() },
+ { "name", GetName() },
+ { "properties", serializedObject },
+ { "debug_hints", dhint },
+ { "debug_info", new Array({
+ m_DebugInfo.Path,
+ m_DebugInfo.FirstLine,
+ m_DebugInfo.FirstColumn,
+ m_DebugInfo.LastLine,
+ m_DebugInfo.LastColumn,
+ }) }
+ });
+
+ ConfigCompilerContext::GetInstance()->WriteObject(persistentItem);
+ }
dhint.reset();
- ConfigCompilerContext::GetInstance()->WriteObject(persistentItem);
- persistentItem.reset();
-
dobj->Register();
m_Object = dobj;