Make sure modified attributes are applied before calling the objects' Start method

refs #4696
This commit is contained in:
Gunnar Beutner 2017-05-03 11:59:51 +02:00
parent 163f48a223
commit 4134f7fe42
4 changed files with 22 additions and 19 deletions

View File

@ -284,7 +284,7 @@ int DaemonCommand::Run(const po::variables_map& vm, const std::vector<std::strin
upq.SetName("DaemonCommand::Run");
// 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.");
return EXIT_FAILURE;
}

View File

@ -21,6 +21,7 @@
#include "config/configcompilercontext.hpp"
#include "config/applyrule.hpp"
#include "config/objectrule.hpp"
#include "config/configcompiler.hpp"
#include "base/application.hpp"
#include "base/configtype.hpp"
#include "base/objectlock.hpp"
@ -573,11 +574,29 @@ bool ConfigItem::CommitItems(const ActivationContext::Ptr& context, WorkQueue& u
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;
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)
Log(LogInformation, "ConfigItem", "Triggering Start signal for config items");

View File

@ -70,7 +70,7 @@ public:
const String& name);
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);

View File

@ -103,22 +103,6 @@ int IcingaApplication::Main(void)
l_RetentionTimer->OnTimerExpired.connect(boost::bind(&IcingaApplication::DumpProgramState, this));
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();
Log(LogInformation, "IcingaApplication", "Icinga has shut down.");