Component::AddSearchDir(ICINGA_LIBDIR);
#endif /* ICINGA_LIBDIR */
- DynamicObject::BeginTx();
+ try {
+ DynamicObject::BeginTx();
- /* load config file */
- String configFile = argv[2];
- vector<ConfigItem::Ptr> configItems = ConfigCompiler::CompileFile(configFile);
+ /* load config file */
+ String configFile = argv[2];
+ vector<ConfigItem::Ptr> configItems = ConfigCompiler::CompileFile(configFile);
- Logger::Write(LogInformation, "icinga", "Executing config items...");
+ Logger::Write(LogInformation, "icinga", "Executing config items...");
- BOOST_FOREACH(const ConfigItem::Ptr& item, configItems) {
- item->Commit();
- }
+ BOOST_FOREACH(const ConfigItem::Ptr& item, configItems) {
+ item->Commit();
+ }
- DynamicObject::FinishTx();
+ DynamicObject::FinishTx();
+ } catch (const exception& ex) {
+ Logger::Write(LogCritical, "icinga", "Configuration error: " + String(ex.what()));
+ return EXIT_FAILURE;
+ }
Application::Ptr app = Application::GetInstance();
* Signals the application to shut down during the next
* execution of the event loop.
*/
-void Application::Shutdown(void)
+void Application::RequestShutdown(void)
{
m_ShuttingDown = true;
}
+/**
+ * Terminates the application.
+ */
+void Application::Terminate(int exitCode)
+{
+ _exit(exitCode);
+}
+
/**
* Retrieves the full path of the executable.
*
if (!instance)
return;
- instance->Shutdown();
+ instance->RequestShutdown();
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
if (!instance)
return TRUE;
- instance->GetInstance()->Shutdown();
+ instance->GetInstance()->RequestShutdown();
SetConsoleCtrlHandler(NULL, FALSE);
return TRUE;
}
/**
- * Grabs the PID file lock and updates the PID.
+ * Grabs the PID file lock and updates the PID. Terminates the application
+ * if the PID file is already locked by another instance of the application.
*
* @param filename The name of the PID file.
*/
if (flock(fileno(m_PidFile), LOCK_EX | LOCK_NB) < 0) {
ClosePidFile();
- throw_exception(runtime_error("Another instance of the application is "
+ Logger::Write(LogCritical, "base",
+ "Another instance of the application is "
"already running. Remove the '" + filename + "' file if "
- "you're certain that this is not the case."));
+ "you're certain that this is not the case.");
+ Terminate(EXIT_FAILURE);
}
#endif /* _WIN32 */
*/
virtual int Main(const vector<String>& args) = 0;
- static void Shutdown(void);
+ static void RequestShutdown(void);
+ static void Terminate(int exitCode);
static bool IsDebugging(void);