mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-27 07:34:15 +02:00
icinga2 daemon -C: write icinga2.debug only if --dump-objects given
to save config (re)load time.
This commit is contained in:
parent
a6b05059ab
commit
0767c6ef87
@ -430,6 +430,7 @@ Command options:
|
|||||||
-c [ --config ] arg parse a configuration file
|
-c [ --config ] arg parse a configuration file
|
||||||
-z [ --no-config ] start without a configuration file
|
-z [ --no-config ] start without a configuration file
|
||||||
-C [ --validate ] exit after validating the configuration
|
-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
|
-e [ --errorlog ] arg log fatal errors to the specified log file (only
|
||||||
works in combination with --daemonize or
|
works in combination with --daemonize or
|
||||||
--close-stdio)
|
--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.
|
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).
|
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)
|
Configuration modifications are not immediately updated. Furthermore there is a known issue with
|
||||||
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.
|
[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.
|
More information can be found in the [troubleshooting](15-troubleshooting.md#troubleshooting-list-configuration-objects) section.
|
||||||
|
|
||||||
|
@ -256,10 +256,9 @@ Found 1 Service objects.
|
|||||||
[2014-10-15 14:27:19 +0200] information/cli: Parsed 175 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)
|
Configuration modifications are not immediately updated. Furthermore there is a known issue with
|
||||||
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.
|
[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 <a id="apply-rules-do-not-match"></a>
|
### Apply rules do not match <a id="apply-rules-do-not-match"></a>
|
||||||
|
|
||||||
|
@ -176,6 +176,7 @@ void DaemonCommand::InitParameters(boost::program_options::options_description&
|
|||||||
("config,c", po::value<std::vector<std::string> >(), "parse a configuration file")
|
("config,c", po::value<std::vector<std::string> >(), "parse a configuration file")
|
||||||
("no-config,z", "start without a configuration file")
|
("no-config,z", "start without a configuration file")
|
||||||
("validate,C", "exit after validating the configuration")
|
("validate,C", "exit after validating the configuration")
|
||||||
|
("dump-objects", "write icinga2.debug cache file for icinga2 object list")
|
||||||
("errorlog,e", po::value<std::string>(), "log fatal errors to the specified log file (only works in combination with --daemonize or --close-stdio)")
|
("errorlog,e", po::value<std::string>(), "log fatal errors to the specified log file (only works in combination with --daemonize or --close-stdio)")
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
("daemonize,d", "detach from the controlling terminal")
|
("daemonize,d", "detach from the controlling terminal")
|
||||||
@ -218,6 +219,8 @@ static double GetDebugWorkerDelay()
|
|||||||
}
|
}
|
||||||
#endif /* I2_DEBUG */
|
#endif /* I2_DEBUG */
|
||||||
|
|
||||||
|
static String l_ObjectsPath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do the actual work (config loading, ...)
|
* Do the actual work (config loading, ...)
|
||||||
*
|
*
|
||||||
@ -248,7 +251,7 @@ int RunWorker(const std::vector<std::string>& configs, bool closeConsoleLog = fa
|
|||||||
{
|
{
|
||||||
std::vector<ConfigItem::Ptr> newItems;
|
std::vector<ConfigItem::Ptr> 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.");
|
Log(LogCritical, "cli", "Config validation failed. Re-run with 'icinga2 daemon -C' after fixing the config.");
|
||||||
NotifyStatus("Config validation failed.");
|
NotifyStatus("Config validation failed.");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -626,12 +629,21 @@ int DaemonCommand::Run(const po::variables_map& vm, const std::vector<std::strin
|
|||||||
configs.push_back(configDir + "/icinga2.conf");
|
configs.push_back(configDir + "/icinga2.conf");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (vm.count("dump-objects")) {
|
||||||
|
if (!vm.count("validate")) {
|
||||||
|
Log(LogCritical, "cli", "--dump-objects is not allowed without -C");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
l_ObjectsPath = Configuration::ObjectsPath;
|
||||||
|
}
|
||||||
|
|
||||||
if (vm.count("validate")) {
|
if (vm.count("validate")) {
|
||||||
Log(LogInformation, "cli", "Loading configuration file(s).");
|
Log(LogInformation, "cli", "Loading configuration file(s).");
|
||||||
|
|
||||||
std::vector<ConfigItem::Ptr> newItems;
|
std::vector<ConfigItem::Ptr> 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.");
|
Log(LogCritical, "cli", "Config validation failed. Re-run with 'icinga2 daemon -C' after fixing the config.");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ int ObjectListCommand::Run(const boost::program_options::variables_map& vm, cons
|
|||||||
if (!Utility::PathExists(objectfile)) {
|
if (!Utility::PathExists(objectfile)) {
|
||||||
Log(LogCritical, "cli")
|
Log(LogCritical, "cli")
|
||||||
<< "Cannot open objects file '" << Configuration::ObjectsPath << "'.";
|
<< "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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +48,9 @@ void ConfigCompilerContext::WriteObject(const Dictionary::Ptr& object)
|
|||||||
|
|
||||||
void ConfigCompilerContext::CancelObjectsFile()
|
void ConfigCompilerContext::CancelObjectsFile()
|
||||||
{
|
{
|
||||||
|
if (!m_ObjectsFP)
|
||||||
|
return;
|
||||||
|
|
||||||
delete m_ObjectsFP;
|
delete m_ObjectsFP;
|
||||||
m_ObjectsFP = nullptr;
|
m_ObjectsFP = nullptr;
|
||||||
|
|
||||||
@ -60,6 +63,9 @@ void ConfigCompilerContext::CancelObjectsFile()
|
|||||||
|
|
||||||
void ConfigCompilerContext::FinishObjectsFile()
|
void ConfigCompilerContext::FinishObjectsFile()
|
||||||
{
|
{
|
||||||
|
if (!m_ObjectsFP)
|
||||||
|
return;
|
||||||
|
|
||||||
delete m_ObjectsFP;
|
delete m_ObjectsFP;
|
||||||
m_ObjectsFP = nullptr;
|
m_ObjectsFP = nullptr;
|
||||||
|
|
||||||
|
@ -22,6 +22,11 @@ public:
|
|||||||
void CancelObjectsFile();
|
void CancelObjectsFile();
|
||||||
void FinishObjectsFile();
|
void FinishObjectsFile();
|
||||||
|
|
||||||
|
inline bool IsOpen() const noexcept
|
||||||
|
{
|
||||||
|
return m_ObjectsFP;
|
||||||
|
}
|
||||||
|
|
||||||
static ConfigCompilerContext *GetInstance();
|
static ConfigCompilerContext *GetInstance();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -285,6 +285,7 @@ ConfigObject::Ptr ConfigItem::Commit(bool discard)
|
|||||||
BOOST_THROW_EXCEPTION(ValidationError(dobj, ex.GetPath(), "Circular references are not allowed"));
|
BOOST_THROW_EXCEPTION(ValidationError(dobj, ex.GetPath(), "Circular references are not allowed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ConfigCompilerContext::GetInstance()->IsOpen()) {
|
||||||
Dictionary::Ptr persistentItem = new Dictionary({
|
Dictionary::Ptr persistentItem = new Dictionary({
|
||||||
{ "type", type->GetName() },
|
{ "type", type->GetName() },
|
||||||
{ "name", GetName() },
|
{ "name", GetName() },
|
||||||
@ -299,10 +300,10 @@ ConfigObject::Ptr ConfigItem::Commit(bool discard)
|
|||||||
}) }
|
}) }
|
||||||
});
|
});
|
||||||
|
|
||||||
dhint.reset();
|
|
||||||
|
|
||||||
ConfigCompilerContext::GetInstance()->WriteObject(persistentItem);
|
ConfigCompilerContext::GetInstance()->WriteObject(persistentItem);
|
||||||
persistentItem.reset();
|
}
|
||||||
|
|
||||||
|
dhint.reset();
|
||||||
|
|
||||||
dobj->Register();
|
dobj->Register();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user