echo "Done"
}
+# Reload Icinga 2
+reload() {
+ printf "Reloading Icinga 2: "
+ if [ ! -e $ICINGA2_PID_FILE ]; then
+ echo "The PID file '$ICINGA2_PID_FILE' does not exist."
+ exit 1
+ fi
+
+ pid=`cat $ICINGA2_PID_FILE`
+
+ if ! kill -HUP $pid >/dev/null 2>&1; then
+ echo "Failed - Icinga 2 is not running."
+ else
+ echo "Done"
+ fi
+}
+
+
# Print status for Icinga 2
status() {
printf "Icinga 2 status: "
stop
start
;;
+reload)
+ reload
+ ;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 1
return true;
}
+static void SigHupHandler(int)
+{
+ Application::RequestRestart();
+}
+
static bool Daemonize(const String& stderrFile)
{
#ifndef _WIN32
if (!app)
BOOST_THROW_EXCEPTION(std::runtime_error("Configuration must create an Application object."));
+#ifndef _WIN32
+ struct sigaction sa;
+ memset(&sa, 0, sizeof(sa));
+ sa.sa_handler = &SigHupHandler;
+ sigaction(SIGHUP, &sa, NULL);
+#endif /* _WIN32 */
+
return app->Run();
}
Application *Application::m_Instance = NULL;
bool Application::m_ShuttingDown = false;
+bool Application::m_Restarting = false;
bool Application::m_Debugging = false;
int Application::m_ArgC;
char **Application::m_ArgV;
void Application::ShutdownTimerHandler(void)
{
- if (m_ShuttingDown) {
+ if (m_ShuttingDown || m_Restarting) {
Log(LogInformation, "base", "Shutting down Icinga...");
Application::GetInstance()->OnShutdown();
m_ShuttingDown = true;
}
+/**
+ * Signals the application to restart during the next
+ * execution of the event loop.
+ */
+void Application::RequestRestart(void)
+{
+ m_Restarting = true;
+}
+
/**
* Retrieves the full path of the executable.
*
result = Main();
+ if (m_Restarting) {
+ Log(LogInformation, "base", "Restarting application.");
+
+#ifndef _WIN32
+ String exePath = GetExePath(m_ArgV[0]);
+
+ (void) execv(exePath.CStr(), m_ArgV);
+#else /* _WIN32 */
+ STARTUPINFO si;
+ memset(&si, 0, sizeof(si));
+ si.cb = sizeof(si);
+ CreateProcess(NULL, GetCommandLine(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
+#endif /* _WIN32 */
+
+ _exit(0);
+ }
+
return result;
}
static void InstallExceptionHandlers(void);
static void RequestShutdown(void);
+ static void RequestRestart(void);
static void SetDebugging(bool debug);
static bool IsDebugging(void);
static bool m_ShuttingDown; /**< Whether the application is in the process of
shutting down. */
+ static bool m_Restarting;
static int m_ArgC; /**< The number of command-line arguments. */
static char **m_ArgV; /**< Command-line arguments. */
FILE *m_PidFile; /**< The PID file */
RegisterCommand("ENABLE_SVC_CHECK", &ExternalCommandProcessor::EnableSvcCheck);
RegisterCommand("DISABLE_SVC_CHECK", &ExternalCommandProcessor::DisableSvcCheck);
RegisterCommand("SHUTDOWN_PROCESS", &ExternalCommandProcessor::ShutdownProcess);
+ RegisterCommand("RESTART_PROCESS", &ExternalCommandProcessor::RestartProcess);
RegisterCommand("SCHEDULE_FORCED_HOST_SVC_CHECKS", &ExternalCommandProcessor::ScheduleForcedHostSvcChecks);
RegisterCommand("SCHEDULE_HOST_SVC_CHECKS", &ExternalCommandProcessor::ScheduleHostSvcChecks);
RegisterCommand("ENABLE_HOST_SVC_CHECKS", &ExternalCommandProcessor::EnableHostSvcChecks);
Application::RequestShutdown();
}
+void ExternalCommandProcessor::RestartProcess(double, const std::vector<String>&)
+{
+ Log(LogInformation, "icinga", "Restarting Icinga via external command.");
+ Application::RequestRestart();
+}
+
void ExternalCommandProcessor::ScheduleForcedHostSvcChecks(double, const std::vector<String>& arguments)
{
if (arguments.size() < 2)
static void EnableSvcCheck(double time, const std::vector<String>& arguments);
static void DisableSvcCheck(double time, const std::vector<String>& arguments);
static void ShutdownProcess(double time, const std::vector<String>& arguments);
+ static void RestartProcess(double time, const std::vector<String>& arguments);
static void ScheduleForcedHostSvcChecks(double time, const std::vector<String>& arguments);
static void ScheduleHostSvcChecks(double time, const std::vector<String>& arguments);
static void EnableHostSvcChecks(double time, const std::vector<String>& arguments);