mirror of https://github.com/Icinga/icinga2.git
Fix: ::Start must be called after restoring the state file.
Fixes #4654
This commit is contained in:
parent
8683a0834f
commit
f134ed61bc
|
@ -85,6 +85,9 @@ static bool LoadConfigFiles(bool validateOnly)
|
||||||
if (validateOnly)
|
if (validateOnly)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
/* restore the previous program state */
|
||||||
|
DynamicObject::RestoreObjects(Application::GetStatePath());
|
||||||
|
|
||||||
ConfigItem::ActivateItems();
|
ConfigItem::ActivateItems();
|
||||||
|
|
||||||
ConfigItem::DiscardItems();
|
ConfigItem::DiscardItems();
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "base/objectlock.h"
|
#include "base/objectlock.h"
|
||||||
#include "base/utility.h"
|
#include "base/utility.h"
|
||||||
#include "base/debug.h"
|
#include "base/debug.h"
|
||||||
|
#include "base/scriptvariable.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <boost/algorithm/string/classification.hpp>
|
#include <boost/algorithm/string/classification.hpp>
|
||||||
#include <boost/thread/thread.hpp>
|
#include <boost/thread/thread.hpp>
|
||||||
|
@ -620,6 +621,22 @@ void Application::SetPkgDataDir(const String& path)
|
||||||
m_PkgDataDir = path;
|
m_PkgDataDir = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the path for the state file.
|
||||||
|
*
|
||||||
|
* @returns The path.
|
||||||
|
*/
|
||||||
|
String Application::GetStatePath(void)
|
||||||
|
{
|
||||||
|
String statePath = ScriptVariable::Get("IcingaStatePath");
|
||||||
|
|
||||||
|
|
||||||
|
if (statePath.IsEmpty())
|
||||||
|
return GetLocalStateDir() + "/lib/icinga2/icinga2.state";
|
||||||
|
else
|
||||||
|
return statePath;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the global thread pool.
|
* Returns the global thread pool.
|
||||||
*
|
*
|
||||||
|
|
|
@ -80,6 +80,8 @@ public:
|
||||||
static String GetPkgDataDir(void);
|
static String GetPkgDataDir(void);
|
||||||
static void SetPkgDataDir(const String& path);
|
static void SetPkgDataDir(const String& path);
|
||||||
|
|
||||||
|
static String GetStatePath(void);
|
||||||
|
|
||||||
static ThreadPool& GetTP(void);
|
static ThreadPool& GetTP(void);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -276,8 +276,10 @@ void DynamicObject::RestoreObjects(const String& filename, int attributeTypes)
|
||||||
|
|
||||||
DynamicObject::Ptr object = dt->GetObject(name);
|
DynamicObject::Ptr object = dt->GetObject(name);
|
||||||
|
|
||||||
if (object)
|
if (object) {
|
||||||
|
ASSERT(!object->IsActive());
|
||||||
object->Deserialize(update, attributeTypes);
|
object->Deserialize(update, attributeTypes);
|
||||||
|
}
|
||||||
|
|
||||||
restored++;
|
restored++;
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -51,9 +51,6 @@ int IcingaApplication::Main(void)
|
||||||
|
|
||||||
UpdatePidFile(GetPidPath());
|
UpdatePidFile(GetPidPath());
|
||||||
|
|
||||||
/* restore the previous program state */
|
|
||||||
DynamicObject::RestoreObjects(GetStatePath());
|
|
||||||
|
|
||||||
/* periodically dump the program state */
|
/* periodically dump the program state */
|
||||||
l_RetentionTimer = boost::make_shared<Timer>();
|
l_RetentionTimer = boost::make_shared<Timer>();
|
||||||
l_RetentionTimer->SetInterval(300);
|
l_RetentionTimer->SetInterval(300);
|
||||||
|
@ -99,16 +96,6 @@ String IcingaApplication::GetPidPath(void) const
|
||||||
return m_PidPath;
|
return m_PidPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
String IcingaApplication::GetStatePath(void) const
|
|
||||||
{
|
|
||||||
ObjectLock olock(this);
|
|
||||||
|
|
||||||
if (m_StatePath.IsEmpty())
|
|
||||||
return Application::GetLocalStateDir() + "/lib/icinga2/icinga2.state";
|
|
||||||
else
|
|
||||||
return m_StatePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
Dictionary::Ptr IcingaApplication::GetMacros(void) const
|
Dictionary::Ptr IcingaApplication::GetMacros(void) const
|
||||||
{
|
{
|
||||||
ObjectLock olock(this);
|
ObjectLock olock(this);
|
||||||
|
@ -160,7 +147,6 @@ void IcingaApplication::InternalSerialize(const Dictionary::Ptr& bag, int attrib
|
||||||
|
|
||||||
if (attributeTypes & Attribute_Config) {
|
if (attributeTypes & Attribute_Config) {
|
||||||
bag->Set("pid_path", m_PidPath);
|
bag->Set("pid_path", m_PidPath);
|
||||||
bag->Set("state_path", m_StatePath);
|
|
||||||
bag->Set("macros", m_Macros);
|
bag->Set("macros", m_Macros);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -171,7 +157,6 @@ void IcingaApplication::InternalDeserialize(const Dictionary::Ptr& bag, int attr
|
||||||
|
|
||||||
if (attributeTypes & Attribute_Config) {
|
if (attributeTypes & Attribute_Config) {
|
||||||
m_PidPath = bag->Get("pid_path");
|
m_PidPath = bag->Get("pid_path");
|
||||||
m_StatePath = bag->Get("state_path");
|
|
||||||
m_Macros = bag->Get("macros");
|
m_Macros = bag->Get("macros");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,6 @@ public:
|
||||||
static IcingaApplication::Ptr GetInstance(void);
|
static IcingaApplication::Ptr GetInstance(void);
|
||||||
|
|
||||||
String GetPidPath(void) const;
|
String GetPidPath(void) const;
|
||||||
String GetStatePath(void) const;
|
|
||||||
Dictionary::Ptr GetMacros(void) const;
|
Dictionary::Ptr GetMacros(void) const;
|
||||||
|
|
||||||
double GetStartTime(void) const;
|
double GetStartTime(void) const;
|
||||||
|
@ -56,7 +55,6 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
String m_PidPath;
|
String m_PidPath;
|
||||||
String m_StatePath;
|
|
||||||
Dictionary::Ptr m_Macros;
|
Dictionary::Ptr m_Macros;
|
||||||
|
|
||||||
double m_StartTime;
|
double m_StartTime;
|
||||||
|
|
Loading…
Reference in New Issue