Skip to content

Commit

Permalink
Share "Last reload attempt failed" time across Icinga process tree on…
Browse files Browse the repository at this point in the history
… *nix

... as only the umbrella process knows that time,
but the icinga check running in the main process also needs to know it.

refs #8428
  • Loading branch information
Al2Klimov committed May 5, 2023
1 parent 3d90b76 commit a6c82de
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/base/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ int Application::m_ArgC;
char **Application::m_ArgV;
double Application::m_StartTime;
bool Application::m_ScriptDebuggerEnabled = false;
double Application::m_LastReloadFailed;

#ifdef _WIN32
double Application::m_LastReloadFailed = 0;
#else /* _WIN32 */
SharedMemory<Application::AtomicTs> Application::m_LastReloadFailed (0);
#endif /* _WIN32 */

#ifdef _WIN32
static LPTOP_LEVEL_EXCEPTION_FILTER l_DefaultUnhandledExceptionFilter = nullptr;
Expand Down Expand Up @@ -1208,12 +1213,20 @@ void Application::SetScriptDebuggerEnabled(bool enabled)

double Application::GetLastReloadFailed()
{
#ifdef _WIN32
return m_LastReloadFailed;
#else /* _WIN32 */
return m_LastReloadFailed.Get().load();
#endif /* _WIN32 */
}

void Application::SetLastReloadFailed(double ts)
{
#ifdef _WIN32
m_LastReloadFailed = ts;
#else /* _WIN32 */
m_LastReloadFailed.Get().store(ts);
#endif /* _WIN32 */
}

void Application::ValidateName(const Lazy<String>& lvalue, const ValidationUtils& utils)
Expand Down
8 changes: 8 additions & 0 deletions lib/base/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
#define APPLICATION_H

#include "base/i2-base.hpp"
#include "base/atomic.hpp"
#include "base/application-ti.hpp"
#include "base/logger.hpp"
#include "base/configuration.hpp"
#include "base/shared-memory.hpp"
#include <iosfwd>

namespace icinga
Expand Down Expand Up @@ -137,7 +139,13 @@ class Application : public ObjectImpl<Application> {
static double m_StartTime;
static double m_MainTime;
static bool m_ScriptDebuggerEnabled;
#ifdef _WIN32
static double m_LastReloadFailed;
#else /* _WIN32 */
typedef Atomic<double> AtomicTs;
static_assert(AtomicTs::is_always_lock_free);
static SharedMemory<AtomicTs> m_LastReloadFailed;
#endif /* _WIN32 */

#ifdef _WIN32
static BOOL WINAPI CtrlHandler(DWORD type);
Expand Down
2 changes: 2 additions & 0 deletions lib/cli/daemoncommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,13 +813,15 @@ int DaemonCommand::Run(const po::variables_map& vm, const std::vector<std::strin
break;
case -2:
Log(LogCritical, "Application", "Found error in config: reloading aborted");
Application::SetLastReloadFailed(Utility::GetTime());
break;
default:
Log(LogInformation, "Application")
<< "Reload done, old process shutting down. Child process with PID '" << nextWorker << "' is taking over.";

NotifyStatus("Shutting down old instance...");

Application::SetLastReloadFailed(0);
(void)kill(currentWorker, SIGTERM);

{
Expand Down

0 comments on commit a6c82de

Please sign in to comment.