#include <StandardApplicationPool.h>
The environment may or may not be multithreaded - StandardApplicationPool is completely thread-safe. Apache with the threading MPM is an example of a multithreaded single-process environment.
This class is unusable in multi-process environments such as Apache with the prefork MPM. The reasons are as follows:
(Of course, StandardApplicationPool is usable if each process creates its own StandardApplicationPool object, but that would defeat the point of having a shared pool.)
For multi-process environments, one should use ApplicationPoolServer instead.
Public Member Functions | |
StandardApplicationPool (const string &spawnServerCommand, const string &logFile="", const string &environment="production", const string &rubyCommand="ruby", const string &user="") | |
Create a new StandardApplicationPool object. | |
virtual Application::SessionPtr | get (const string &appRoot, bool lowerPrivilege=true, const string &lowestUser="nobody") |
Open a new session with the application specified by appRoot . | |
virtual void | clear () |
Clear all application instances that are currently in the pool. | |
virtual void | setMax (unsigned int max) |
Set a hard limit on the number of application instances that this ApplicationPool may spawn. | |
virtual unsigned int | getActive () const |
Get the number of active applications in the pool. | |
virtual unsigned int | getCount () const |
Get the number of active applications in the pool. | |
virtual pid_t | getSpawnServerPid () const |
Get the process ID of the spawn server that is used. |
Passenger::StandardApplicationPool::StandardApplicationPool | ( | const string & | spawnServerCommand, | |
const string & | logFile = "" , |
|||
const string & | environment = "production" , |
|||
const string & | rubyCommand = "ruby" , |
|||
const string & | user = "" | |||
) | [inline] |
Create a new StandardApplicationPool object.
spawnServerCommand | The filename of the spawn server to use. | |
logFile | Specify a log file that the spawn server should use. Messages on its standard output and standard error channels will be written to this log file. If an empty string is specified, no log file will be used, and the spawn server will use the same standard output/error channels as the current process. | |
environment | The RAILS_ENV environment that all RoR applications should use. If an empty string is specified, the current value of the RAILS_ENV environment variable will be used. | |
rubyCommand | The Ruby interpreter's command. | |
user | The user that the spawn manager should run as. This parameter only has effect if the current process is running as root. If the empty string is given, or if the user is not a valid username, then the spawn manager will be run as the current user. | |
rubyCommand | The Ruby interpreter's command. |
SystemException | An error occured while trying to setup the spawn server. | |
IOException | The specified log file could not be opened. |
virtual Application::SessionPtr Passenger::StandardApplicationPool::get | ( | const string & | appRoot, | |
bool | lowerPrivilege = true , |
|||
const string & | lowestUser = "nobody" | |||
) | [inline, virtual] |
Open a new session with the application specified by appRoot
.
See the class description for ApplicationPool, as well as Application::connect(), on how to use the returned session object.
Internally, this method may either spawn a new application instance, or use an existing one.
If lowerPrivilege
is true, then any newly spawned application instances will have lower privileges. See SpawnManager::SpawnManager()'s description of lowerPrivilege
and lowestUser
for details.
appRoot | The application root of a RoR application, i.e. the folder that contains 'app/', 'public/', 'config/', etc. This must be a valid directory, but does not have to be an absolute path. | |
lowerPrivilege | Whether to lower the application's privileges. | |
lowestUser | The user to fallback to if lowering privilege fails. |
SpawnException | An attempt was made to spawn a new application instance, but that attempt failed. | |
IOException | Something else went wrong. |
appRoot
does not have to be absolute, it should be. If one calls get("/home/foo")
and get("/home/../home/foo")
, then ApplicationPool will think they're 2 different applications, and thus will spawn 2 application instances. Implements Passenger::ApplicationPool.
virtual void Passenger::StandardApplicationPool::clear | ( | ) | [inline, virtual] |
Clear all application instances that are currently in the pool.
This method is used by unit tests to verify that the implementation is correct, and thus should not be called directly.
Implements Passenger::ApplicationPool.
virtual void Passenger::StandardApplicationPool::setMax | ( | unsigned int | max | ) | [inline, virtual] |
Set a hard limit on the number of application instances that this ApplicationPool may spawn.
The exact behavior depends on the used algorithm, and is not specified by these API docs.
It is allowed to set a limit lower than the current number of spawned applications.
Implements Passenger::ApplicationPool.
virtual unsigned int Passenger::StandardApplicationPool::getActive | ( | ) | const [inline, virtual] |
Get the number of active applications in the pool.
This method exposes an implementation detail of the underlying pooling algorithm. It is used by unit tests to verify that the implementation is correct, and thus should not be called directly.
Implements Passenger::ApplicationPool.
virtual unsigned int Passenger::StandardApplicationPool::getCount | ( | ) | const [inline, virtual] |
Get the number of active applications in the pool.
This method exposes an implementation detail of the underlying pooling algorithm. It is used by unit tests to verify that the implementation is correct, and thus should not be called directly.
Implements Passenger::ApplicationPool.
virtual pid_t Passenger::StandardApplicationPool::getSpawnServerPid | ( | ) | const [inline, virtual] |
Get the process ID of the spawn server that is used.
This method exposes an implementation detail. It is used by unit tests to verify that the implementation is correct, and thus should not be used directly.
Implements Passenger::ApplicationPool.