icinga2/lib/base/application.hpp

161 lines
4.0 KiB
C++
Raw Normal View History

/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
#ifndef APPLICATION_H
#define APPLICATION_H
2012-03-28 13:24:49 +02:00
2014-05-25 16:23:35 +02:00
#include "base/i2-base.hpp"
2018-01-18 13:50:38 +01:00
#include "base/application-ti.hpp"
2014-10-19 14:21:12 +02:00
#include "base/logger.hpp"
2018-08-09 15:37:23 +02:00
#include "base/configuration.hpp"
2018-01-04 18:24:45 +01:00
#include <iosfwd>
2013-03-16 21:18:53 +01:00
namespace icinga
{
2018-01-04 18:24:45 +01:00
class ThreadPool;
/**
* Abstract base class for applications.
2012-05-18 22:21:28 +02:00
*
* @ingroup base
*/
2017-12-31 07:22:16 +01:00
class Application : public ObjectImpl<Application> {
public:
2014-11-03 00:44:04 +01:00
DECLARE_OBJECT(Application);
static boost::signals2::signal<void ()> OnReopenLogs;
2014-05-22 11:22:30 +02:00
~Application() override;
2012-03-28 13:24:49 +02:00
static void InitializeBase();
static void UninitializeBase();
static Application::Ptr GetInstance();
static void Exit(int rc);
2014-08-04 16:26:17 +02:00
int Run();
2012-09-17 14:47:43 +02:00
/**
* Starts the application.
*
* @returns The exit code of the application.
*/
virtual int Main() = 0;
2012-03-28 13:24:49 +02:00
static void SetResourceLimits();
static int GetArgC();
static void SetArgC(int argc);
static char **GetArgV();
static void SetArgV(char **argv);
static void InstallExceptionHandlers();
static void RequestShutdown();
static void RequestRestart();
static void RequestReopenLogs();
#ifndef _WIN32
static void SetUmbrellaProcess(pid_t pid);
#endif /* _WIN32 */
static bool IsShuttingDown();
static bool IsRestarting();
static void SetDebuggingSeverity(LogSeverity severity);
static LogSeverity GetDebuggingSeverity();
2018-01-04 18:24:45 +01:00
void UpdatePidFile(const String& filename);
void UpdatePidFile(const String& filename, pid_t pid);
void ClosePidFile(bool unlink);
static pid_t ReadPidFile(const String& filename);
static String GetExePath(const String& argv0);
#ifdef _WIN32
static bool IsProcessElevated();
#endif /* _WIN32 */
static int GetDefaultRLimitFiles();
static int GetDefaultRLimitProcesses();
static int GetDefaultRLimitStack();
static double GetReloadTimeout();
static ThreadPool& GetTP();
2013-02-15 06:47:26 +01:00
static String GetAppVersion();
static String GetAppSpecVersion();
static String GetAppEnvironment();
static void SetAppEnvironment(const String& name);
static double GetStartTime();
2013-10-26 09:41:45 +02:00
static void SetStartTime(double ts);
2020-01-31 16:49:49 +01:00
static double GetUptime();
static bool GetScriptDebuggerEnabled();
static void SetScriptDebuggerEnabled(bool enabled);
static double GetLastReloadFailed();
static void SetLastReloadFailed(double ts);
static void DisplayInfoMessage(std::ostream& os, bool skipVersion = false);
protected:
void OnConfigLoaded() override;
void Stop(bool runtimeRemoved) override;
void RunEventLoop();
pid_t StartReloadProcess();
virtual void OnShutdown();
2014-08-04 16:26:17 +02:00
void ValidateName(const Lazy<String>& lvalue, const ValidationUtils& utils) final;
private:
static Application::Ptr m_Instance; /**< The application instance. */
static bool m_ShuttingDown; /**< Whether the application is in the process of shutting down. */
static bool m_RequestRestart; /**< A restart was requested through SIGHUP */
static pid_t m_ReloadProcess; /**< The PID of a subprocess doing a reload, only valid when l_Restarting==true */
2014-05-22 11:22:30 +02:00
static bool m_RequestReopenLogs; /**< Whether we should re-open log files. */
#ifndef _WIN32
2019-07-16 11:11:10 +02:00
static pid_t m_UmbrellaProcess; /**< The PID of the Icinga umbrella process */
#endif /* _WIN32 */
static int m_ArgC; /**< The number of command-line arguments. */
static char **m_ArgV; /**< Command-line arguments. */
2019-07-15 16:08:08 +02:00
FILE *m_PidFile = nullptr; /**< The PID file */
static bool m_Debugging; /**< Whether debugging is enabled. */
static LogSeverity m_DebuggingSeverity; /**< Whether debugging severity is set. */
2013-10-26 09:41:45 +02:00
static double m_StartTime;
static double m_MainTime;
static bool m_ScriptDebuggerEnabled;
static double m_LastReloadFailed;
2019-07-12 13:45:54 +02:00
#ifdef _WIN32
static BOOL WINAPI CtrlHandler(DWORD type);
static LONG WINAPI SEHUnhandledExceptionFilter(PEXCEPTION_POINTERS exi);
#endif /* _WIN32 */
static void DisplayBugMessage(std::ostream& os);
static void SigAbrtHandler(int signum);
2014-05-22 11:22:30 +02:00
static void SigUsr1Handler(int signum);
static void ExceptionHandler();
static String GetCrashReportFilename();
static void AttachDebugger(const String& filename, bool interactive);
2012-03-28 13:24:49 +02:00
};
2012-04-22 16:45:31 +02:00
}
2012-03-28 13:24:49 +02:00
#endif /* APPLICATION_H */