mirror of https://github.com/Icinga/icinga2.git
Make sure modified attributes are applied before calling the objects' Start method
refs #4696
This commit is contained in:
parent
163f48a223
commit
4134f7fe42
|
@ -284,7 +284,7 @@ int DaemonCommand::Run(const po::variables_map& vm, const std::vector<std::strin
|
||||||
upq.SetName("DaemonCommand::Run");
|
upq.SetName("DaemonCommand::Run");
|
||||||
|
|
||||||
// activate config only after daemonization: it starts threads and that is not compatible with fork()
|
// activate config only after daemonization: it starts threads and that is not compatible with fork()
|
||||||
if (!ConfigItem::ActivateItems(upq, newItems)) {
|
if (!ConfigItem::ActivateItems(upq, newItems, false, false, true)) {
|
||||||
Log(LogCritical, "cli", "Error activating configuration.");
|
Log(LogCritical, "cli", "Error activating configuration.");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "config/configcompilercontext.hpp"
|
#include "config/configcompilercontext.hpp"
|
||||||
#include "config/applyrule.hpp"
|
#include "config/applyrule.hpp"
|
||||||
#include "config/objectrule.hpp"
|
#include "config/objectrule.hpp"
|
||||||
|
#include "config/configcompiler.hpp"
|
||||||
#include "base/application.hpp"
|
#include "base/application.hpp"
|
||||||
#include "base/configtype.hpp"
|
#include "base/configtype.hpp"
|
||||||
#include "base/objectlock.hpp"
|
#include "base/objectlock.hpp"
|
||||||
|
@ -573,11 +574,29 @@ bool ConfigItem::CommitItems(const ActivationContext::Ptr& context, WorkQueue& u
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfigItem::ActivateItems(WorkQueue& upq, const std::vector<ConfigItem::Ptr>& newItems, bool runtimeCreated, bool silent)
|
bool ConfigItem::ActivateItems(WorkQueue& upq, const std::vector<ConfigItem::Ptr>& newItems, bool runtimeCreated, bool silent, bool withModAttrs)
|
||||||
{
|
{
|
||||||
static boost::mutex mtx;
|
static boost::mutex mtx;
|
||||||
boost::mutex::scoped_lock lock(mtx);
|
boost::mutex::scoped_lock lock(mtx);
|
||||||
|
|
||||||
|
if (withModAttrs) {
|
||||||
|
/* restore modified attributes */
|
||||||
|
if (Utility::PathExists(Application::GetModAttrPath())) {
|
||||||
|
Expression *expression = ConfigCompiler::CompileFile(Application::GetModAttrPath());
|
||||||
|
|
||||||
|
if (expression) {
|
||||||
|
try {
|
||||||
|
ScriptFrame frame;
|
||||||
|
expression->Evaluate(frame);
|
||||||
|
} catch (const std::exception& ex) {
|
||||||
|
Log(LogCritical, "config", DiagnosticInformation(ex));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
delete expression;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!silent)
|
if (!silent)
|
||||||
Log(LogInformation, "ConfigItem", "Triggering Start signal for config items");
|
Log(LogInformation, "ConfigItem", "Triggering Start signal for config items");
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ public:
|
||||||
const String& name);
|
const String& name);
|
||||||
|
|
||||||
static bool CommitItems(const ActivationContext::Ptr& context, WorkQueue& upq, std::vector<ConfigItem::Ptr>& newItems, bool silent = false);
|
static bool CommitItems(const ActivationContext::Ptr& context, WorkQueue& upq, std::vector<ConfigItem::Ptr>& newItems, bool silent = false);
|
||||||
static bool ActivateItems(WorkQueue& upq, const std::vector<ConfigItem::Ptr>& newItems, bool runtimeCreated = false, bool silent = false);
|
static bool ActivateItems(WorkQueue& upq, const std::vector<ConfigItem::Ptr>& newItems, bool runtimeCreated = false, bool silent = false, bool withModAttrs = false);
|
||||||
|
|
||||||
static bool RunWithActivationContext(const Function::Ptr& function);
|
static bool RunWithActivationContext(const Function::Ptr& function);
|
||||||
|
|
||||||
|
|
|
@ -103,22 +103,6 @@ int IcingaApplication::Main(void)
|
||||||
l_RetentionTimer->OnTimerExpired.connect(boost::bind(&IcingaApplication::DumpProgramState, this));
|
l_RetentionTimer->OnTimerExpired.connect(boost::bind(&IcingaApplication::DumpProgramState, this));
|
||||||
l_RetentionTimer->Start();
|
l_RetentionTimer->Start();
|
||||||
|
|
||||||
/* restore modified attributes */
|
|
||||||
if (Utility::PathExists(GetModAttrPath())) {
|
|
||||||
Expression *expression = ConfigCompiler::CompileFile(GetModAttrPath());
|
|
||||||
|
|
||||||
if (expression) {
|
|
||||||
try {
|
|
||||||
ScriptFrame frame;
|
|
||||||
expression->Evaluate(frame);
|
|
||||||
} catch (const std::exception& ex) {
|
|
||||||
Log(LogCritical, "config", DiagnosticInformation(ex));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
delete expression;
|
|
||||||
}
|
|
||||||
|
|
||||||
RunEventLoop();
|
RunEventLoop();
|
||||||
|
|
||||||
Log(LogInformation, "IcingaApplication", "Icinga has shut down.");
|
Log(LogInformation, "IcingaApplication", "Icinga has shut down.");
|
||||||
|
|
Loading…
Reference in New Issue