WSACleanup();
#endif /* _WIN32 */
- // Getting a shutdown-signal when a restart is in progress usually
- // 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);
+ ClosePidFile(true);
ObjectImpl<Application>::Stop(runtimeRemoved);
}
sd_notifyf(0, "MAINPID=%lu", (unsigned long) m_ReloadProcess);
#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);
}
Log(LogInformation, "cli", "Requesting to take over.");
int rc = kill(vm["reload-internal"].as<int>(), SIGUSR2);
if (rc) {
- Log(LogCritical, "Application")
+ Log(LogCritical, "cli")
<< "Failed to send signal to \"" << vm["reload-internal"].as<int>() << "\" with " << strerror(errno);
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 */