public
Description: Phusion Passenger (mod_rails)
Homepage: http://www.modrails.com/
Clone URL: git://github.com/FooBarWidget/passenger.git
Search Repo:
Click here to lend your support to: passenger and make a donation at www.pledgie.com !
restartServer: Add code for shutting down existing server.
Hongli Lai (Phusion) (author)
Wed Apr 23 01:55:26 -0700 2008
commit  38ad8efb77974fcc0df75d37964acd1a50480ce1
tree    22b6ec1c6367624054a9f1e3f026bcc4a245173a
parent  d441eec5934ba741b5e15cca9c07cb00dd9c9b78
...
225
226
227
228
 
229
230
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
232
233
...
310
311
312
 
313
314
315
...
225
226
227
 
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
...
336
337
338
339
340
341
342
0
@@ -225,9 +225,35 @@
0
   int serverSocket;
0
   
0
   void restartServer() {
0
- int fds[2];
0
+ int fds[2], ret;
0
     pid_t pid;
0
     
0
+ if (serverPid != 0) {
0
+ time_t begin;
1
+ bool done;
0
+
0
+ // Shutdown existing server instance.
0
+ do {
0
+ ret = close(serverSocket);
0
+ } while (ret == -1 && errno == EINTR);
0
+
0
+ P_DEBUG("Waiting for existing ApplicationPoolServerExecutable to exit...");
0
+ begin = time(NULL);
0
+ while (!done && time(NULL) < begin + 5) {
0
+ done = waitpid(serverPid, NULL, WNOHANG) > 0;
0
+ usleep(100000);
0
+ }
0
+ if (done) {
0
+ P_DEBUG("ApplicationPoolServerExecutable exited.");
0
+ } else {
0
+ P_DEBUG("ApplicationPoolServerExecutable not exited in time. Killing it...");
0
+ kill(serverPid, SIGTERM);
0
+ waitpid(serverPid, NULL, 0);
0
+ }
0
+ serverSocket = -1;
0
+ serverPid = 0;
0
+ }
0
+
0
     if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == -1) {
0
       throw SystemException("Cannot create a Unix socket pair", errno);
0
     }
0
@@ -310,6 +336,7 @@
0
    m_rubyCommand(rubyCommand),
0
    m_user(user) {
0
     serverSocket = -1;
0
+ serverPid = 0;
0
     restartServer();
0
   }
0
   

Comments