* Do the actual work (config loading, ...) * * @param configs Files to read config from * @param closeConsoleLog Whether to close the console log after config loading * @param stderrFile Where to log errors * * @return Exit code */
| 238 | * @return Exit code |
| 239 | */ |
| 240 | static inline |
| 241 | int RunWorker(const std::vector<std::string>& configs, bool closeConsoleLog = false, const String& stderrFile = String()) |
| 242 | { |
| 243 | |
| 244 | #ifdef I2_DEBUG |
| 245 | double delay = GetDebugWorkerDelay(); |
| 246 | |
| 247 | if (delay > 0.0) { |
| 248 | Log(LogInformation, "RunWorker") |
| 249 | << "DEBUG: Current PID: " << Utility::GetPid() << ". Sleeping for " << delay << " seconds to allow lldb/gdb -p <PID> attachment."; |
| 250 | |
| 251 | Utility::Sleep(delay); |
| 252 | } |
| 253 | #endif /* I2_DEBUG */ |
| 254 | |
| 255 | Log(LogInformation, "cli", "Loading configuration file(s)."); |
| 256 | NotifyStatus("Loading configuration file(s)..."); |
| 257 | |
| 258 | { |
| 259 | std::vector<ConfigItem::Ptr> newItems; |
| 260 | |
| 261 | if (!DaemonUtility::LoadConfigFiles(configs, newItems, l_ObjectsPath, Configuration::VarsPath)) { |
| 262 | Log(LogCritical, "cli", "Config validation failed. Re-run with 'icinga2 daemon -C' after fixing the config."); |
| 263 | NotifyStatus("Config validation failed."); |
| 264 | return EXIT_FAILURE; |
| 265 | } |
| 266 | |
| 267 | #ifndef _WIN32 |
| 268 | Log(LogNotice, "cli") |
| 269 | << "Notifying umbrella process (PID " << l_UmbrellaPid << ") about the config loading success"; |
| 270 | |
| 271 | (void)kill(l_UmbrellaPid, SIGUSR2); |
| 272 | |
| 273 | Log(LogNotice, "cli") |
| 274 | << "Waiting for the umbrella process to let us doing the actual work"; |
| 275 | |
| 276 | NotifyStatus("Waiting for the umbrella process to let us doing the actual work..."); |
| 277 | |
| 278 | if (closeConsoleLog) { |
| 279 | CloseStdIO(stderrFile); |
| 280 | Logger::DisableConsoleLog(); |
| 281 | } |
| 282 | |
| 283 | while (!l_AllowedToWork.load()) { |
| 284 | Utility::Sleep(0.2); |
| 285 | } |
| 286 | |
| 287 | Log(LogNotice, "cli") |
| 288 | << "The umbrella process let us continuing"; |
| 289 | #endif /* _WIN32 */ |
| 290 | |
| 291 | NotifyStatus("Restoring the previous program state..."); |
| 292 | |
| 293 | /* restore the previous program state */ |
| 294 | try { |
| 295 | ConfigObject::RestoreObjects(Configuration::StatePath); |
| 296 | } catch (const std::exception& ex) { |
| 297 | Log(LogCritical, "cli") |
no test coverage detected