mirror of https://github.com/Icinga/icinga2.git
parent
8b516f0c08
commit
f0c763465b
|
@ -45,6 +45,14 @@ static po::variables_map g_AppParams;
|
||||||
|
|
||||||
REGISTER_CLICOMMAND("daemon", DaemonCommand);
|
REGISTER_CLICOMMAND("daemon", DaemonCommand);
|
||||||
|
|
||||||
|
static inline
|
||||||
|
void NotifyStatus(const char* status)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_SYSTEMD
|
||||||
|
(void)sd_notifyf(0, "STATUS=%s", status);
|
||||||
|
#endif /* HAVE_SYSTEMD */
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Daemonize(). On error, this function logs by itself and exits (i.e. does not return).
|
* Daemonize(). On error, this function logs by itself and exits (i.e. does not return).
|
||||||
*
|
*
|
||||||
|
@ -235,12 +243,14 @@ int RunWorker(const std::vector<std::string>& configs, bool closeConsoleLog = fa
|
||||||
#endif /* I2_DEBUG */
|
#endif /* I2_DEBUG */
|
||||||
|
|
||||||
Log(LogInformation, "cli", "Loading configuration file(s).");
|
Log(LogInformation, "cli", "Loading configuration file(s).");
|
||||||
|
NotifyStatus("Loading configuration file(s)...");
|
||||||
|
|
||||||
{
|
{
|
||||||
std::vector<ConfigItem::Ptr> newItems;
|
std::vector<ConfigItem::Ptr> newItems;
|
||||||
|
|
||||||
if (!DaemonUtility::LoadConfigFiles(configs, newItems, Configuration::ObjectsPath, Configuration::VarsPath)) {
|
if (!DaemonUtility::LoadConfigFiles(configs, newItems, Configuration::ObjectsPath, Configuration::VarsPath)) {
|
||||||
Log(LogCritical, "cli", "Config validation failed. Re-run with 'icinga2 daemon -C' after fixing the config.");
|
Log(LogCritical, "cli", "Config validation failed. Re-run with 'icinga2 daemon -C' after fixing the config.");
|
||||||
|
NotifyStatus("Config validation failed.");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,6 +263,8 @@ int RunWorker(const std::vector<std::string>& configs, bool closeConsoleLog = fa
|
||||||
Log(LogNotice, "cli")
|
Log(LogNotice, "cli")
|
||||||
<< "Waiting for the umbrella process to let us doing the actual work";
|
<< "Waiting for the umbrella process to let us doing the actual work";
|
||||||
|
|
||||||
|
NotifyStatus("Waiting for the umbrella process to let us doing the actual work...");
|
||||||
|
|
||||||
if (closeConsoleLog) {
|
if (closeConsoleLog) {
|
||||||
CloseStdIO(stderrFile);
|
CloseStdIO(stderrFile);
|
||||||
Logger::DisableConsoleLog();
|
Logger::DisableConsoleLog();
|
||||||
|
@ -266,18 +278,28 @@ int RunWorker(const std::vector<std::string>& configs, bool closeConsoleLog = fa
|
||||||
<< "The umbrella process let us continuing";
|
<< "The umbrella process let us continuing";
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
|
NotifyStatus("Restoring the previous program state...");
|
||||||
|
|
||||||
/* restore the previous program state */
|
/* restore the previous program state */
|
||||||
try {
|
try {
|
||||||
ConfigObject::RestoreObjects(Configuration::StatePath);
|
ConfigObject::RestoreObjects(Configuration::StatePath);
|
||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
Log(LogCritical, "cli")
|
Log(LogCritical, "cli")
|
||||||
<< "Failed to restore state file: " << DiagnosticInformation(ex);
|
<< "Failed to restore state file: " << DiagnosticInformation(ex);
|
||||||
|
|
||||||
|
NotifyStatus("Failed to restore state file.");
|
||||||
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NotifyStatus("Activating config objects...");
|
||||||
|
|
||||||
// activate config only after daemonization: it starts threads and that is not compatible with fork()
|
// activate config only after daemonization: it starts threads and that is not compatible with fork()
|
||||||
if (!ConfigItem::ActivateItems(newItems, false, false, true)) {
|
if (!ConfigItem::ActivateItems(newItems, false, false, true)) {
|
||||||
Log(LogCritical, "cli", "Error activating configuration.");
|
Log(LogCritical, "cli", "Error activating configuration.");
|
||||||
|
|
||||||
|
NotifyStatus("Error activating configuration.");
|
||||||
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -296,6 +318,8 @@ int RunWorker(const std::vector<std::string>& configs, bool closeConsoleLog = fa
|
||||||
|
|
||||||
ApiListener::UpdateObjectAuthority();
|
ApiListener::UpdateObjectAuthority();
|
||||||
|
|
||||||
|
NotifyStatus("Startup finished.");
|
||||||
|
|
||||||
return Application::GetInstance()->Run();
|
return Application::GetInstance()->Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -796,6 +820,8 @@ int DaemonCommand::Run(const po::variables_map& vm, const std::vector<std::strin
|
||||||
Log(LogInformation, "Application")
|
Log(LogInformation, "Application")
|
||||||
<< "Reload done, old process shutting down. Child process with PID '" << nextWorker << "' is taking over.";
|
<< "Reload done, old process shutting down. Child process with PID '" << nextWorker << "' is taking over.";
|
||||||
|
|
||||||
|
NotifyStatus("Shutting down old instance...");
|
||||||
|
|
||||||
(void)kill(currentWorker, SIGTERM);
|
(void)kill(currentWorker, SIGTERM);
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -814,6 +840,8 @@ int DaemonCommand::Run(const po::variables_map& vm, const std::vector<std::strin
|
||||||
// Old instance shut down, allow the new one to continue working beyond config validation
|
// Old instance shut down, allow the new one to continue working beyond config validation
|
||||||
(void)kill(nextWorker, SIGUSR2);
|
(void)kill(nextWorker, SIGUSR2);
|
||||||
|
|
||||||
|
NotifyStatus("Shut down old instance.");
|
||||||
|
|
||||||
currentWorker = nextWorker;
|
currentWorker = nextWorker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue