public
Description: Phusion Passenger (mod_rails)
Homepage: http://www.modrails.com/
Clone URL: git://github.com/FooBarWidget/passenger.git
Click here to lend your support to: passenger and make a donation at www.pledgie.com !
Fully integrate ApplicationPoolServerExecutable into Passenger. Replace 
'RailsSpawnServer' option with 'PassengerRoot'.
Hongli Lai (Phusion) (author)
Sat Apr 19 03:41:42 -0700 2008
commit  3647f801e8072fb82826194ac1e4621a6b19c6ac
tree    db73a595986a6857bb11b3f871b7cd4b3caa1cdd
parent  ccf0a6ec3cdbe9cbf0515c46c6e59d22253434a3
...
80
81
82
83
 
84
85
86
...
99
100
101
102
 
103
104
105
...
119
120
121
122
 
123
124
125
...
135
136
137
 
 
 
 
 
 
 
 
138
139
140
...
172
173
174
175
176
177
178
179
180
181
182
183
184
185
...
234
235
236
 
 
 
 
 
 
 
 
 
237
238
239
240
 
 
 
 
 
 
241
242
243
...
263
264
265
266
267
268
269
270
271
272
273
...
288
289
290
 
 
 
 
 
 
 
 
291
292
293
...
80
81
82
 
83
84
85
86
...
99
100
101
 
102
103
104
105
...
119
120
121
 
122
123
124
125
...
135
136
137
138
139
140
141
142
143
144
145
146
147
148
...
180
181
182
 
 
 
 
 
 
 
 
183
184
185
...
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
...
278
279
280
 
 
 
 
 
281
282
283
...
298
299
300
301
302
303
304
305
306
307
308
309
310
311
0
@@ -80,7 +80,7 @@ passenger_config_create_server(apr_pool_t *p, server_rec *s) {
0
   ServerConfig *config = create_server_config_struct(p);
0
   config->ruby = NULL;
0
   config->env = NULL;
0
- config->spawnServer = NULL;
0
+ config->root = NULL;
0
   config->maxPoolSize = DEFAULT_MAX_POOL_SIZE;
0
   config->maxPoolSizeSpecified = false;
0
   config->poolIdleTime = DEFAULT_POOL_IDLE_TIME;
0
@@ -99,7 +99,7 @@ passenger_config_merge_server(apr_pool_t *p, void *basev, void *addv) {
0
   
0
   config->ruby = (add->ruby == NULL) ? base->ruby : add->ruby;
0
   config->env = (add->env == NULL) ? base->env : add->env;
0
- config->spawnServer = (add->spawnServer == NULL) ? base->spawnServer : add->spawnServer;
0
+ config->root = (add->root == NULL) ? base->root : add->root;
0
   config->maxPoolSize = (add->maxPoolSizeSpecified) ? base->maxPoolSize : add->maxPoolSize;
0
   config->maxPoolSizeSpecified = base->maxPoolSizeSpecified || add->maxPoolSizeSpecified;
0
   config->poolIdleTime = (add->poolIdleTime) ? base->poolIdleTime : add->poolIdleTime;
0
@@ -119,7 +119,7 @@ passenger_config_merge_all_servers(apr_pool_t *pool, server_rec *main_server) {
0
     ServerConfig *config = (ServerConfig *) ap_get_module_config(s->module_config, &passenger_module);
0
     final->ruby = (final->ruby != NULL) ? final->ruby : config->ruby;
0
     final->env = (final->env != NULL) ? final->env : config->env;
0
- final->spawnServer = (final->spawnServer != NULL) ? final->spawnServer : config->spawnServer;
0
+ final->root = (final->root != NULL) ? final->root : config->root;
0
     final->maxPoolSize = (final->maxPoolSizeSpecified) ? final->maxPoolSize : config->maxPoolSize;
0
     final->maxPoolSizeSpecified = final->maxPoolSizeSpecified || config->maxPoolSizeSpecified;
0
     final->poolIdleTime = (final->poolIdleTimeSpecified) ? final->poolIdleTime : config->poolIdleTime;
0
@@ -135,6 +135,14 @@ passenger_config_merge_all_servers(apr_pool_t *pool, server_rec *main_server) {
0
 }
0
 
0
 static const char *
0
+cmd_passenger_root(cmd_parms *cmd, void *pcfg, const char *arg) {
0
+ ServerConfig *config = (ServerConfig *) ap_get_module_config(
0
+ cmd->server->module_config, &passenger_module);
0
+ config->root = arg;
0
+ return NULL;
0
+}
0
+
0
+static const char *
0
 cmd_rails_base_uri(cmd_parms *cmd, void *pcfg, const char *arg) {
0
   DirConfig *config = (DirConfig *) pcfg;
0
   config->base_uris.insert(arg);
0
@@ -172,14 +180,6 @@ cmd_rails_env(cmd_parms *cmd, void *pcfg, const char *arg) {
0
 }
0
 
0
 static const char *
0
-cmd_rails_spawn_server(cmd_parms *cmd, void *pcfg, const char *arg) {
0
- ServerConfig *config = (ServerConfig *) ap_get_module_config(
0
- cmd->server->module_config, &passenger_module);
0
- config->spawnServer = arg;
0
- return NULL;
0
-}
0
-
0
-static const char *
0
 cmd_rails_max_pool_size(cmd_parms *cmd, void *pcfg, const char *arg) {
0
   ServerConfig *config = (ServerConfig *) ap_get_module_config(
0
     cmd->server->module_config, &passenger_module);
0
@@ -234,10 +234,25 @@ cmd_rails_default_user(cmd_parms *cmd, void *dummy, const char *arg) {
0
   return NULL;
0
 }
0
 
0
+static const char *
0
+cmd_rails_spawn_server(cmd_parms *cmd, void *pcfg, const char *arg) {
0
+ fprintf(stderr, "WARNING: The 'RailsSpawnServer' option is obsolete. "
0
+ "Please specify 'PassengerRoot' instead. The correct value was "
0
+ "given to you by 'passenger-install-apache2-module'.");
0
+ fflush(stderr);
0
+ return NULL;
0
+}
0
+
0
 
0
 typedef const char * (*Take1Func)(); // Workaround for some weird C++-specific compiler error.
0
 
0
 const command_rec passenger_commands[] = {
0
+ AP_INIT_TAKE1("PassengerRoot",
0
+ (Take1Func) cmd_passenger_root,
0
+ NULL,
0
+ RSRC_CONF,
0
+ "The Passenger root folder."),
0
+
0
   AP_INIT_TAKE1("RailsBaseURI",
0
     (Take1Func) cmd_rails_base_uri,
0
     NULL,
0
@@ -263,11 +278,6 @@ const command_rec passenger_commands[] = {
0
     NULL,
0
     RSRC_CONF,
0
     "The environment under which a Rails app must run."),
0
- AP_INIT_TAKE1("RailsSpawnServer",
0
- (Take1Func) cmd_rails_spawn_server,
0
- NULL,
0
- RSRC_CONF,
0
- "The filename of the spawn server to use."),
0
   AP_INIT_TAKE1("RailsMaxPoolSize",
0
     (Take1Func) cmd_rails_max_pool_size,
0
     NULL,
0
@@ -288,6 +298,14 @@ const command_rec passenger_commands[] = {
0
     NULL,
0
     RSRC_CONF,
0
     "The user that Rails applications must run as when user switching fails or is disabled."),
0
+
0
+ // Obsolete options.
0
+ AP_INIT_TAKE1("RailsSpawnServer",
0
+ (Take1Func) cmd_rails_spawn_server,
0
+ NULL,
0
+ RSRC_CONF,
0
+ "Obsolete option."),
0
+
0
   { NULL }
0
 };
0
 
...
61
62
63
64
65
 
 
66
67
68
...
61
62
63
 
 
64
65
66
67
68
0
@@ -61,8 +61,8 @@
0
        * Rails application should operate. */
0
       const char *env;
0
       
0
- /** The filename of the spawn server to use. */
0
- const char *spawnServer;
0
+ /** The Passenger root folder. */
0
+ const char *root;
0
       
0
       /** The maximum number of simultaneously alive Rails application
0
        * instances. */
...
123
124
125
 
 
 
 
 
 
 
 
 
 
 
 
126
127
128
...
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
0
@@ -123,6 +123,18 @@ public:
0
 };
0
 
0
 /**
0
+ * Thrown when an invalid configuration is given.
0
+ */
0
+class ConfigurationException: public exception {
0
+private:
0
+ string msg;
0
+public:
0
+ ConfigurationException(const string &message): msg(message) {}
0
+ virtual ~ConfigurationException() throw() {}
0
+ virtual const char *what() const throw() { return msg.c_str(); }
0
+};
0
+
0
+/**
0
  * Thrown when SpawnManager or ApplicationPool fails to spawn an application
0
  * instance. The exception may contain an error page, which is a user-friendly
0
  * HTML page with details about the error.
...
315
316
317
318
 
319
320
321
...
326
327
328
329
330
331
332
333
334
335
336
337
338
 
 
 
 
 
 
339
 
 
340
341
 
342
343
 
 
 
 
 
 
 
 
 
 
344
345
346
347
348
 
 
 
349
350
351
...
315
316
317
 
318
319
320
321
...
326
327
328
 
 
 
 
 
 
 
 
 
 
329
330
331
332
333
334
335
336
337
338
 
339
340
 
341
342
343
344
345
346
347
348
349
350
351
352
353
354
 
355
356
357
358
359
360
0
@@ -315,7 +315,7 @@ public:
0
     
0
     ServerConfig *config = getServerConfig(s);
0
     const char *ruby, *environment, *user;
0
- string spawnServer;
0
+ string applicationPoolServerExe, spawnServer;
0
     
0
     ruby = (config->ruby != NULL) ? config->ruby : DEFAULT_RUBY_COMMAND;
0
     environment = (config->env != NULL) ? config->env : DEFAULT_RAILS_ENV;
0
@@ -326,26 +326,35 @@ public:
0
     } else {
0
       user = "nobody";
0
     }
0
- if (config->spawnServer != NULL) {
0
- spawnServer = config->spawnServer;
0
- } else {
0
- spawnServer = findSpawnServer();
0
- if (spawnServer.empty()) {
0
- throw FileNotFoundException("The Passenger spawn server script "
0
- "could not be found. Please ensure that it can be found "
0
- "in $PATH, or specify it with the RailsSpawnServer "
0
- "configuration option.");
0
- }
0
+
0
+ if (config->root == NULL) {
0
+ throw ConfigurationException("The 'PassengerRoot' configuration option "
0
+ "is not specified. This option is required, so please specify it. "
0
+ "TIP: The correct value for this option was given to you by "
0
+ "'passenger-install-apache2-module'.");
0
     }
0
+
0
+ spawnServer = findSpawnServer(config->root);
0
     if (!fileExists(spawnServer.c_str())) {
0
- string message("The specified Passenger spawn server script, '");
0
+ string message("The Passenger spawn server script, '");
0
       message.append(spawnServer);
0
- message.append("', does not exist.");
0
+ message.append("', does not exist. Please check whether the 'PassengerRoot' "
0
+ "option is specified correctly.");
0
+ throw FileNotFoundException(message);
0
+ }
0
+ applicationPoolServerExe = findApplicationPoolServer(config->root);
0
+ if (!fileExists(applicationPoolServerExe.c_str())) {
0
+ string message("The Passenger application pool server, '");
0
+ message.append(applicationPoolServerExe);
0
+ message.append("', does not exist. Please check whether the 'PassengerRoot' "
0
+ "option is specified correctly.");
0
       throw FileNotFoundException(message);
0
     }
0
     
0
     applicationPoolServer = ptr(
0
- new ApplicationPoolServer(spawnServer, "", environment, ruby, user)
0
+ new ApplicationPoolServer(
0
+ applicationPoolServerExe, spawnServer, "",
0
+ environment, ruby, user)
0
     );
0
   }
0
   
...
19
20
21
 
22
23
24
...
54
55
56
57
58
59
60
61
 
 
 
 
 
 
 
 
 
 
 
 
 
62
63
64
65
66
67
68
69
70
 
 
 
 
 
 
 
 
 
71
72
 
 
 
 
 
 
 
 
 
 
73
74
 
 
75
76
77
...
19
20
21
22
23
24
25
...
55
56
57
 
 
 
 
 
58
59
60
61
62
63
64
65
66
67
68
69
70
71
 
 
 
 
 
 
 
 
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
 
94
95
96
97
98
0
@@ -19,6 +19,7 @@
0
 #include <sys/stat.h>
0
 #include <cstdlib>
0
 #include <climits>
0
+#include <cassert>
0
 #include <unistd.h>
0
 #include "Utils.h"
0
 
0
@@ -54,24 +55,44 @@ bool fileExists(const char *filename) {
0
 }
0
 
0
 string
0
-findSpawnServer() {
0
- const char *path = getenv("PATH");
0
- if (path == NULL) {
0
- return "";
0
- }
0
+findSpawnServer(const char *passengerRoot) {
0
+ if (passengerRoot != NULL) {
0
+ string path(passengerRoot);
0
+ if (path.at(path.size() - 1) != '/') {
0
+ path.append(1, '/');
0
+ }
0
+ path.append("bin/passenger-spawn-server");
0
+ return path;
0
+ } else {
0
+ const char *path = getenv("PATH");
0
+ if (path == NULL) {
0
+ return "";
0
+ }
0
   
0
- vector<string> paths;
0
- split(getenv("PATH"), ':', paths);
0
- for (vector<string>::const_iterator it(paths.begin()); it != paths.end(); it++) {
0
- if (!it->empty() && (*it).at(0) == '/') {
0
- string filename(*it);
0
- filename.append("/" SPAWN_SERVER_SCRIPT_NAME);
0
- if (fileExists(filename.c_str())) {
0
- return filename;
0
+ vector<string> paths;
0
+ split(getenv("PATH"), ':', paths);
0
+ for (vector<string>::const_iterator it(paths.begin()); it != paths.end(); it++) {
0
+ if (!it->empty() && (*it).at(0) == '/') {
0
+ string filename(*it);
0
+ filename.append("/" SPAWN_SERVER_SCRIPT_NAME);
0
+ if (fileExists(filename.c_str())) {
0
+ return filename;
0
+ }
0
       }
0
     }
0
+ return "";
0
+ }
0
+}
0
+
0
+string
0
+findApplicationPoolServer(const char *passengerRoot) {
0
+ assert(passengerRoot != NULL);
0
+ string path(passengerRoot);
0
+ if (path.at(path.size() - 1) != '/') {
0
+ path.append(1, '/');
0
   }
0
- return "";
0
+ path.append("ext/apache2/ApplicationPoolServerExecutable");
0
+ return path;
0
 }
0
 
0
 string
...
124
125
126
127
128
 
129
 
 
 
130
131
132
133
134
 
 
 
 
 
 
 
 
 
 
 
 
135
136
137
...
124
125
126
 
 
127
128
129
130
131
132
133
134
135
 
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
0
@@ -124,14 +124,27 @@ bool fileExists(const char *filename);
0
 
0
 /**
0
  * Find the location of the Passenger spawn server script.
0
- * This is done by scanning $PATH. For security reasons, only
0
- * absolute paths are scanned.
0
+ * If passengerRoot is given, t T
0
  *
0
+ * @param passengerRoot The Passenger root folder. If NULL is given, then
0
+ * the spawn server is found by scanning $PATH. For security reasons,
0
+ * only absolute paths are scanned.
0
  * @return An absolute path to the spawn server script, or
0
  * an empty string on error.
0
  * @ingroup Support
0
  */
0
-string findSpawnServer();
0
+string findSpawnServer(const char *passengerRoot = NULL);
0
+
0
+/**
0
+ * Find the location of the Passenger ApplicationPool server
0
+ * executable.
0
+ *
0
+ * @param passengerRoot The Passenger root folder.
0
+ * @return An absolute path to the executable.
0
+ * @pre passengerRoot != NULL
0
+ * @ingroup Support
0
+ */
0
+string findApplicationPoolServer(const char *passengerRoot);
0
 
0
 /**
0
  * Returns a canonical version of the specified path. All symbolic links
...
91
92
93
 
94
95
96
97
98
99
 
 
 
 
 
 
 
 
 
 
100
...
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
0
@@ -91,10 +91,21 @@ namespace tut {
0
   }
0
   
0
   TEST_METHOD(10) {
0
+ // It should find in $PATH.
0
     char cwd[PATH_MAX];
0
     string binpath(getcwd(cwd, sizeof(cwd)));
0
     binpath.append("/../bin");
0
     setenv("PATH", binpath.c_str(), 1);
0
     ensure("Spawn server is found.", !findSpawnServer().empty());
0
   }
0
+
0
+ TEST_METHOD(11) {
0
+ // It should use _passengerRoot_.
0
+ ensure_equals(findSpawnServer("/foo"), "/foo/bin/passenger-spawn-server");
0
+ }
0
+
0
+ TEST_METHOD(12) {
0
+ // It ignore trailing slash in _passengerRoot_.
0
+ ensure_equals(findSpawnServer("/foo/"), "/foo/bin/passenger-spawn-server");
0
+ }
0
 }

Comments

    No one has commented yet.