- Main Page
- Modules
- Classes
- Files

# Configuration.h

    00001 /*
    00002  *  Phusion Passenger - http://www.modrails.com/
    00003  *  Copyright (C) 2008  Phusion
    00004  *
    00005  *  Phusion Passenger is a trademark of Hongli Lai & Ninh Bui.
    00006  *
    00007  *  This program is free software; you can redistribute it and/or modify
    00008  *  it under the terms of the GNU General Public License as published by
    00009  *  the Free Software Foundation; version 2 of the License.
    00010  *
    00011  *  This program is distributed in the hope that it will be useful,
    00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00014  *  GNU General Public License for more details.
    00015  *
    00016  *  You should have received a copy of the GNU General Public License along
    00017  *  with this program; if not, write to the Free Software Foundation, Inc.,
    00018  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    00019  */
    00020 #ifndef _PASSENGER_CONFIGURATION_H_
    00021 #define _PASSENGER_CONFIGURATION_H_
    00022
    00023 #include "Utils.h"
    00024 #include "MessageChannel.h"
    00025
    00026 /* The APR headers must come after the Passenger headers. See Hooks.cpp
    00027  * to learn why.
    00028  *
    00029  * MessageChannel.h must be included -- even though we don't actually use
    00030  * MessageChannel.h in here, it's necessary to make sure that apr_want.h
    00031  * doesn't b0rk on 'struct iovec'.
    00032  */
    00033 #include <apr_pools.h>
    00034 #include <httpd.h>
    00035 #include <http_config.h>
    00036
    00037 /**
    00038  * @defgroup Configuration Apache module configuration
    00039  * @ingroup Core
    00040  * @{
    00041  */
    00042
    00043 /** Module version number. */
    00044 #define PASSENGER_VERSION "2.1.3"
    00045
    00046 #ifdef __cplusplus
    00047         #include <set>
    00048         #include <string>
    00049
    00050         namespace Passenger {
    00051
    00052                 using namespace std;
    00053
    00054                 /**
    00055                  * Per-directory configuration information.
    00056                  *
    00057                  * Use the getter methods to query information, because those will return
    00058                  * the default value if the value is not specified.
    00059                  */
    00060                 struct DirConfig {
    00061                         enum Threeway { ENABLED, DISABLED, UNSET };
    00062                         enum SpawnMethod { SM_UNSET, SM_SMART, SM_SMART_LV2, SM_CONSERVATIVE };
    00063
    00064                         Threeway enabled;
    00065
    00066                         std::set<std::string> railsBaseURIs;
    00067                         std::set<std::string> rackBaseURIs;
    00068
    00069                         /** Whether to autodetect Rails applications. */
    00070                         Threeway autoDetectRails;
    00071
    00072                         /** Whether to autodetect Rack applications. */
    00073                         Threeway autoDetectRack;
    00074
    00075                         /** Whether to autodetect WSGI applications. */
    00076                         Threeway autoDetectWSGI;
    00077
    00078                         /** Whether mod_rewrite should be allowed for Rails applications. */
    00079                         Threeway allowModRewrite;
    00080
    00081                         /** The environment (i.e. value for RAILS_ENV) under which
    00082                          * Rails applications should operate. */
    00083                         const char *railsEnv;
    00084
    00085                         /** The path to the application's root (for example: RAILS_ROOT
    00086                          * for Rails applications, directory containing 'config.ru'
    00087                          * for Rack applications). If this value is NULL, the default
    00088                          * autodetected path will be used.
    00089                          */
    00090                         const char *appRoot;
    00091
    00092                         /** The environment (i.e. value for RACK_ENV) under which
    00093                          * Rack applications should operate. */
    00094                         const char *rackEnv;
    00095
    00096                         /** The Rails spawn method to use. */
    00097                         SpawnMethod spawnMethod;
    00098
    00099                         /**
    00100                          * The idle timeout, in seconds, of Rails framework spawners.
    00101                          * May also be 0 (which indicates that the framework spawner should
    00102                          * never idle timeout) or -1 (which means that the value is not specified).
    00103                          */
    00104                         long frameworkSpawnerTimeout;
    00105
    00106                         /**
    00107                          * The idle timeout, in seconds, of Rails application spawners.
    00108                          * May also be 0 (which indicates that the application spawner should
    00109                          * never idle timeout) or -1 (which means that the value is not specified).
    00110                          */
    00111                         long appSpawnerTimeout;
    00112
    00113                         /**
    00114                          * The maximum number of requests that the spawned application may process
    00115                          * before exiting. A value of 0 means unlimited.
    00116                          */
    00117                         unsigned long maxRequests;
    00118
    00119                         /** Indicates whether the maxRequests option was explicitly specified
    00120                          * in the directory configuration. */
    00121                         bool maxRequestsSpecified;
    00122
    00123                         /**
    00124                          * The maximum amount of memory (in MB) the spawned application may use.
    00125                          * A value of 0 means unlimited.
    00126                          */
    00127                         unsigned long memoryLimit;
    00128
    00129                         /** Indicates whether the memoryLimit option was explicitly specified
    00130                          * in the directory configuration. */
    00131                         bool memoryLimitSpecified;
    00132
    00133                         Threeway highPerformance;
    00134
    00135                         /** Whether global queuing should be used. */
    00136                         Threeway useGlobalQueue;
    00137
    00138                         /**
    00139                          * Throttle the number of stat() calls on files like
    00140                          * restart.txt to the once per given number of seconds.
    00141                          */
    00142                         unsigned long statThrottleRate;
    00143
    00144                         /** Indicates whether the statThrottleRate option was
    00145                          * explicitly specified in the directory configuration. */
    00146                         bool statThrottleRateSpecified;
    00147
    00148                         /** The directory in which Passenger should look for
    00149                          * restart.txt. NULL means that the default directory
    00150                          * should be used.
    00151                          */
    00152                         const char *restartDir;
    00153
    00154                         /*************************************/
    00155
    00156                         bool isEnabled() const {
    00157                                 return enabled != DISABLED;
    00158                         }
    00159
    00160                         string getAppRoot(const char *documentRoot) const {
    00161                                 if (appRoot == NULL) {
    00162                                         return string(documentRoot).append("/..");
    00163                                 } else {
    00164                                         return appRoot;
    00165                                 }
    00166                         }
    00167
    00168                         const char *getRailsEnv() const {
    00169                                 if (railsEnv != NULL) {
    00170                                         return railsEnv;
    00171                                 } else {
    00172                                         return "production";
    00173                                 }
    00174                         }
    00175
    00176                         const char *getRackEnv() const {
    00177                                 if (rackEnv != NULL) {
    00178                                         return rackEnv;
    00179                                 } else {
    00180                                         return "production";
    00181                                 }
    00182                         }
    00183
    00184                         const char *getSpawnMethodString() {
    00185                                 switch (spawnMethod) {
    00186                                 case SM_SMART:
    00187                                         return "smart";
    00188                                 case SM_SMART_LV2:
    00189                                         return "smart-lv2";
    00190                                 case SM_CONSERVATIVE:
    00191                                         return "conservative";
    00192                                 default:
    00193                                         return "smart-lv2";
    00194                                 }
    00195                         }
    00196
    00197                         unsigned long getMaxRequests() {
    00198                                 if (maxRequestsSpecified) {
    00199                                         return maxRequests;
    00200                                 } else {
    00201                                         return 0;
    00202                                 }
    00203                         }
    00204
    00205                         unsigned long getMemoryLimit() {
    00206                                 if (memoryLimitSpecified) {
    00207                                         return memoryLimit;
    00208                                 } else {
    00209                                         return 200;
    00210                                 }
    00211                         }
    00212
    00213                         bool highPerformanceMode() const {
    00214                                 return highPerformance == ENABLED;
    00215                         }
    00216
    00217                         bool usingGlobalQueue() const {
    00218                                 return useGlobalQueue == ENABLED;
    00219                         }
    00220
    00221                         unsigned long getStatThrottleRate() const {
    00222                                 if (statThrottleRateSpecified) {
    00223                                         return statThrottleRate;
    00224                                 } else {
    00225                                         return 0;
    00226                                 }
    00227                         }
    00228
    00229                         const char *getRestartDir() const {
    00230                                 if (restartDir != NULL) {
    00231                                         return restartDir;
    00232                                 } else {
    00233                                         return "";
    00234                                 }
    00235                         }
    00236
    00237                         /*************************************/
    00238                 };
    00239
    00240                 /**
    00241                  * Server-wide (global, not per-virtual host) configuration information.
    00242                  *
    00243                  * Use the getter methods to query information, because those will return
    00244                  * the default value if the value is not specified.
    00245                  */
    00246                 struct ServerConfig {
    00247                         /** The filename of the Ruby interpreter to use. */
    00248                         const char *ruby;
    00249
    00250                         /** The Passenger root folder. */
    00251                         const char *root;
    00252
    00253                         /** The log verbosity. */
    00254                         unsigned int logLevel;
    00255
    00256                         /** The maximum number of simultaneously alive application
    00257                          * instances. */
    00258                         unsigned int maxPoolSize;
    00259
    00260                         /** Whether the maxPoolSize option was explicitly specified in
    00261                          * this server config. */
    00262                         bool maxPoolSizeSpecified;
    00263
    00264                         /** The maximum number of simultaneously alive Rails application
    00265                          * that a single Rails application may occupy. */
    00266                         unsigned int maxInstancesPerApp;
    00267
    00268                         /** Whether the maxInstancesPerApp option was explicitly specified in
    00269                          * this server config. */
    00270                         bool maxInstancesPerAppSpecified;
    00271
    00272                         /** The maximum number of seconds that an application may be
    00273                          * idle before it gets terminated. */
    00274                         unsigned int poolIdleTime;
    00275
    00276                         /** Whether the poolIdleTime option was explicitly specified in
    00277                          * this server config. */
    00278                         bool poolIdleTimeSpecified;
    00279
    00280                         /** Whether user switching support is enabled. */
    00281                         bool userSwitching;
    00282
    00283                         /** Whether the userSwitching option was explicitly specified in
    00284                          * this server config. */
    00285                         bool userSwitchingSpecified;
    00286
    00287                         /** The user that applications must run as if user switching
    00288                          * fails or is disabled. NULL means the option is not specified.
    00289                          */
    00290                         const char *defaultUser;
    00291
    00292                         /** The temp directory that Passenger should use. NULL
    00293                          * means unspecified.
    00294                          */
    00295                         const char *tempDir;
    00296
    00297                         const char *getDefaultUser() const {
    00298                                 if (defaultUser != NULL) {
    00299                                         return defaultUser;
    00300                                 } else {
    00301                                         return "nobody";
    00302                                 }
    00303                         }
    00304
    00305                         const char *getTempDir() const {
    00306                                 if (tempDir != NULL) {
    00307                                         return tempDir;
    00308                                 } else {
    00309                                         return getSystemTempDir();
    00310                                 }
    00311                         }
    00312                 };
    00313         }
    00314
    00315         extern "C" {
    00316 #endif
    00317
    00318 /** Configuration hook for per-directory configuration structure creation. */
    00319 void *passenger_config_create_dir(apr_pool_t *p, char *dirspec);
    00320
    00321 /** Configuration hook for per-directory configuration structure merging. */
    00322 void *passenger_config_merge_dir(apr_pool_t *p, void *basev, void *addv);
    00323
    00324 /** Configuration hook for per-server configuration structure creation. */
    00325 void *passenger_config_create_server(apr_pool_t *p, server_rec *s);
    00326
    00327 /** Configuration hook for per-server configuration structure merging. */
    00328 void *passenger_config_merge_server(apr_pool_t *p, void *basev, void *overridesv);
    00329
    00330 void passenger_config_merge_all_servers(apr_pool_t *pool, server_rec *main_server);
    00331
    00332 /** Apache module commands array. */
    00333 extern const command_rec passenger_commands[];
    00334
    00335 #ifdef __cplusplus
    00336         }
    00337 #endif
    00338
    00339 /**
    00340  * @}
    00341  */
    00342
    00343 #endif /* _PASSENGER_CONFIGURATION_H_ */