00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _PASSENGER_SPAWN_OPTIONS_H_
00021 #define _PASSENGER_SPAWN_OPTIONS_H_
00022
00023 #include <string>
00024 #include "Utils.h"
00025
00026 namespace Passenger {
00027
00028 using namespace std;
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 struct PoolOptions {
00056
00057
00058
00059
00060
00061 string appRoot;
00062
00063
00064 bool lowerPrivilege;
00065
00066
00067
00068
00069 string lowestUser;
00070
00071
00072
00073
00074
00075 string environment;
00076
00077
00078
00079
00080
00081 string spawnMethod;
00082
00083
00084 string appType;
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 long frameworkSpawnerTimeout;
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 long appSpawnerTimeout;
00107
00108
00109
00110
00111
00112 unsigned long maxRequests;
00113
00114
00115
00116
00117
00118 unsigned long memoryLimit;
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 bool useGlobalQueue;
00131
00132
00133
00134
00135
00136
00137 unsigned long statThrottleRate;
00138
00139
00140
00141
00142
00143 string restartDir;
00144
00145
00146
00147
00148
00149 PoolOptions() {
00150 lowerPrivilege = true;
00151 lowestUser = "nobody";
00152 environment = "production";
00153 spawnMethod = "smart";
00154 appType = "rails";
00155 frameworkSpawnerTimeout = -1;
00156 appSpawnerTimeout = -1;
00157 maxRequests = 0;
00158 memoryLimit = 0;
00159 useGlobalQueue = false;
00160 statThrottleRate = 0;
00161 }
00162
00163
00164
00165
00166 PoolOptions(const string &appRoot,
00167 bool lowerPrivilege = true,
00168 const string &lowestUser = "nobody",
00169 const string &environment = "production",
00170 const string &spawnMethod = "smart",
00171 const string &appType = "rails",
00172 long frameworkSpawnerTimeout = -1,
00173 long appSpawnerTimeout = -1,
00174 unsigned long maxRequests = 0,
00175 unsigned long memoryLimit = 0,
00176 bool useGlobalQueue = false,
00177 unsigned long statThrottleRate = 0,
00178 const string &restartDir = ""
00179 ) {
00180 this->appRoot = appRoot;
00181 this->lowerPrivilege = lowerPrivilege;
00182 this->lowestUser = lowestUser;
00183 this->environment = environment;
00184 this->spawnMethod = spawnMethod;
00185 this->appType = appType;
00186 this->frameworkSpawnerTimeout = frameworkSpawnerTimeout;
00187 this->appSpawnerTimeout = appSpawnerTimeout;
00188 this->maxRequests = maxRequests;
00189 this->memoryLimit = memoryLimit;
00190 this->useGlobalQueue = useGlobalQueue;
00191 this->statThrottleRate = statThrottleRate;
00192 this->restartDir = restartDir;
00193 }
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214 PoolOptions(const vector<string> &vec, unsigned int startIndex = 0) {
00215 appRoot = vec[startIndex + 1];
00216 lowerPrivilege = vec[startIndex + 3] == "true";
00217 lowestUser = vec[startIndex + 5];
00218 environment = vec[startIndex + 7];
00219 spawnMethod = vec[startIndex + 9];
00220 appType = vec[startIndex + 11];
00221 frameworkSpawnerTimeout = atol(vec[startIndex + 13]);
00222 appSpawnerTimeout = atol(vec[startIndex + 15]);
00223 maxRequests = atol(vec[startIndex + 17]);
00224 memoryLimit = atol(vec[startIndex + 19]);
00225 useGlobalQueue = vec[startIndex + 21] == "true";
00226 statThrottleRate = atol(vec[startIndex + 23]);
00227 restartDir = vec[startIndex + 25];
00228 }
00229
00230
00231
00232
00233
00234
00235 void toVector(vector<string> &vec) const {
00236 if (vec.capacity() < vec.size() + 10) {
00237 vec.reserve(vec.size() + 10);
00238 }
00239 appendKeyValue (vec, "app_root", appRoot);
00240 appendKeyValue (vec, "lower_privilege", lowerPrivilege ? "true" : "false");
00241 appendKeyValue (vec, "lowest_user", lowestUser);
00242 appendKeyValue (vec, "environment", environment);
00243 appendKeyValue (vec, "spawn_method", spawnMethod);
00244 appendKeyValue (vec, "app_type", appType);
00245 appendKeyValue2(vec, "framework_spawner_timeout", frameworkSpawnerTimeout);
00246 appendKeyValue2(vec, "app_spawner_timeout", appSpawnerTimeout);
00247 appendKeyValue3(vec, "max_requests", maxRequests);
00248 appendKeyValue3(vec, "memory_limit", memoryLimit);
00249 appendKeyValue (vec, "use_global_queue", useGlobalQueue ? "true" : "false");
00250 appendKeyValue3(vec, "stat_throttle_rate", statThrottleRate);
00251 appendKeyValue (vec, "restart_dir", restartDir);
00252 }
00253
00254 private:
00255 static inline void
00256 appendKeyValue(vector<string> &vec, const char *key, const string &value) {
00257 vec.push_back(key);
00258 vec.push_back(const_cast<string &>(value));
00259 }
00260
00261 static inline void
00262 appendKeyValue(vector<string> &vec, const char *key, const char *value) {
00263 vec.push_back(key);
00264 vec.push_back(value);
00265 }
00266
00267 static inline void
00268 appendKeyValue2(vector<string> &vec, const char *key, long value) {
00269 vec.push_back(key);
00270 vec.push_back(toString(value));
00271 }
00272
00273 static inline void
00274 appendKeyValue3(vector<string> &vec, const char *key, unsigned long value) {
00275 vec.push_back(key);
00276 vec.push_back(toString(value));
00277 }
00278 };
00279
00280 }
00281
00282 #endif
00283