0
#include "Application.h"
0
+#include "SpawnOptions.h"
0
#include "MessageChannel.h"
0
#include "Exceptions.h"
0
@@ -244,35 +245,23 @@ private:
0
* Send the spawn command to the spawn server.
0
- * @param appRoot The application root of the application to spawn.
0
- * @param lowerPrivilege Whether to lower the application's privileges.
0
- * @param lowestUser The user to fallback to if lowering privilege fails.
0
- * @param environment The RAILS_ENV/RACK_ENV environment that should be used.
0
- * @param spawnMethod The spawn method to use.
0
- * @param appType The application type.
0
+ * @param spawnOptions The spawn options to use.
0
* @return An Application smart pointer, representing the spawned application.
0
* @throws SpawnException Something went wrong.
0
- ApplicationPtr sendSpawnCommand(
0
- const string &appRoot,
0
- const string &lowestUser,
0
- const string &environment,
0
- const string &spawnMethod,
0
+ ApplicationPtr sendSpawnCommand(const SpawnOptions &spawnOptions) {
0
channel.write("spawn_application",
0
- (lowerPrivilege) ? "true" : "false",
0
+ spawnOptions.appRoot.c_str(),
0
+ (spawnOptions.lowerPrivilege) ? "true" : "false",
0
+ spawnOptions.lowestUser.c_str(),
0
+ spawnOptions.environment.c_str(),
0
+ spawnOptions.spawnMethod.c_str(),
0
+ spawnOptions.appType.c_str(),
0
} catch (const SystemException &e) {
0
throw SpawnException(string("Could not write 'spawn_application' "
0
@@ -336,18 +325,15 @@ private:
0
ret = chown(args[1].c_str(), getuid(), getgid());
0
} while (ret == -1 && errno == EINTR);
0
- return ApplicationPtr(new Application(appRoot, pid, args[1],
0
- usingAbstractNamespace, ownerPipe));
0
+ return ApplicationPtr(new Application(spawnOptions.appRoot,
0
+ pid, args[1], usingAbstractNamespace, ownerPipe));
0
* @throws boost::thread_interrupted
0
- handleSpawnException(const SpawnException &e, const string &appRoot,
0
- bool lowerPrivilege, const string &lowestUser,
0
- const string &environment, const string &spawnMethod,
0
- const string &appType) {
0
+ handleSpawnException(const SpawnException &e, const SpawnOptions &spawnOptions) {
0
@@ -364,8 +350,7 @@ private:
0
- return sendSpawnCommand(appRoot, lowerPrivilege, lowestUser,
0
- environment, spawnMethod, appType);
0
+ return sendSpawnCommand(spawnOptions);
0
throw SpawnException("The spawn server died unexpectedly, and restarting it failed.");
0
@@ -479,66 +464,32 @@ public:
0
- * Spawn a new instance of a Ruby on Rails or Rack application.
0
+ * Spawn a new instance of an application. Spawning details are to be passed
0
+ * via the <tt>spawnOptions</tt> parameter.
0
* If the spawn server died during the spawning process, then the server
0
* will be automatically restarted, and another spawn attempt will be made.
0
* If restarting the server fails, or if the second spawn attempt fails,
0
* then an exception will be thrown.
0
- * If <tt>lowerPrivilege</tt> is true, then it will be attempt to
0
- * switch the spawned application instance to the user who owns the
0
- * application's <tt>config/environment.rb</tt>, and to the default
0
- * If that user doesn't exist on the system, or if that user is root,
0
- * then it will be attempted to switch to the username given by
0
- * <tt>lowestUser</tt> (and to the default group of that user).
0
- * If <tt>lowestUser</tt> doesn't exist either, or if switching user failed
0
- * (because the spawn server process does not have the privilege to do so),
0
- * then the application will be spawned anyway, without reporting an error.
0
- * It goes without saying that lowering privilege is only possible if
0
- * the spawn server is running as root (and thus, by induction, that
0
- * Passenger and Apache's control process are also running as root).
0
- * Note that if Apache is listening on port 80, then its control process must
0
- * be running as root. See "doc/Security of user switching.txt" for
0
- * a detailed explanation.
0
- * @param appRoot The application root of a RoR application, i.e. the folder that
0
- * contains 'app/', 'public/', 'config/', etc. This must be a valid directory,
0
- * but the path does not have to be absolute.
0
- * @param lowerPrivilege Whether to lower the application's privileges.
0
- * @param lowestUser The user to fallback to if lowering privilege fails.
0
- * @param environment The RAILS_ENV/RACK_ENV environment that should be used. May not be empty.
0
- * @param spawnMethod The spawn method to use. Either "smart" or "conservative".
0
- * See the Ruby class SpawnManager for details.
0
- * @param appType The application type. Either "rails" or "rack".
0
+ * @param spawnOptions An object containing the details for this spawn operation,
0
+ * such as which application to spawn. See SpawnOptions for details.
0
* @return A smart pointer to an Application object, which represents the application
0
* instance that has been spawned. Use this object to communicate with the
0
* @throws SpawnException Something went wrong.
0
* @throws boost::thread_interrupted
0
- const string &appRoot,
0
- bool lowerPrivilege = true,
0
- const string &lowestUser = "nobody",
0
- const string &environment = "production",
0
- const string &spawnMethod = "smart",
0
- const string &appType = "rails"
0
+ ApplicationPtr spawn(const SpawnOptions &spawnOptions) {
0
boost::mutex::scoped_lock l(lock);
0
- return sendSpawnCommand(appRoot, lowerPrivilege, lowestUser,
0
- environment, spawnMethod, appType);
0
+ return sendSpawnCommand(spawnOptions);
0
} catch (const SpawnException &e) {
0
if (e.hasErrorPage()) {
0
- return handleSpawnException(e, appRoot, lowerPrivilege,
0
- lowestUser, environment, spawnMethod, appType);
0
+ return handleSpawnException(e, spawnOptions);
Comments
No one has commented yet.