mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-22 13:14:32 +02:00
Implement restarting Icinga.
This commit is contained in:
parent
59d979c61e
commit
e8c61a578f
@ -84,6 +84,24 @@ stop() {
|
|||||||
echo "Done"
|
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
|
# Print status for Icinga 2
|
||||||
status() {
|
status() {
|
||||||
printf "Icinga 2 status: "
|
printf "Icinga 2 status: "
|
||||||
@ -111,6 +129,9 @@ case "$1" in
|
|||||||
stop
|
stop
|
||||||
start
|
start
|
||||||
;;
|
;;
|
||||||
|
reload)
|
||||||
|
reload
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
echo $"Usage: $0 {start|stop|restart|status}"
|
echo $"Usage: $0 {start|stop|restart|status}"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -93,6 +93,11 @@ static bool LoadConfigFiles(bool validateOnly)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void SigHupHandler(int)
|
||||||
|
{
|
||||||
|
Application::RequestRestart();
|
||||||
|
}
|
||||||
|
|
||||||
static bool Daemonize(const String& stderrFile)
|
static bool Daemonize(const String& stderrFile)
|
||||||
{
|
{
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
@ -317,5 +322,12 @@ int main(int argc, char **argv)
|
|||||||
if (!app)
|
if (!app)
|
||||||
BOOST_THROW_EXCEPTION(std::runtime_error("Configuration must create an Application object."));
|
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();
|
return app->Run();
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,7 @@ using namespace icinga;
|
|||||||
|
|
||||||
Application *Application::m_Instance = NULL;
|
Application *Application::m_Instance = NULL;
|
||||||
bool Application::m_ShuttingDown = false;
|
bool Application::m_ShuttingDown = false;
|
||||||
|
bool Application::m_Restarting = false;
|
||||||
bool Application::m_Debugging = false;
|
bool Application::m_Debugging = false;
|
||||||
int Application::m_ArgC;
|
int Application::m_ArgC;
|
||||||
char **Application::m_ArgV;
|
char **Application::m_ArgV;
|
||||||
@ -131,7 +132,7 @@ void Application::SetArgV(char **argv)
|
|||||||
|
|
||||||
void Application::ShutdownTimerHandler(void)
|
void Application::ShutdownTimerHandler(void)
|
||||||
{
|
{
|
||||||
if (m_ShuttingDown) {
|
if (m_ShuttingDown || m_Restarting) {
|
||||||
Log(LogInformation, "base", "Shutting down Icinga...");
|
Log(LogInformation, "base", "Shutting down Icinga...");
|
||||||
Application::GetInstance()->OnShutdown();
|
Application::GetInstance()->OnShutdown();
|
||||||
|
|
||||||
@ -203,6 +204,15 @@ void Application::RequestShutdown(void)
|
|||||||
m_ShuttingDown = true;
|
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.
|
* Retrieves the full path of the executable.
|
||||||
*
|
*
|
||||||
@ -464,6 +474,23 @@ int Application::Run(void)
|
|||||||
|
|
||||||
result = Main();
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +59,7 @@ public:
|
|||||||
static void InstallExceptionHandlers(void);
|
static void InstallExceptionHandlers(void);
|
||||||
|
|
||||||
static void RequestShutdown(void);
|
static void RequestShutdown(void);
|
||||||
|
static void RequestRestart(void);
|
||||||
|
|
||||||
static void SetDebugging(bool debug);
|
static void SetDebugging(bool debug);
|
||||||
static bool IsDebugging(void);
|
static bool IsDebugging(void);
|
||||||
@ -98,6 +99,7 @@ private:
|
|||||||
|
|
||||||
static bool m_ShuttingDown; /**< Whether the application is in the process of
|
static bool m_ShuttingDown; /**< Whether the application is in the process of
|
||||||
shutting down. */
|
shutting down. */
|
||||||
|
static bool m_Restarting;
|
||||||
static int m_ArgC; /**< The number of command-line arguments. */
|
static int m_ArgC; /**< The number of command-line arguments. */
|
||||||
static char **m_ArgV; /**< Command-line arguments. */
|
static char **m_ArgV; /**< Command-line arguments. */
|
||||||
FILE *m_PidFile; /**< The PID file */
|
FILE *m_PidFile; /**< The PID file */
|
||||||
|
@ -106,6 +106,7 @@ void ExternalCommandProcessor::Initialize(void)
|
|||||||
RegisterCommand("ENABLE_SVC_CHECK", &ExternalCommandProcessor::EnableSvcCheck);
|
RegisterCommand("ENABLE_SVC_CHECK", &ExternalCommandProcessor::EnableSvcCheck);
|
||||||
RegisterCommand("DISABLE_SVC_CHECK", &ExternalCommandProcessor::DisableSvcCheck);
|
RegisterCommand("DISABLE_SVC_CHECK", &ExternalCommandProcessor::DisableSvcCheck);
|
||||||
RegisterCommand("SHUTDOWN_PROCESS", &ExternalCommandProcessor::ShutdownProcess);
|
RegisterCommand("SHUTDOWN_PROCESS", &ExternalCommandProcessor::ShutdownProcess);
|
||||||
|
RegisterCommand("RESTART_PROCESS", &ExternalCommandProcessor::RestartProcess);
|
||||||
RegisterCommand("SCHEDULE_FORCED_HOST_SVC_CHECKS", &ExternalCommandProcessor::ScheduleForcedHostSvcChecks);
|
RegisterCommand("SCHEDULE_FORCED_HOST_SVC_CHECKS", &ExternalCommandProcessor::ScheduleForcedHostSvcChecks);
|
||||||
RegisterCommand("SCHEDULE_HOST_SVC_CHECKS", &ExternalCommandProcessor::ScheduleHostSvcChecks);
|
RegisterCommand("SCHEDULE_HOST_SVC_CHECKS", &ExternalCommandProcessor::ScheduleHostSvcChecks);
|
||||||
RegisterCommand("ENABLE_HOST_SVC_CHECKS", &ExternalCommandProcessor::EnableHostSvcChecks);
|
RegisterCommand("ENABLE_HOST_SVC_CHECKS", &ExternalCommandProcessor::EnableHostSvcChecks);
|
||||||
@ -416,6 +417,12 @@ void ExternalCommandProcessor::ShutdownProcess(double, const std::vector<String>
|
|||||||
Application::RequestShutdown();
|
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)
|
void ExternalCommandProcessor::ScheduleForcedHostSvcChecks(double, const std::vector<String>& arguments)
|
||||||
{
|
{
|
||||||
if (arguments.size() < 2)
|
if (arguments.size() < 2)
|
||||||
|
@ -59,6 +59,7 @@ private:
|
|||||||
static void EnableSvcCheck(double time, const std::vector<String>& arguments);
|
static void EnableSvcCheck(double time, const std::vector<String>& arguments);
|
||||||
static void DisableSvcCheck(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 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 ScheduleForcedHostSvcChecks(double time, const std::vector<String>& arguments);
|
||||||
static void ScheduleHostSvcChecks(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);
|
static void EnableHostSvcChecks(double time, const std::vector<String>& arguments);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user