mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-28 16:14:09 +02:00
Only activate HARunOnce objects once there's a cluster connection
fixes #11765
This commit is contained in:
parent
a529725a92
commit
fc1168ed3e
@ -60,6 +60,7 @@ static bool l_InExceptionHandler = false;
|
|||||||
int Application::m_ArgC;
|
int Application::m_ArgC;
|
||||||
char **Application::m_ArgV;
|
char **Application::m_ArgV;
|
||||||
double Application::m_StartTime;
|
double Application::m_StartTime;
|
||||||
|
double Application::m_MainTime;
|
||||||
bool Application::m_ScriptDebuggerEnabled = false;
|
bool Application::m_ScriptDebuggerEnabled = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -885,6 +886,8 @@ int Application::Run(void)
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SetMainTime(Utility::GetTime());
|
||||||
|
|
||||||
return Main();
|
return Main();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1364,6 +1367,16 @@ void Application::SetStartTime(double ts)
|
|||||||
m_StartTime = ts;
|
m_StartTime = ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double Application::GetMainTime(void)
|
||||||
|
{
|
||||||
|
return m_MainTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::SetMainTime(double ts)
|
||||||
|
{
|
||||||
|
m_MainTime = ts;
|
||||||
|
}
|
||||||
|
|
||||||
bool Application::GetScriptDebuggerEnabled(void)
|
bool Application::GetScriptDebuggerEnabled(void)
|
||||||
{
|
{
|
||||||
return m_ScriptDebuggerEnabled;
|
return m_ScriptDebuggerEnabled;
|
||||||
|
@ -134,6 +134,9 @@ public:
|
|||||||
static double GetStartTime(void);
|
static double GetStartTime(void);
|
||||||
static void SetStartTime(double ts);
|
static void SetStartTime(double ts);
|
||||||
|
|
||||||
|
static double GetMainTime(void);
|
||||||
|
static void SetMainTime(double ts);
|
||||||
|
|
||||||
static bool GetScriptDebuggerEnabled(void);
|
static bool GetScriptDebuggerEnabled(void);
|
||||||
static void SetScriptDebuggerEnabled(bool enabled);
|
static void SetScriptDebuggerEnabled(bool enabled);
|
||||||
|
|
||||||
@ -167,6 +170,7 @@ private:
|
|||||||
static bool m_Debugging; /**< Whether debugging is enabled. */
|
static bool m_Debugging; /**< Whether debugging is enabled. */
|
||||||
static LogSeverity m_DebuggingSeverity; /**< Whether debugging severity is set. */
|
static LogSeverity m_DebuggingSeverity; /**< Whether debugging severity is set. */
|
||||||
static double m_StartTime;
|
static double m_StartTime;
|
||||||
|
static double m_MainTime;
|
||||||
static bool m_ScriptDebuggerEnabled;
|
static bool m_ScriptDebuggerEnabled;
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
|
@ -396,6 +396,7 @@ void ConfigObject::Activate(bool runtimeCreated)
|
|||||||
SetActive(true, true);
|
SetActive(true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (GetHAMode() == HARunEverywhere)
|
||||||
SetAuthority(true);
|
SetAuthority(true);
|
||||||
|
|
||||||
NotifyActive();
|
NotifyActive();
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include "cli/daemoncommand.hpp"
|
#include "cli/daemoncommand.hpp"
|
||||||
#include "cli/daemonutility.hpp"
|
#include "cli/daemonutility.hpp"
|
||||||
|
#include "remote/apilistener.hpp"
|
||||||
#include "config/configcompiler.hpp"
|
#include "config/configcompiler.hpp"
|
||||||
#include "config/configcompilercontext.hpp"
|
#include "config/configcompilercontext.hpp"
|
||||||
#include "config/configitembuilder.hpp"
|
#include "config/configitembuilder.hpp"
|
||||||
@ -302,5 +303,8 @@ int DaemonCommand::Run(const po::variables_map& vm, const std::vector<std::strin
|
|||||||
sigaction(SIGHUP, &sa, NULL);
|
sigaction(SIGHUP, &sa, NULL);
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
|
/* update object authority */
|
||||||
|
ApiListener::UpdateObjectAuthorityAsync();
|
||||||
|
|
||||||
return Application::GetInstance()->Run();
|
return Application::GetInstance()->Run();
|
||||||
}
|
}
|
||||||
|
@ -97,6 +97,9 @@ public:
|
|||||||
static Value ConfigDeleteObjectAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params);
|
static Value ConfigDeleteObjectAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params);
|
||||||
|
|
||||||
static Value HelloAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params);
|
static Value HelloAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params);
|
||||||
|
|
||||||
|
static void UpdateObjectAuthorityAsync(void);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void OnConfigLoaded(void) override;
|
virtual void OnConfigLoaded(void) override;
|
||||||
virtual void OnAllConfigLoaded(void) override;
|
virtual void OnAllConfigLoaded(void) override;
|
||||||
|
@ -36,42 +36,60 @@ static bool ObjectNameLessComparer(const ConfigObject::Ptr& a, const ConfigObjec
|
|||||||
|
|
||||||
static void AuthorityTimerHandler(void)
|
static void AuthorityTimerHandler(void)
|
||||||
{
|
{
|
||||||
ApiListener::Ptr listener = ApiListener::GetInstance();
|
|
||||||
|
|
||||||
if (!listener || !listener->IsActive())
|
|
||||||
return;
|
|
||||||
|
|
||||||
Zone::Ptr my_zone = Zone::GetLocalZone();
|
Zone::Ptr my_zone = Zone::GetLocalZone();
|
||||||
if (!my_zone)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Endpoint::Ptr my_endpoint = Endpoint::GetLocalEndpoint();
|
|
||||||
|
|
||||||
std::vector<Endpoint::Ptr> endpoints;
|
std::vector<Endpoint::Ptr> endpoints;
|
||||||
|
Endpoint::Ptr my_endpoint;
|
||||||
|
|
||||||
|
if (my_zone) {
|
||||||
|
my_endpoint = Endpoint::GetLocalEndpoint();
|
||||||
|
|
||||||
|
int num_total = 0;
|
||||||
|
|
||||||
BOOST_FOREACH(const Endpoint::Ptr& endpoint, my_zone->GetEndpoints()) {
|
BOOST_FOREACH(const Endpoint::Ptr& endpoint, my_zone->GetEndpoints()) {
|
||||||
if (!endpoint->GetConnected() && endpoint != my_endpoint)
|
num_total++;
|
||||||
|
|
||||||
|
if (endpoint != my_endpoint && !endpoint->GetConnected())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
endpoints.push_back(endpoint);
|
endpoints.push_back(endpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double mainTime = Application::GetMainTime();
|
||||||
|
|
||||||
|
if (num_total > 1 && endpoints.size() <= 1 && (mainTime == 0 || Utility::GetTime() - mainTime < 60))
|
||||||
|
return;
|
||||||
|
|
||||||
std::sort(endpoints.begin(), endpoints.end(), ObjectNameLessComparer);
|
std::sort(endpoints.begin(), endpoints.end(), ObjectNameLessComparer);
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_FOREACH(const ConfigType::Ptr& type, ConfigType::GetTypes()) {
|
BOOST_FOREACH(const ConfigType::Ptr& type, ConfigType::GetTypes()) {
|
||||||
BOOST_FOREACH(const ConfigObject::Ptr& object, type->GetObjects()) {
|
BOOST_FOREACH(const ConfigObject::Ptr& object, type->GetObjects()) {
|
||||||
Endpoint::Ptr endpoint = endpoints[Utility::SDBM(object->GetName()) % endpoints.size()];
|
if (object->GetHAMode() != HARunOnce)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (object->GetHAMode() == HARunOnce)
|
bool authority;
|
||||||
object->SetAuthority(endpoint == my_endpoint);
|
|
||||||
|
if (!my_zone)
|
||||||
|
authority = true;
|
||||||
|
else
|
||||||
|
authority = endpoints[Utility::SDBM(object->GetName()) % endpoints.size()] == my_endpoint;
|
||||||
|
|
||||||
|
object->SetAuthority(authority);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ApiListener::UpdateObjectAuthorityAsync(void)
|
||||||
|
{
|
||||||
|
l_AuthorityTimer->Reschedule(0);
|
||||||
|
}
|
||||||
|
|
||||||
static void StaticInitialize(void)
|
static void StaticInitialize(void)
|
||||||
{
|
{
|
||||||
l_AuthorityTimer = new Timer();
|
l_AuthorityTimer = new Timer();
|
||||||
l_AuthorityTimer->OnTimerExpired.connect(boost::bind(&AuthorityTimerHandler));
|
l_AuthorityTimer->OnTimerExpired.connect(boost::bind(&AuthorityTimerHandler));
|
||||||
l_AuthorityTimer->SetInterval(30);
|
l_AuthorityTimer->SetInterval(15);
|
||||||
l_AuthorityTimer->Start();
|
l_AuthorityTimer->Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user