mirror of https://github.com/Icinga/icinga2.git
cluster: Rotate the log file when Icinga is started.
This commit is contained in:
parent
e05f270459
commit
558daf7b84
|
@ -44,6 +44,7 @@ void ClusterComponent::Start(void)
|
|||
|
||||
{
|
||||
ObjectLock olock(this);
|
||||
RotateLogFile();
|
||||
OpenLogFile();
|
||||
}
|
||||
|
||||
|
@ -89,6 +90,7 @@ void ClusterComponent::Stop(void)
|
|||
{
|
||||
ObjectLock olock(this);
|
||||
CloseLogFile();
|
||||
RotateLogFile();
|
||||
}
|
||||
|
||||
String ClusterComponent::GetCertificateFile(void) const
|
||||
|
@ -225,6 +227,7 @@ void ClusterComponent::RelayMessage(const Endpoint::Ptr& except, const Dictionar
|
|||
|
||||
if (m_LogMessageCount > 250000) {
|
||||
CloseLogFile();
|
||||
RotateLogFile();
|
||||
OpenLogFile();
|
||||
}
|
||||
}
|
||||
|
@ -278,11 +281,20 @@ void ClusterComponent::CloseLogFile(void)
|
|||
m_LogFile->Close();
|
||||
m_LogFile.reset();
|
||||
|
||||
if (m_LogMessageTimestamp != 0) {
|
||||
String oldpath = GetClusterDir() + "current";
|
||||
String newpath = GetClusterDir() + Convert::ToString(static_cast<int>(m_LogMessageTimestamp) + 1);
|
||||
(void) rename(oldpath.CStr(), newpath.CStr());
|
||||
}
|
||||
}
|
||||
|
||||
void ClusterComponent::RotateLogFile(void)
|
||||
{
|
||||
ASSERT(OwnsLock());
|
||||
|
||||
double ts = m_LogMessageTimestamp;
|
||||
|
||||
if (ts == 0)
|
||||
ts = Utility::GetTime();
|
||||
|
||||
String oldpath = GetClusterDir() + "current";
|
||||
String newpath = GetClusterDir() + Convert::ToString(static_cast<int>(ts) + 1);
|
||||
(void) rename(oldpath.CStr(), newpath.CStr());
|
||||
}
|
||||
|
||||
void ClusterComponent::LogGlobHandler(std::vector<int>& files, const String& file)
|
||||
|
@ -307,6 +319,7 @@ void ClusterComponent::ReplayLog(const Endpoint::Ptr& endpoint, const Stream::Pt
|
|||
ASSERT(OwnsLock());
|
||||
|
||||
CloseLogFile();
|
||||
RotateLogFile();
|
||||
|
||||
std::vector<int> files;
|
||||
Utility::Glob(GetClusterDir() + "*", boost::bind(&ClusterComponent::LogGlobHandler, boost::ref(files), _1));
|
||||
|
@ -934,6 +947,9 @@ void ClusterComponent::InternalSerialize(const Dictionary::Ptr& bag, int attribu
|
|||
bag->Set("bind_port", m_BindPort);
|
||||
bag->Set("peers", m_Peers);
|
||||
}
|
||||
|
||||
if (attributeTypes & Attribute_State)
|
||||
bag->Set("log_message_timestamp", m_LogMessageTimestamp);
|
||||
}
|
||||
|
||||
void ClusterComponent::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
|
||||
|
@ -947,4 +963,7 @@ void ClusterComponent::InternalDeserialize(const Dictionary::Ptr& bag, int attri
|
|||
m_BindPort = bag->Get("bind_port");
|
||||
m_Peers = bag->Get("peers");
|
||||
}
|
||||
|
||||
if (attributeTypes & Attribute_State)
|
||||
m_LogMessageTimestamp = bag->Get("log_message_timestamp");
|
||||
}
|
||||
|
|
|
@ -84,6 +84,7 @@ private:
|
|||
void RelayMessage(const Endpoint::Ptr& except, const Dictionary::Ptr& message, bool persistent);
|
||||
|
||||
void OpenLogFile(void);
|
||||
void RotateLogFile(void);
|
||||
void CloseLogFile(void);
|
||||
static void LogGlobHandler(std::vector<int>& files, const String& file);
|
||||
void ReplayLog(const Endpoint::Ptr& endpoint, const Stream::Ptr& stream);
|
||||
|
|
Loading…
Reference in New Issue