diff --git a/lib/cli/daemoncommand.cpp b/lib/cli/daemoncommand.cpp index e25048c1b..2a50e2cf3 100644 --- a/lib/cli/daemoncommand.cpp +++ b/lib/cli/daemoncommand.cpp @@ -45,6 +45,14 @@ static po::variables_map g_AppParams; 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). * @@ -235,12 +243,14 @@ int RunWorker(const std::vector& configs, bool closeConsoleLog = fa #endif /* I2_DEBUG */ Log(LogInformation, "cli", "Loading configuration file(s)."); + NotifyStatus("Loading configuration file(s)..."); { std::vector newItems; 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."); + NotifyStatus("Config validation failed."); return EXIT_FAILURE; } @@ -253,6 +263,8 @@ int RunWorker(const std::vector& configs, bool closeConsoleLog = fa Log(LogNotice, "cli") << "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) { CloseStdIO(stderrFile); Logger::DisableConsoleLog(); @@ -266,18 +278,28 @@ int RunWorker(const std::vector& configs, bool closeConsoleLog = fa << "The umbrella process let us continuing"; #endif /* _WIN32 */ + NotifyStatus("Restoring the previous program state..."); + /* restore the previous program state */ try { ConfigObject::RestoreObjects(Configuration::StatePath); } catch (const std::exception& ex) { Log(LogCritical, "cli") << "Failed to restore state file: " << DiagnosticInformation(ex); + + NotifyStatus("Failed to restore state file."); + return EXIT_FAILURE; } + NotifyStatus("Activating config objects..."); + // activate config only after daemonization: it starts threads and that is not compatible with fork() if (!ConfigItem::ActivateItems(newItems, false, false, true)) { Log(LogCritical, "cli", "Error activating configuration."); + + NotifyStatus("Error activating configuration."); + return EXIT_FAILURE; } } @@ -296,6 +318,8 @@ int RunWorker(const std::vector& configs, bool closeConsoleLog = fa ApiListener::UpdateObjectAuthority(); + NotifyStatus("Startup finished."); + return Application::GetInstance()->Run(); } @@ -796,6 +820,8 @@ int DaemonCommand::Run(const po::variables_map& vm, const std::vector