mirror of https://github.com/Icinga/icinga2.git
Merge pull request #6163 from Icinga/fix/handle-restart
Fix reload handling by updating the PID file before process overtake
This commit is contained in:
commit
da9b3991aa
|
@ -90,25 +90,7 @@ void Application::Stop(bool runtimeRemoved)
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
// Getting a shutdown-signal when a restart is in progress usually
|
ClosePidFile(true);
|
||||||
// means that the restart succeeded and the new process wants to take
|
|
||||||
// over. Write the PID of the new process to the pidfile before this
|
|
||||||
// process exits to keep systemd happy.
|
|
||||||
if (l_Restarting) {
|
|
||||||
try {
|
|
||||||
UpdatePidFile(GetPidPath(), m_ReloadProcess);
|
|
||||||
} catch (const std::exception&) {
|
|
||||||
/* abort restart */
|
|
||||||
Log(LogCritical, "Application", "Cannot update PID file. Aborting restart operation.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log(LogDebug, "Application")
|
|
||||||
<< "Keeping pid '" << m_ReloadProcess << "' open.";
|
|
||||||
|
|
||||||
ClosePidFile(false);
|
|
||||||
} else
|
|
||||||
ClosePidFile(true);
|
|
||||||
|
|
||||||
ObjectImpl<Application>::Stop(runtimeRemoved);
|
ObjectImpl<Application>::Stop(runtimeRemoved);
|
||||||
}
|
}
|
||||||
|
@ -742,6 +724,20 @@ void Application::SigUsr2Handler(int)
|
||||||
sd_notifyf(0, "MAINPID=%lu", (unsigned long) m_ReloadProcess);
|
sd_notifyf(0, "MAINPID=%lu", (unsigned long) m_ReloadProcess);
|
||||||
#endif /* HAVE_SYSTEMD */
|
#endif /* HAVE_SYSTEMD */
|
||||||
|
|
||||||
|
/* Write the PID of the new process to the pidfile before this
|
||||||
|
* process exits to keep systemd happy.
|
||||||
|
*/
|
||||||
|
Application::Ptr instance = GetInstance();
|
||||||
|
try {
|
||||||
|
instance->UpdatePidFile(GetPidPath(), m_ReloadProcess);
|
||||||
|
} catch (const std::exception&) {
|
||||||
|
/* abort restart */
|
||||||
|
Log(LogCritical, "Application", "Cannot update PID file. Aborting restart operation.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
instance->ClosePidFile(false);
|
||||||
|
|
||||||
Exit(0);
|
Exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -262,10 +262,17 @@ int DaemonCommand::Run(const po::variables_map& vm, const std::vector<std::strin
|
||||||
Log(LogInformation, "cli", "Requesting to take over.");
|
Log(LogInformation, "cli", "Requesting to take over.");
|
||||||
int rc = kill(vm["reload-internal"].as<int>(), SIGUSR2);
|
int rc = kill(vm["reload-internal"].as<int>(), SIGUSR2);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
Log(LogCritical, "Application")
|
Log(LogCritical, "cli")
|
||||||
<< "Failed to send signal to \"" << vm["reload-internal"].as<int>() << "\" with " << strerror(errno);
|
<< "Failed to send signal to \"" << vm["reload-internal"].as<int>() << "\" with " << strerror(errno);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double start = Utility::GetTime();
|
||||||
|
while (kill(vm["reload-internal"].as<int>(), SIGCHLD) == 0)
|
||||||
|
Utility::Sleep(0.2);
|
||||||
|
|
||||||
|
Log(LogNotice, "cli")
|
||||||
|
<< "Waited for " << Utility::FormatDuration(Utility::GetTime() - start) << " on old process to exit.";
|
||||||
}
|
}
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue