- Main Page
- Modules
- Classes
- Files

- File List

# Configuration.h

    00001 /*
    00002  *  Phusion Passenger - http://www.modrails.com/
    00003  *  Copyright (c) 2008, 2009 Phusion
    00004  *
    00005  *  "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
    00006  *
    00007  *  Permission is hereby granted, free of charge, to any person obtaining a copy
    00008  *  of this software and associated documentation files (the "Software"), to deal
    00009  *  in the Software without restriction, including without limitation the rights
    00010  *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00011  *  copies of the Software, and to permit persons to whom the Software is
    00012  *  furnished to do so, subject to the following conditions:
    00013  *
    00014  *  The above copyright notice and this permission notice shall be included in
    00015  *  all copies or substantial portions of the Software.
    00016  *
    00017  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00018  *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00019  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00020  *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00021  *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00022  *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00023  *  THE SOFTWARE.
    00024  */
    00025 #ifndef _PASSENGER_CONFIGURATION_H_
    00026 #define _PASSENGER_CONFIGURATION_H_
    00027
    00028 #ifdef __cplusplus
    00029         #include "Utils.h"
    00030         #include "MessageChannel.h"
    00031         #include "Logging.h"
    00032 #endif
    00033
    00034 /* The APR headers must come after the Passenger headers. See Hooks.cpp
    00035  * to learn why.
    00036  *
    00037  * MessageChannel.h must be included -- even though we don't actually use
    00038  * MessageChannel.h in here, it's necessary to make sure that apr_want.h
    00039  * doesn't b0rk on 'struct iovec'.
    00040  */
    00041 #include <apr_pools.h>
    00042 #include <httpd.h>
    00043 #include <http_config.h>
    00044
    00045 /**
    00046  * @defgroup Configuration Apache module configuration
    00047  * @ingroup Core
    00048  * @{
    00049  */
    00050
    00051 #ifdef __cplusplus
    00052         #include <set>
    00053         #include <string>
    00054
    00055         namespace Passenger {
    00056
    00057                 using namespace std;
    00058
    00059                 /**
    00060                  * Per-directory configuration information.
    00061                  *
    00062                  * Use the getter methods to query information, because those will return
    00063                  * the default value if the value is not specified.
    00064                  */
    00065                 struct DirConfig {
    00066                         enum Threeway { ENABLED, DISABLED, UNSET };
    00067                         enum SpawnMethod { SM_UNSET, SM_SMART, SM_SMART_LV2, SM_CONSERVATIVE };
    00068
    00069                         Threeway enabled;
    00070
    00071                         std::set<std::string> railsBaseURIs;
    00072                         std::set<std::string> rackBaseURIs;
    00073
    00074                         /** Whether to autodetect Rails applications. */
    00075                         Threeway autoDetectRails;
    00076
    00077                         /** Whether to autodetect Rack applications. */
    00078                         Threeway autoDetectRack;
    00079
    00080                         /** Whether to autodetect WSGI applications. */
    00081                         Threeway autoDetectWSGI;
    00082
    00083                         /** Whether mod_rewrite should be allowed for Rails applications. */
    00084                         Threeway allowModRewrite;
    00085
    00086                         /** The environment (i.e. value for RAILS_ENV) under which
    00087                          * Rails applications should operate. */
    00088                         const char *railsEnv;
    00089
    00090                         /** The path to the application's root (for example: RAILS_ROOT
    00091                          * for Rails applications, directory containing 'config.ru'
    00092                          * for Rack applications). If this value is NULL, the default
    00093                          * autodetected path will be used.
    00094                          */
    00095                         const char *appRoot;
    00096
    00097                         /** The environment (i.e. value for RACK_ENV) under which
    00098                          * Rack applications should operate. */
    00099                         const char *rackEnv;
    00100
    00101                         /** The Rails spawn method to use. */
    00102                         SpawnMethod spawnMethod;
    00103
    00104                         /**
    00105                          * The idle timeout, in seconds, of Rails framework spawners.
    00106                          * May also be 0 (which indicates that the framework spawner should
    00107                          * never idle timeout) or -1 (which means that the value is not specified).
    00108                          */
    00109                         long frameworkSpawnerTimeout;
    00110
    00111                         /**
    00112                          * The idle timeout, in seconds, of Rails application spawners.
    00113                          * May also be 0 (which indicates that the application spawner should
    00114                          * never idle timeout) or -1 (which means that the value is not specified).
    00115                          */
    00116                         long appSpawnerTimeout;
    00117
    00118                         /**
    00119                          * The maximum number of requests that the spawned application may process
    00120                          * before exiting. A value of 0 means unlimited.
    00121                          */
    00122                         unsigned long maxRequests;
    00123
    00124                         /** Indicates whether the maxRequests option was explicitly specified
    00125                          * in the directory configuration. */
    00126                         bool maxRequestsSpecified;
    00127
    00128                         /**
    00129                          * The maximum amount of memory (in MB) the spawned application may use.
    00130                          * A value of 0 means unlimited.
    00131                          */
    00132                         unsigned long memoryLimit;
    00133
    00134                         /** Indicates whether the memoryLimit option was explicitly specified
    00135                          * in the directory configuration. */
    00136                         bool memoryLimitSpecified;
    00137
    00138                         /** Whether symlinks in the document root path should be resolved.
    00139                          * The implication of this is documented in the users guide, section
    00140                          * "How Phusion Passenger detects whether a virtual host is a web application".
    00141                          */
    00142                         Threeway resolveSymlinksInDocRoot;
    00143
    00144                         /** Whether high performance mode should be turned on. */
    00145                         Threeway highPerformance;
    00146
    00147                         /** Whether global queuing should be used. */
    00148                         Threeway useGlobalQueue;
    00149
    00150                         /**
    00151                          * Whether encoded slashes in URLs should be supported. This however conflicts
    00152                          * with mod_rewrite support because of a bug/limitation in Apache, so it's one
    00153                          * or the other.
    00154                          */
    00155                         Threeway allowEncodedSlashes;
    00156
    00157                         /**
    00158                          * Throttle the number of stat() calls on files like
    00159                          * restart.txt to the once per given number of seconds.
    00160                          */
    00161                         unsigned long statThrottleRate;
    00162
    00163                         /** Indicates whether the statThrottleRate option was
    00164                          * explicitly specified in the directory configuration. */
    00165                         bool statThrottleRateSpecified;
    00166
    00167                         /** The directory in which Passenger should look for
    00168                          * restart.txt. NULL means that the default directory
    00169                          * should be used.
    00170                          */
    00171                         const char *restartDir;
    00172
    00173                         /**
    00174                          * The directory in which Passenger should place upload buffer
    00175                          * files. NULL means that the default directory should be used.
    00176                          */
    00177                         const char *uploadBufferDir;
    00178
    00179                         /*************************************/
    00180                         /*************************************/
    00181
    00182                         bool isEnabled() const {
    00183                                 return enabled != DISABLED;
    00184                         }
    00185
    00186                         string getAppRoot(const char *documentRoot) const {
    00187                                 if (appRoot == NULL) {
    00188                                         if (resolveSymlinksInDocRoot == DirConfig::ENABLED) {
    00189                                                 return extractDirName(resolveSymlink(documentRoot));
    00190                                         } else {
    00191                                                 return extractDirName(documentRoot);
    00192                                         }
    00193                                 } else {
    00194                                         return appRoot;
    00195                                 }
    00196                         }
    00197
    00198                         string getAppRoot(const string &documentRoot) const {
    00199                                 if (appRoot == NULL) {
    00200                                         if (resolveSymlinksInDocRoot == DirConfig::ENABLED) {
    00201                                                 return extractDirName(resolveSymlink(documentRoot));
    00202                                         } else {
    00203                                                 return extractDirName(documentRoot);
    00204                                         }
    00205                                 } else {
    00206                                         return appRoot;
    00207                                 }
    00208                         }
    00209
    00210                         const char *getRailsEnv() const {
    00211                                 if (railsEnv != NULL) {
    00212                                         return railsEnv;
    00213                                 } else {
    00214                                         return "production";
    00215                                 }
    00216                         }
    00217
    00218                         const char *getRackEnv() const {
    00219                                 if (rackEnv != NULL) {
    00220                                         return rackEnv;
    00221                                 } else {
    00222                                         return "production";
    00223                                 }
    00224                         }
    00225
    00226                         const char *getSpawnMethodString() {
    00227                                 switch (spawnMethod) {
    00228                                 case SM_SMART:
    00229                                         return "smart";
    00230                                 case SM_SMART_LV2:
    00231                                         return "smart-lv2";
    00232                                 case SM_CONSERVATIVE:
    00233                                         return "conservative";
    00234                                 default:
    00235                                         return "smart-lv2";
    00236                                 }
    00237                         }
    00238
    00239                         unsigned long getMaxRequests() {
    00240                                 if (maxRequestsSpecified) {
    00241                                         return maxRequests;
    00242                                 } else {
    00243                                         return 0;
    00244                                 }
    00245                         }
    00246
    00247                         unsigned long getMemoryLimit() {
    00248                                 if (memoryLimitSpecified) {
    00249                                         return memoryLimit;
    00250                                 } else {
    00251                                         return 200;
    00252                                 }
    00253                         }
    00254
    00255                         bool highPerformanceMode() const {
    00256                                 return highPerformance == ENABLED;
    00257                         }
    00258
    00259                         bool usingGlobalQueue() const {
    00260                                 return useGlobalQueue == ENABLED;
    00261                         }
    00262
    00263                         bool allowsEncodedSlashes() const {
    00264                                 return allowEncodedSlashes == ENABLED;
    00265                         }
    00266
    00267                         unsigned long getStatThrottleRate() const {
    00268                                 if (statThrottleRateSpecified) {
    00269                                         return statThrottleRate;
    00270                                 } else {
    00271                                         return 0;
    00272                                 }
    00273                         }
    00274
    00275                         const char *getRestartDir() const {
    00276                                 if (restartDir != NULL) {
    00277                                         return restartDir;
    00278                                 } else {
    00279                                         return "";
    00280                                 }
    00281                         }
    00282
    00283                         string getUploadBufferDir() const {
    00284                                 if (uploadBufferDir != NULL) {
    00285                                         return uploadBufferDir;
    00286                                 } else {
    00287                                         return getPassengerTempDir() + "/webserver_private";
    00288                                 }
    00289                         }
    00290
    00291                         /*************************************/
    00292                 };
    00293
    00294                 /**
    00295                  * Server-wide (global, not per-virtual host) configuration information.
    00296                  *
    00297                  * Use the getter methods to query information, because those will return
    00298                  * the default value if the value is not specified.
    00299                  */
    00300                 struct ServerConfig {
    00301                         /** The filename of the Ruby interpreter to use. */
    00302                         const char *ruby;
    00303
    00304                         /** The Passenger root folder. */
    00305                         const char *root;
    00306
    00307                         /** The log verbosity. */
    00308                         unsigned int logLevel;
    00309
    00310                         /** The maximum number of simultaneously alive application
    00311                          * instances. */
    00312                         unsigned int maxPoolSize;
    00313
    00314                         /** Whether the maxPoolSize option was explicitly specified in
    00315                          * this server config. */
    00316                         bool maxPoolSizeSpecified;
    00317
    00318                         /** The maximum number of simultaneously alive Rails application
    00319                          * that a single Rails application may occupy. */
    00320                         unsigned int maxInstancesPerApp;
    00321
    00322                         /** Whether the maxInstancesPerApp option was explicitly specified in
    00323                          * this server config. */
    00324                         bool maxInstancesPerAppSpecified;
    00325
    00326                         /** The maximum number of seconds that an application may be
    00327                          * idle before it gets terminated. */
    00328                         unsigned int poolIdleTime;
    00329
    00330                         /** Whether the poolIdleTime option was explicitly specified in
    00331                          * this server config. */
    00332                         bool poolIdleTimeSpecified;
    00333
    00334                         /** Whether user switching support is enabled. */
    00335                         bool userSwitching;
    00336
    00337                         /** Whether the userSwitching option was explicitly specified in
    00338                          * this server config. */
    00339                         bool userSwitchingSpecified;
    00340
    00341                         /** The user that applications must run as if user switching
    00342                          * fails or is disabled. NULL means the option is not specified.
    00343                          */
    00344                         const char *defaultUser;
    00345
    00346                         /** The temp directory that Passenger should use. NULL
    00347                          * means unspecified.
    00348                          */
    00349                         const char *tempDir;
    00350
    00351                         const char *getRuby() const {
    00352                                 if (ruby != NULL) {
    00353                                         return ruby;
    00354                                 } else {
    00355                                         return "ruby";
    00356                                 }
    00357                         }
    00358
    00359                         const char *getDefaultUser() const {
    00360                                 if (defaultUser != NULL) {
    00361                                         return defaultUser;
    00362                                 } else {
    00363                                         return "nobody";
    00364                                 }
    00365                         }
    00366
    00367                         const char *getTempDir() const {
    00368                                 if (tempDir != NULL) {
    00369                                         return tempDir;
    00370                                 } else {
    00371                                         return getSystemTempDir();
    00372                                 }
    00373                         }
    00374                 };
    00375         }
    00376
    00377         extern "C" {
    00378 #endif
    00379
    00380 /** Configuration hook for per-directory configuration structure creation. */
    00381 void *passenger_config_create_dir(apr_pool_t *p, char *dirspec);
    00382
    00383 /** Configuration hook for per-directory configuration structure merging. */
    00384 void *passenger_config_merge_dir(apr_pool_t *p, void *basev, void *addv);
    00385
    00386 /** Configuration hook for per-server configuration structure creation. */
    00387 void *passenger_config_create_server(apr_pool_t *p, server_rec *s);
    00388
    00389 /** Configuration hook for per-server configuration structure merging. */
    00390 void *passenger_config_merge_server(apr_pool_t *p, void *basev, void *overridesv);
    00391
    00392 void passenger_config_merge_all_servers(apr_pool_t *pool, server_rec *main_server);
    00393
    00394 /** Apache module commands array. */
    00395 extern const command_rec passenger_commands[];
    00396
    00397 #ifdef __cplusplus
    00398         }
    00399 #endif
    00400
    00401 /**
    00402  * @}
    00403  */
    00404
    00405 #endif /* _PASSENGER_CONFIGURATION_H_ */