~Server() { TRACE_POINT(); this_thread::disable_syscall_interruption dsi; this_thread::disable_interruption di; P_DEBUG("Shutting down helper agent..."); prestarterThread->interrupt_and_join(); if (messageServerThread != NULL) { messageServerThread->interrupt_and_join(); } messageServer.reset(); P_DEBUG("Destroying application pool..."); pool->destroy(); uninstallDiagnosticsDumper(); pool.reset(); poolLoop.stop(); requestLoop.stop(); requestHandler.reset(); if (!options.requestSocketLink.empty()) { syscalls::unlink(options.requestSocketLink.c_str()); } P_TRACE(2, "All threads have been shut down."); }
void mainLoop() { TRACE_POINT(); boost::function<void ()> func; func = boost::bind(&MessageServer::mainLoop, messageServer.get()); messageServerThread = ptr(new oxt::thread( boost::bind(runAndPrintExceptions, func, true), "MessageServer thread", MESSAGE_SERVER_THREAD_STACK_SIZE )); poolLoop.start("Pool event loop", 0); requestLoop.start("Request event loop", 0); /* Wait until the watchdog closes the feedback fd (meaning it * was killed) or until we receive an exit message. */ this_thread::disable_syscall_interruption dsi; fd_set fds; int largestFd; FD_ZERO(&fds); FD_SET(feedbackFd, &fds); FD_SET(exitEvent.fd(), &fds); largestFd = (feedbackFd > exitEvent.fd()) ? (int) feedbackFd : exitEvent.fd(); UPDATE_TRACE_POINT(); installDiagnosticsDumper(); if (syscalls::select(largestFd + 1, &fds, NULL, NULL, NULL) == -1) { int e = errno; uninstallDiagnosticsDumper(); throw SystemException("select() failed", e); } if (FD_ISSET(feedbackFd, &fds)) { /* If the watchdog has been killed then we'll kill all descendant * processes and exit. There's no point in keeping this helper * server running because we can't detect when the web server exits, * and because this helper agent doesn't own the server instance * directory. As soon as passenger-status is run, the server * instance directory will be cleaned up, making this helper agent * inaccessible. */ P_DEBUG("Watchdog seems to be killed; forcing shutdown of all subprocesses"); syscalls::killpg(getpgrp(), SIGKILL); _exit(2); // In case killpg() fails. } else { /* We received an exit command. We want to exit 5 seconds after * all clients have disconnected have become inactive. */ P_DEBUG("Received command to exit gracefully. " "Waiting until 5 seconds after all clients have disconnected..."); while (requestHandler->inactivityTime() < 5000) { syscalls::usleep(250000); } P_DEBUG("It's now 5 seconds after all clients have disconnected. " "Proceeding with graceful exit."); } }
~Server() { TRACE_POINT(); this_thread::disable_syscall_interruption dsi; this_thread::disable_interruption di; P_DEBUG("Shutting down helper agent..."); prestarterThread->interrupt_and_join(); if (messageServerThread != NULL) { messageServerThread->interrupt_and_join(); } messageServer.reset(); P_DEBUG("Destroying application pool..."); pool->destroy(); uninstallDiagnosticsDumper(); pool.reset(); poolLoop.stop(); requestLoop.stop(); requestHandler.reset(); if (!options.requestSocketLink.empty()) { char path[PATH_MAX + 1]; ssize_t ret; bool shouldUnlink; ret = readlink(options.requestSocketLink.c_str(), path, PATH_MAX); if (ret != -1) { path[ret] = '\0'; // Only unlink if a new Flying Passenger instance hasn't overwritten the // symlink. // https://code.google.com/p/phusion-passenger/issues/detail?id=939 shouldUnlink = getRequestSocketFilename() == path; } else { shouldUnlink = true; } if (shouldUnlink) { syscalls::unlink(options.requestSocketLink.c_str()); } } P_TRACE(2, "All threads have been shut down."); }
~Server() { TRACE_POINT(); this_thread::disable_syscall_interruption dsi; this_thread::disable_interruption di; P_DEBUG("Shutting down helper agent..."); prestarterThread->interrupt_and_join(); if (messageServerThread != NULL) { messageServerThread->interrupt_and_join(); } messageServer.reset(); pool->destroy(); pool.reset(); requestHandler.reset(); poolLoop.stop(); requestLoop.stop(); P_TRACE(2, "All threads have been shut down."); }