Fix: ::Start must be called after restoring the state file.

Fixes #4654
This commit is contained in:
Gunnar Beutner 2013-08-29 10:17:12 +02:00
parent 8683a0834f
commit f134ed61bc
7 changed files with 298 additions and 290 deletions

View File

@ -85,6 +85,9 @@ static bool LoadConfigFiles(bool validateOnly)
if (validateOnly)
return true;
/* restore the previous program state */
DynamicObject::RestoreObjects(Application::GetStatePath());
ConfigItem::ActivateItems();
ConfigItem::DiscardItems();

View File

@ -25,6 +25,7 @@
#include "base/objectlock.h"
#include "base/utility.h"
#include "base/debug.h"
#include "base/scriptvariable.h"
#include <sstream>
#include <boost/algorithm/string/classification.hpp>
#include <boost/thread/thread.hpp>
@ -620,6 +621,22 @@ void Application::SetPkgDataDir(const String& 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.
*

View File

@ -80,6 +80,8 @@ public:
static String GetPkgDataDir(void);
static void SetPkgDataDir(const String& path);
static String GetStatePath(void);
static ThreadPool& GetTP(void);
protected:

View File

@ -276,8 +276,10 @@ void DynamicObject::RestoreObjects(const String& filename, int attributeTypes)
DynamicObject::Ptr object = dt->GetObject(name);
if (object)
if (object) {
ASSERT(!object->IsActive());
object->Deserialize(update, attributeTypes);
}
restored++;
}

File diff suppressed because it is too large Load Diff

View File

@ -51,9 +51,6 @@ int IcingaApplication::Main(void)
UpdatePidFile(GetPidPath());
/* restore the previous program state */
DynamicObject::RestoreObjects(GetStatePath());
/* periodically dump the program state */
l_RetentionTimer = boost::make_shared<Timer>();
l_RetentionTimer->SetInterval(300);
@ -99,16 +96,6 @@ String IcingaApplication::GetPidPath(void) const
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
{
ObjectLock olock(this);
@ -160,7 +147,6 @@ void IcingaApplication::InternalSerialize(const Dictionary::Ptr& bag, int attrib
if (attributeTypes & Attribute_Config) {
bag->Set("pid_path", m_PidPath);
bag->Set("state_path", m_StatePath);
bag->Set("macros", m_Macros);
}
}
@ -171,7 +157,6 @@ void IcingaApplication::InternalDeserialize(const Dictionary::Ptr& bag, int attr
if (attributeTypes & Attribute_Config) {
m_PidPath = bag->Get("pid_path");
m_StatePath = bag->Get("state_path");
m_Macros = bag->Get("macros");
}
}

View File

@ -43,7 +43,6 @@ public:
static IcingaApplication::Ptr GetInstance(void);
String GetPidPath(void) const;
String GetStatePath(void) const;
Dictionary::Ptr GetMacros(void) const;
double GetStartTime(void) const;
@ -56,7 +55,6 @@ protected:
private:
String m_PidPath;
String m_StatePath;
Dictionary::Ptr m_Macros;
double m_StartTime;