Save program state when shutting down.

This commit is contained in:
Gunnar Beutner 2012-07-26 11:41:36 +02:00
parent 1eb25ad4e9
commit e56e493a00
2 changed files with 7 additions and 4 deletions

View File

@ -47,7 +47,7 @@ int IcingaApplication::Main(const vector<string>& args)
m_RetentionTimer = boost::make_shared<Timer>(); m_RetentionTimer = boost::make_shared<Timer>();
m_RetentionTimer->SetInterval(60); m_RetentionTimer->SetInterval(60);
m_RetentionTimer->OnTimerExpired.connect(boost::bind(&IcingaApplication::RetentionTimerHandler, this)); m_RetentionTimer->OnTimerExpired.connect(boost::bind(&IcingaApplication::DumpProgramState, this));
m_RetentionTimer->Start(); m_RetentionTimer->Start();
/* register handler for 'log' config objects */ /* register handler for 'log' config objects */
@ -225,13 +225,16 @@ int IcingaApplication::Main(const vector<string>& args)
RunEventLoop(); RunEventLoop();
DumpProgramState();
Logger::Write(LogInformation, "icinga", "Icinga shutting down."); Logger::Write(LogInformation, "icinga", "Icinga shutting down.");
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
void IcingaApplication::RetentionTimerHandler(void) { void IcingaApplication::DumpProgramState(void) {
ConfigObject::DumpObjects("retention.dat"); ConfigObject::DumpObjects("retention.dat.tmp");
rename("retention.dat.tmp", "retention.dat");
} }
void IcingaApplication::NewComponentHandler(const ConfigObject::Ptr& object) void IcingaApplication::NewComponentHandler(const ConfigObject::Ptr& object)

View File

@ -63,7 +63,7 @@ private:
Timer::Ptr m_RetentionTimer; Timer::Ptr m_RetentionTimer;
void RetentionTimerHandler(void); void DumpProgramState(void);
void NewComponentHandler(const ConfigObject::Ptr& object); void NewComponentHandler(const ConfigObject::Ptr& object);
void DeletedComponentHandler(const ConfigObject::Ptr& object); void DeletedComponentHandler(const ConfigObject::Ptr& object);