0
#include <boost/bind.hpp>
0
#include <boost/thread/thread.hpp>
0
#include <sys/resource.h>
0
@@ -58,6 +63,8 @@ typedef shared_ptr<Client> ClientPtr;
0
#define SERVER_SOCKET_FD 3
0
+static bool serverDone = false;
0
/*****************************************
0
@@ -71,6 +78,39 @@ private:
0
StandardApplicationPool pool;
0
set<ClientPtr> clients;
0
+ string statusReportFIFO;
0
+ void statusReportThread() {
0
+ ret = stat(statusReportFIFO.c_str(), &buf);
0
+ } while (ret == -1 && errno == EINTR);
0
+ if (ret == -1 || !S_ISFIFO(buf.st_mode)) {
0
+ // Something bad happened with the status
0
+ // report FIFO, so we bail out.
0
+ f = fopen(statusReportFIFO.c_str(), "w");
0
+ } while (f == NULL && errno == EINTR);
0
+ string report(pool.toString());
0
+ fwrite(report.c_str(), 1, report.size(), f);
0
+ // Prevent sending too much data at once.
0
Server(int serverSocket,
0
@@ -79,7 +119,21 @@ public:
0
const string &rubyCommand,
0
: pool(spawnServerCommand, logFile, rubyCommand, user) {
0
this->serverSocket = serverSocket;
0
+ char filename[PATH_MAX];
0
+ snprintf(filename, sizeof(filename), "/tmp/passenger_status.%d.fifo",
0
+ filename[PATH_MAX - 1] = '\0';
0
+ if (mkfifo(filename, S_IRUSR | S_IWUSR) == -1 && errno != EEXIST) {
0
+ fprintf(stderr, "*** WARNING: Could not create FIFO '%s'; "
0
+ "disabling Passenger ApplicationPool status reporting.\n",
0
+ statusReportFIFO = filename;
0
@@ -101,6 +155,8 @@ public:
0
+ unlink(statusReportFIFO.c_str());
0
int start(); // Will be defined later, because Client depends on Server's interface.
0
@@ -318,9 +374,25 @@ public:
0
+gracefulShutdown(int sig) {
0
+ if (!statusReportFIFO.empty()) {
0
+ bind(&Server::statusReportThread, this),
0
+ signal(SIGINT, gracefulShutdown);
0
+ siginterrupt(SIGINT, 1);
0
@@ -328,8 +400,8 @@ Server::start() {
0
// and is not important.
0
ret = read(serverSocket, &x, 1);
0
- } while (ret == -1 && errno == EINTR);
0
+ } while (ret == -1 && errno == EINTR && !serverDone);
0
+ if (ret == 0 || serverDone) {
0
// All web server processes disconnected from this server.
0
// So we can safely quit.
0
@@ -339,31 +411,15 @@ Server::start() {
0
// ApplicationPool client.
0
ret = socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
0
- } while (ret == -1 && errno == EINTR);
0
- P_ERROR("Cannot create an anonymous Unix socket: " <<
0
- strerror(e) << " (" << e << ") --- aborting!");
0
- // Shut up compiler warning.
0
+ } while (ret == -1 && errno == EINTR && !serverDone);
0
+ if (ret == -1 || serverDone) {
0
+ throw SystemException("Cannot create an anonymous Unix socket", errno);
0
- MessageChannel(serverSocket).writeFileDescriptor(fds[1]);
0
- } while (ret == -1 && errno == EINTR);
0
- } catch (SystemException &e) {
0
- P_ERROR("Cannot send a file descriptor: " << e.sys() <<
0
- } catch (const exception &e) {
0
- P_ERROR("Cannot send a file descriptor: " << e.what() <<
0
+ MessageChannel(serverSocket).writeFileDescriptor(fds[1]);
0
+ } while (ret == -1 && errno == EINTR);
0
ClientPtr client(new Client(*this, fds[0]));
0
pair<set<ClientPtr>::iterator, bool> p;
0
@@ -386,7 +442,6 @@ main(int argc, char *argv[]) {
0
"ApplicationPool server:\n%s\n",
Comments
No one has commented yet.