passenger 5.0.9 → 5.0.10

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of passenger might be problematic. Click here for more details.

Files changed (106) hide show
  1. checksums.yaml +8 -8
  2. checksums.yaml.gz.asc +7 -7
  3. data.tar.gz.asc +7 -7
  4. data/CHANGELOG +15 -0
  5. data/CONTRIBUTORS +6 -0
  6. data/README.md +1 -1
  7. data/bin/passenger-install-apache2-module +24 -11
  8. data/bin/passenger-status +29 -14
  9. data/build/agents.rb +12 -10
  10. data/build/cxx_tests.rb +30 -30
  11. data/doc/Design and Architecture.html +1 -10
  12. data/doc/Design and Architecture.txt +1 -6
  13. data/doc/Users guide Apache.html +1 -19
  14. data/doc/Users guide Apache.txt +1 -1
  15. data/doc/Users guide Nginx.html +2 -20
  16. data/doc/Users guide Nginx.txt +2 -2
  17. data/doc/users_guide_snippets/tips.txt +0 -9
  18. data/ext/common/ApplicationPool2/ApiKey.h +158 -0
  19. data/ext/common/ApplicationPool2/BasicGroupInfo.h +81 -0
  20. data/ext/common/ApplicationPool2/BasicProcessInfo.h +106 -0
  21. data/ext/common/ApplicationPool2/Common.h +5 -44
  22. data/ext/common/ApplicationPool2/Context.h +94 -0
  23. data/ext/common/ApplicationPool2/Group.h +130 -1205
  24. data/ext/common/ApplicationPool2/Group/InitializationAndShutdown.cpp +190 -0
  25. data/ext/common/ApplicationPool2/Group/InternalUtils.cpp +329 -0
  26. data/ext/common/ApplicationPool2/Group/LifetimeAndBasics.cpp +103 -0
  27. data/ext/common/ApplicationPool2/{Pool/Debug.h → Group/Miscellaneous.cpp} +40 -38
  28. data/ext/common/ApplicationPool2/Group/OutOfBandWork.cpp +323 -0
  29. data/ext/common/ApplicationPool2/Group/ProcessListManagement.cpp +606 -0
  30. data/ext/common/ApplicationPool2/Group/SessionManagement.cpp +337 -0
  31. data/ext/common/ApplicationPool2/Group/SpawningAndRestarting.cpp +478 -0
  32. data/ext/common/ApplicationPool2/Group/StateInspection.cpp +197 -0
  33. data/ext/common/ApplicationPool2/Group/Verification.cpp +159 -0
  34. data/ext/common/ApplicationPool2/Implementation.cpp +19 -1401
  35. data/ext/common/ApplicationPool2/Options.h +5 -5
  36. data/ext/common/ApplicationPool2/Pool.h +260 -815
  37. data/ext/common/ApplicationPool2/Pool/{AnalyticsCollection.h → AnalyticsCollection.cpp} +55 -56
  38. data/ext/common/ApplicationPool2/Pool/{GarbageCollection.h → GarbageCollection.cpp} +49 -49
  39. data/ext/common/ApplicationPool2/Pool/GeneralUtils.cpp +241 -0
  40. data/ext/common/ApplicationPool2/Pool/GroupUtils.cpp +276 -0
  41. data/ext/common/ApplicationPool2/Pool/InitializationAndShutdown.cpp +145 -0
  42. data/ext/common/ApplicationPool2/Pool/Miscellaneous.cpp +244 -0
  43. data/ext/common/ApplicationPool2/Pool/ProcessUtils.cpp +330 -0
  44. data/ext/common/ApplicationPool2/Pool/StateInspection.cpp +299 -0
  45. data/ext/common/ApplicationPool2/Process.h +399 -205
  46. data/ext/common/ApplicationPool2/Session.h +70 -28
  47. data/ext/common/ApplicationPool2/Socket.h +1 -0
  48. data/ext/common/Constants.h +11 -3
  49. data/ext/common/Exceptions.h +1 -1
  50. data/ext/common/Logging.cpp +9 -4
  51. data/ext/common/Logging.h +6 -0
  52. data/ext/common/ServerKit/HttpServer.h +225 -215
  53. data/ext/common/ServerKit/Server.h +57 -57
  54. data/ext/common/SpawningKit/BackgroundIOCapturer.h +160 -0
  55. data/ext/common/SpawningKit/Config.h +107 -0
  56. data/ext/common/{ApplicationPool2 → SpawningKit}/DirectSpawner.h +17 -16
  57. data/ext/common/{ApplicationPool2 → SpawningKit}/DummySpawner.h +33 -33
  58. data/ext/common/{ApplicationPool2/SpawnerFactory.h → SpawningKit/Factory.h} +17 -17
  59. data/ext/common/{ApplicationPool2/ComponentInfo.h → SpawningKit/Options.h} +8 -21
  60. data/ext/common/SpawningKit/PipeWatcher.h +148 -0
  61. data/ext/common/{ApplicationPool2/PipeWatcher.h → SpawningKit/Result.h} +15 -33
  62. data/ext/common/{ApplicationPool2 → SpawningKit}/SmartSpawner.h +52 -57
  63. data/ext/common/{ApplicationPool2 → SpawningKit}/Spawner.h +83 -371
  64. data/ext/common/SpawningKit/UserSwitchingRules.h +265 -0
  65. data/ext/common/Utils/BufferedIO.h +24 -0
  66. data/ext/common/{ApplicationPool2/SpawnObject.h → Utils/ClassUtils.h} +24 -51
  67. data/ext/common/Utils/IOUtils.cpp +70 -0
  68. data/ext/common/Utils/IOUtils.h +19 -0
  69. data/ext/common/Utils/JsonUtils.h +113 -0
  70. data/ext/common/Utils/StrIntUtils.h +29 -0
  71. data/ext/common/Utils/json.h +1 -1
  72. data/ext/common/agents/ApiServerUtils.h +941 -0
  73. data/ext/common/agents/HelperAgent/{AdminServer.h → ApiServer.h} +163 -365
  74. data/ext/common/agents/HelperAgent/Main.cpp +86 -88
  75. data/ext/common/agents/HelperAgent/OptionParser.h +9 -10
  76. data/ext/common/agents/HelperAgent/RequestHandler/BufferBody.cpp +3 -0
  77. data/ext/common/agents/HelperAgent/RequestHandler/ForwardResponse.cpp +2 -0
  78. data/ext/common/agents/HelperAgent/RequestHandler/Hooks.cpp +1 -1
  79. data/ext/common/agents/HelperAgent/RequestHandler/SendRequest.cpp +2 -2
  80. data/ext/common/agents/LoggingAgent/ApiServer.h +279 -0
  81. data/ext/common/agents/LoggingAgent/Main.cpp +41 -51
  82. data/ext/common/agents/LoggingAgent/OptionParser.h +11 -11
  83. data/ext/common/agents/Watchdog/ApiServer.h +311 -0
  84. data/ext/common/agents/Watchdog/Main.cpp +91 -65
  85. data/helper-scripts/prespawn +2 -0
  86. data/lib/phusion_passenger.rb +1 -1
  87. data/lib/phusion_passenger/admin_tools/instance.rb +1 -1
  88. data/lib/phusion_passenger/common_library.rb +27 -14
  89. data/lib/phusion_passenger/config/{admin_command_command.rb → api_call_command.rb} +19 -16
  90. data/lib/phusion_passenger/config/detach_process_command.rb +6 -3
  91. data/lib/phusion_passenger/config/main.rb +3 -5
  92. data/lib/phusion_passenger/config/reopen_logs_command.rb +29 -7
  93. data/lib/phusion_passenger/config/restart_app_command.rb +13 -4
  94. data/lib/phusion_passenger/config/utils.rb +15 -8
  95. data/lib/phusion_passenger/constants.rb +6 -2
  96. data/lib/phusion_passenger/platform_info/apache.rb +4 -0
  97. data/lib/phusion_passenger/platform_info/apache_detector.rb +18 -3
  98. data/resources/templates/apache2/mpm_unknown.txt.erb +20 -0
  99. metadata +42 -21
  100. metadata.gz.asc +7 -7
  101. data/ext/common/ApplicationPool2/Pool/GeneralUtils.h +0 -127
  102. data/ext/common/ApplicationPool2/Pool/Inspection.h +0 -219
  103. data/ext/common/ApplicationPool2/Pool/ProcessUtils.h +0 -85
  104. data/ext/common/ApplicationPool2/SuperGroup.h +0 -706
  105. data/ext/common/agents/LoggingAgent/AdminServer.h +0 -435
  106. data/ext/common/agents/Watchdog/AdminServer.h +0 -432
@@ -0,0 +1,330 @@
1
+ /*
2
+ * Phusion Passenger - https://www.phusionpassenger.com/
3
+ * Copyright (c) 2011-2015 Phusion
4
+ *
5
+ * "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in
15
+ * all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ * THE SOFTWARE.
24
+ */
25
+ #include <ApplicationPool2/Pool.h>
26
+
27
+ /*************************************************************************
28
+ *
29
+ * Process data structure utility functions for ApplicationPool2::Pool
30
+ *
31
+ *************************************************************************/
32
+
33
+ namespace Passenger {
34
+ namespace ApplicationPool2 {
35
+
36
+ using namespace std;
37
+ using namespace boost;
38
+
39
+
40
+ /****************************
41
+ *
42
+ * Private methods
43
+ *
44
+ ****************************/
45
+
46
+
47
+ ProcessPtr
48
+ Pool::findOldestIdleProcess(const Group *exclude) const {
49
+ ProcessPtr oldestIdleProcess;
50
+
51
+ GroupMap::ConstIterator g_it(groups);
52
+ while (*g_it != NULL) {
53
+ const GroupPtr &group = g_it.getValue();
54
+ if (group.get() == exclude) {
55
+ g_it.next();
56
+ continue;
57
+ }
58
+ const ProcessList &processes = group->enabledProcesses;
59
+ ProcessList::const_iterator p_it, p_end = processes.end();
60
+ for (p_it = processes.begin(); p_it != p_end; p_it++) {
61
+ const ProcessPtr process = *p_it;
62
+ if (process->busyness() == 0
63
+ && (oldestIdleProcess == NULL
64
+ || process->lastUsed < oldestIdleProcess->lastUsed)
65
+ ) {
66
+ oldestIdleProcess = process;
67
+ }
68
+ }
69
+ g_it.next();
70
+ }
71
+
72
+ return oldestIdleProcess;
73
+ }
74
+
75
+ ProcessPtr
76
+ Pool::findBestProcessToTrash() const {
77
+ ProcessPtr oldestProcess;
78
+
79
+ GroupMap::ConstIterator g_it(groups);
80
+ while (*g_it != NULL) {
81
+ const GroupPtr &group = g_it.getValue();
82
+ const ProcessList &processes = group->enabledProcesses;
83
+ ProcessList::const_iterator p_it, p_end = processes.end();
84
+ for (p_it = processes.begin(); p_it != p_end; p_it++) {
85
+ const ProcessPtr process = *p_it;
86
+ if (oldestProcess == NULL
87
+ || process->lastUsed < oldestProcess->lastUsed) {
88
+ oldestProcess = process;
89
+ }
90
+ }
91
+ g_it.next();
92
+ }
93
+
94
+ return oldestProcess;
95
+ }
96
+
97
+ /**
98
+ * Calls Group::detach() so be sure to fix up the invariants afterwards.
99
+ * See the comments for Group::detach() and the code for detachProcessUnlocked().
100
+ */
101
+ ProcessPtr
102
+ Pool::forceFreeCapacity(const Group *exclude,
103
+ boost::container::vector<Callback> &postLockActions)
104
+ {
105
+ ProcessPtr process = findOldestIdleProcess(exclude);
106
+ if (process != NULL) {
107
+ P_DEBUG("Forcefully detaching process " << process->inspect() <<
108
+ " in order to free capacity in the pool");
109
+
110
+ Group *group = process->getGroup();
111
+ assert(group != NULL);
112
+ assert(group->getWaitlist.empty());
113
+
114
+ group->detach(process, postLockActions);
115
+ }
116
+ return process;
117
+ }
118
+
119
+ bool
120
+ Pool::detachProcessUnlocked(const ProcessPtr &process,
121
+ boost::container::vector<Callback> &postLockActions)
122
+ {
123
+ if (OXT_LIKELY(process->isAlive())) {
124
+ verifyInvariants();
125
+
126
+ Group *group = process->getGroup();
127
+ group->detach(process, postLockActions);
128
+ // 'process' may now be a stale pointer so don't use it anymore.
129
+ assignSessionsToGetWaiters(postLockActions);
130
+ possiblySpawnMoreProcessesForExistingGroups();
131
+
132
+ group->verifyInvariants();
133
+ verifyInvariants();
134
+ verifyExpensiveInvariants();
135
+
136
+ return true;
137
+ } else {
138
+ return false;
139
+ }
140
+ }
141
+
142
+ void
143
+ Pool::syncDisableProcessCallback(const ProcessPtr &process, DisableResult result,
144
+ boost::shared_ptr<DisableWaitTicket> ticket)
145
+ {
146
+ LockGuard l(ticket->syncher);
147
+ ticket->done = true;
148
+ ticket->result = result;
149
+ ticket->cond.notify_one();
150
+ }
151
+
152
+ void
153
+ Pool::possiblySpawnMoreProcessesForExistingGroups() {
154
+ /* Looks for Groups that are waiting for capacity to become available,
155
+ * and spawn processes in those groups.
156
+ */
157
+ GroupMap::ConstIterator g_it(groups);
158
+ while (*g_it != NULL) {
159
+ const GroupPtr &group = g_it.getValue();
160
+ if (group->isWaitingForCapacity()) {
161
+ P_DEBUG("Group " << group->getName() << " is waiting for capacity");
162
+ group->spawn();
163
+ if (atFullCapacityUnlocked()) {
164
+ return;
165
+ }
166
+ }
167
+ g_it.next();
168
+ }
169
+ /* Now look for Groups that haven't maximized their allowed capacity
170
+ * yet, and spawn processes in those groups.
171
+ */
172
+ g_it = GroupMap::ConstIterator(groups);
173
+ while (*g_it != NULL) {
174
+ const GroupPtr &group = g_it.getValue();
175
+ if (group->shouldSpawn()) {
176
+ P_DEBUG("Group " << group->getName() << " requests more processes to be spawned");
177
+ group->spawn();
178
+ if (atFullCapacityUnlocked()) {
179
+ return;
180
+ }
181
+ }
182
+ g_it.next();
183
+ }
184
+ }
185
+
186
+
187
+ /****************************
188
+ *
189
+ * Public methods
190
+ *
191
+ ****************************/
192
+
193
+
194
+ vector<ProcessPtr>
195
+ Pool::getProcesses(bool lock) const {
196
+ DynamicScopedLock l(syncher, lock);
197
+ vector<ProcessPtr> result;
198
+ GroupMap::ConstIterator g_it(groups);
199
+ while (*g_it != NULL) {
200
+ const GroupPtr &group = g_it.getValue();
201
+ ProcessList::const_iterator p_it;
202
+
203
+ for (p_it = group->enabledProcesses.begin(); p_it != group->enabledProcesses.end(); p_it++) {
204
+ result.push_back(*p_it);
205
+ }
206
+ for (p_it = group->disablingProcesses.begin(); p_it != group->disablingProcesses.end(); p_it++) {
207
+ result.push_back(*p_it);
208
+ }
209
+ for (p_it = group->disabledProcesses.begin(); p_it != group->disabledProcesses.end(); p_it++) {
210
+ result.push_back(*p_it);
211
+ }
212
+
213
+ g_it.next();
214
+ }
215
+ return result;
216
+ }
217
+
218
+ ProcessPtr
219
+ Pool::findProcessByGupid(const StaticString &gupid, bool lock) const {
220
+ vector<ProcessPtr> processes = getProcesses(lock);
221
+ vector<ProcessPtr>::const_iterator it, end = processes.end();
222
+ for (it = processes.begin(); it != end; it++) {
223
+ const ProcessPtr &process = *it;
224
+ if (process->getGupid() == gupid) {
225
+ return process;
226
+ }
227
+ }
228
+ return ProcessPtr();
229
+ }
230
+
231
+ ProcessPtr
232
+ Pool::findProcessByPid(pid_t pid, bool lock) const {
233
+ vector<ProcessPtr> processes = getProcesses(lock);
234
+ vector<ProcessPtr>::const_iterator it, end = processes.end();
235
+ for (it = processes.begin(); it != end; it++) {
236
+ const ProcessPtr &process = *it;
237
+ if (process->getPid() == pid) {
238
+ return process;
239
+ }
240
+ }
241
+ return ProcessPtr();
242
+ }
243
+
244
+ bool
245
+ Pool::detachProcess(const ProcessPtr &process) {
246
+ ScopedLock l(syncher);
247
+ boost::container::vector<Callback> actions;
248
+ bool result = detachProcessUnlocked(process, actions);
249
+ fullVerifyInvariants();
250
+ l.unlock();
251
+ runAllActions(actions);
252
+ return result;
253
+ }
254
+
255
+ bool
256
+ Pool::detachProcess(pid_t pid, const AuthenticationOptions &options) {
257
+ ScopedLock l(syncher);
258
+ ProcessPtr process = findProcessByPid(pid, false);
259
+ if (process != NULL) {
260
+ const Group *group = process->getGroup();
261
+ if (group->authorizeByUid(options.uid)
262
+ || group->authorizeByApiKey(options.apiKey))
263
+ {
264
+ boost::container::vector<Callback> actions;
265
+ bool result = detachProcessUnlocked(process, actions);
266
+ fullVerifyInvariants();
267
+ l.unlock();
268
+ runAllActions(actions);
269
+ return result;
270
+ } else {
271
+ throw SecurityException("Operation unauthorized");
272
+ }
273
+ } else {
274
+ return false;
275
+ }
276
+ }
277
+
278
+ bool
279
+ Pool::detachProcess(const string &gupid, const AuthenticationOptions &options) {
280
+ ScopedLock l(syncher);
281
+ ProcessPtr process = findProcessByGupid(gupid, false);
282
+ if (process != NULL) {
283
+ const Group *group = process->getGroup();
284
+ if (group->authorizeByUid(options.uid)
285
+ || group->authorizeByApiKey(options.apiKey))
286
+ {
287
+ boost::container::vector<Callback> actions;
288
+ bool result = detachProcessUnlocked(process, actions);
289
+ fullVerifyInvariants();
290
+ l.unlock();
291
+ runAllActions(actions);
292
+ return result;
293
+ } else {
294
+ throw SecurityException("Operation unauthorized");
295
+ }
296
+ } else {
297
+ return false;
298
+ }
299
+ }
300
+
301
+ DisableResult
302
+ Pool::disableProcess(const StaticString &gupid) {
303
+ ScopedLock l(syncher);
304
+ ProcessPtr process = findProcessByGupid(gupid, false);
305
+ if (process != NULL) {
306
+ Group *group = process->getGroup();
307
+ // Must be a boost::shared_ptr to be interruption-safe.
308
+ boost::shared_ptr<DisableWaitTicket> ticket = boost::make_shared<DisableWaitTicket>();
309
+ DisableResult result = group->disable(process,
310
+ boost::bind(syncDisableProcessCallback, _1, _2, ticket));
311
+ group->verifyInvariants();
312
+ group->verifyExpensiveInvariants();
313
+ if (result == DR_DEFERRED) {
314
+ l.unlock();
315
+ ScopedLock l2(ticket->syncher);
316
+ while (!ticket->done) {
317
+ ticket->cond.wait(l2);
318
+ }
319
+ return ticket->result;
320
+ } else {
321
+ return result;
322
+ }
323
+ } else {
324
+ return DR_NOOP;
325
+ }
326
+ }
327
+
328
+
329
+ } // namespace ApplicationPool2
330
+ } // namespace Passenger
@@ -0,0 +1,299 @@
1
+ /*
2
+ * Phusion Passenger - https://www.phusionpassenger.com/
3
+ * Copyright (c) 2011-2015 Phusion
4
+ *
5
+ * "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in
15
+ * all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ * THE SOFTWARE.
24
+ */
25
+ #include <ApplicationPool2/Pool.h>
26
+
27
+ /*************************************************************************
28
+ *
29
+ * State inspection functions for ApplicationPool2::Pool
30
+ *
31
+ *************************************************************************/
32
+
33
+ namespace Passenger {
34
+ namespace ApplicationPool2 {
35
+
36
+ using namespace std;
37
+ using namespace boost;
38
+
39
+
40
+ /****************************
41
+ *
42
+ * Private methods
43
+ *
44
+ ****************************/
45
+
46
+
47
+ unsigned int
48
+ Pool::capacityUsedUnlocked() const {
49
+ if (groups.size() == 1) {
50
+ GroupPtr *group;
51
+ groups.lookupRandom(NULL, &group);
52
+ return (*group)->capacityUsed();
53
+ } else {
54
+ GroupMap::ConstIterator g_it(groups);
55
+ int result = 0;
56
+ while (*g_it != NULL) {
57
+ const GroupPtr &group = g_it.getValue();
58
+ result += group->capacityUsed();
59
+ g_it.next();
60
+ }
61
+ return result;
62
+ }
63
+ }
64
+
65
+ bool
66
+ Pool::atFullCapacityUnlocked() const {
67
+ return capacityUsedUnlocked() >= max;
68
+ }
69
+
70
+ void
71
+ Pool::inspectProcessList(const InspectOptions &options, stringstream &result,
72
+ const Group *group, const ProcessList &processes) const
73
+ {
74
+ ProcessList::const_iterator p_it;
75
+ for (p_it = processes.begin(); p_it != processes.end(); p_it++) {
76
+ const ProcessPtr &process = *p_it;
77
+ char buf[128];
78
+ char cpubuf[10];
79
+ char membuf[10];
80
+
81
+ if (process->metrics.isValid()) {
82
+ snprintf(cpubuf, sizeof(cpubuf), "%d%%", (int) process->metrics.cpu);
83
+ snprintf(membuf, sizeof(membuf), "%ldM",
84
+ (unsigned long) (process->metrics.realMemory() / 1024));
85
+ } else {
86
+ snprintf(cpubuf, sizeof(cpubuf), "0%%");
87
+ snprintf(membuf, sizeof(membuf), "0M");
88
+ }
89
+ snprintf(buf, sizeof(buf),
90
+ " * PID: %-5lu Sessions: %-2u Processed: %-5u Uptime: %s\n"
91
+ " CPU: %-5s Memory : %-5s Last used: %s ago",
92
+ (unsigned long) process->getPid(),
93
+ process->sessions,
94
+ process->processed,
95
+ process->uptime().c_str(),
96
+ cpubuf,
97
+ membuf,
98
+ distanceOfTimeInWords(process->lastUsed / 1000000).c_str());
99
+ result << buf << endl;
100
+
101
+ if (process->enabled == Process::DISABLING) {
102
+ result << " Disabling..." << endl;
103
+ } else if (process->enabled == Process::DISABLED) {
104
+ result << " DISABLED" << endl;
105
+ } else if (process->enabled == Process::DETACHED) {
106
+ result << " Shutting down..." << endl;
107
+ }
108
+
109
+ const Socket *socket;
110
+ if (options.verbose && (socket = process->getSockets().findSocketWithName("http")) != NULL) {
111
+ result << " URL : http://" << replaceString(socket->address, "tcp://", "") << endl;
112
+ result << " Password: " << group->getApiKey().toStaticString() << endl;
113
+ }
114
+ }
115
+ }
116
+
117
+
118
+ /****************************
119
+ *
120
+ * Public methods
121
+ *
122
+ ****************************/
123
+
124
+
125
+ string
126
+ Pool::inspect(const InspectOptions &options, bool lock) const {
127
+ DynamicScopedLock l(syncher, lock);
128
+ stringstream result;
129
+ const char *headerColor = maybeColorize(options, ANSI_COLOR_YELLOW ANSI_COLOR_BLUE_BG ANSI_COLOR_BOLD);
130
+ const char *resetColor = maybeColorize(options, ANSI_COLOR_RESET);
131
+
132
+ if (!authorizeByUid(options.uid, false)
133
+ && !authorizeByApiKey(options.apiKey, false))
134
+ {
135
+ throw SecurityException("Operation unauthorized");
136
+ }
137
+
138
+ result << headerColor << "----------- General information -----------" << resetColor << endl;
139
+ result << "Max pool size : " << max << endl;
140
+ result << "App groups : " << groups.size() << endl;
141
+ result << "Processes : " << getProcessCount(false) << endl;
142
+ result << "Requests in top-level queue : " << getWaitlist.size() << endl;
143
+ if (options.verbose) {
144
+ unsigned int i = 0;
145
+ foreach (const GetWaiter &waiter, getWaitlist) {
146
+ result << " " << i << ": " << waiter.options.getAppGroupName() << endl;
147
+ i++;
148
+ }
149
+ }
150
+ result << endl;
151
+
152
+ result << headerColor << "----------- Application groups -----------" << resetColor << endl;
153
+ GroupMap::ConstIterator g_it(groups);
154
+ while (*g_it != NULL) {
155
+ const GroupPtr &group = g_it.getValue();
156
+ if (!group->authorizeByUid(options.uid)
157
+ && !group->authorizeByApiKey(options.apiKey))
158
+ {
159
+ g_it.next();
160
+ continue;
161
+ }
162
+
163
+ ProcessList::const_iterator p_it;
164
+
165
+ result << group->getName() << ":" << endl;
166
+ result << " App root: " << group->options.appRoot << endl;
167
+ if (group->restarting()) {
168
+ result << " (restarting...)" << endl;
169
+ }
170
+ if (group->spawning()) {
171
+ if (group->processesBeingSpawned == 0) {
172
+ result << " (spawning...)" << endl;
173
+ } else {
174
+ result << " (spawning " << group->processesBeingSpawned << " new " <<
175
+ maybePluralize(group->processesBeingSpawned, "process", "processes") <<
176
+ "...)" << endl;
177
+ }
178
+ }
179
+ result << " Requests in queue: " << group->getWaitlist.size() << endl;
180
+ inspectProcessList(options, result, group.get(), group->enabledProcesses);
181
+ inspectProcessList(options, result, group.get(), group->disablingProcesses);
182
+ inspectProcessList(options, result, group.get(), group->disabledProcesses);
183
+ inspectProcessList(options, result, group.get(), group->detachedProcesses);
184
+ result << endl;
185
+
186
+ g_it.next();
187
+ }
188
+ return result.str();
189
+ }
190
+
191
+ string
192
+ Pool::toXml(const ToXmlOptions &options, bool lock) const {
193
+ DynamicScopedLock l(syncher, lock);
194
+ stringstream result;
195
+ GroupMap::ConstIterator g_it(groups);
196
+ ProcessList::const_iterator p_it;
197
+
198
+ if (!authorizeByUid(options.uid, false)
199
+ && !authorizeByApiKey(options.apiKey, false))
200
+ {
201
+ throw SecurityException("Operation unauthorized");
202
+ }
203
+
204
+ result << "<?xml version=\"1.0\" encoding=\"iso8859-1\" ?>\n";
205
+ result << "<info version=\"3\">";
206
+
207
+ result << "<passenger_version>" << PASSENGER_VERSION << "</passenger_version>";
208
+ result << "<group_count>" << groups.size() << "</group_count>";
209
+ result << "<process_count>" << getProcessCount(false) << "</process_count>";
210
+ result << "<max>" << max << "</max>";
211
+ result << "<capacity_used>" << capacityUsedUnlocked() << "</capacity_used>";
212
+ result << "<get_wait_list_size>" << getWaitlist.size() << "</get_wait_list_size>";
213
+
214
+ if (options.secrets) {
215
+ vector<GetWaiter>::const_iterator w_it, w_end = getWaitlist.end();
216
+
217
+ result << "<get_wait_list>";
218
+ for (w_it = getWaitlist.begin(); w_it != w_end; w_it++) {
219
+ const GetWaiter &waiter = *w_it;
220
+ result << "<item>";
221
+ result << "<app_group_name>" << escapeForXml(waiter.options.getAppGroupName()) << "</app_group_name>";
222
+ result << "</item>";
223
+ }
224
+ result << "</get_wait_list>";
225
+ }
226
+
227
+ result << "<supergroups>";
228
+ while (*g_it != NULL) {
229
+ const GroupPtr &group = g_it.getValue();
230
+ if (!group->authorizeByUid(options.uid)
231
+ && !group->authorizeByApiKey(options.apiKey))
232
+ {
233
+ g_it.next();
234
+ continue;
235
+ }
236
+
237
+ result << "<supergroup>";
238
+ result << "<name>" << escapeForXml(group->getName()) << "</name>";
239
+ result << "<state>READY</state>";
240
+ result << "<get_wait_list_size>0</get_wait_list_size>";
241
+ result << "<capacity_used>" << group->capacityUsed() << "</capacity_used>";
242
+ if (options.secrets) {
243
+ result << "<secret>" << escapeForXml(group->getApiKey().toStaticString()) << "</secret>";
244
+ }
245
+
246
+ result << "<group default=\"true\">";
247
+ group->inspectXml(result, options.secrets);
248
+ result << "</group>";
249
+
250
+ result << "</supergroup>";
251
+
252
+ g_it.next();
253
+ }
254
+ result << "</supergroups>";
255
+
256
+ result << "</info>";
257
+ return result.str();
258
+ }
259
+
260
+
261
+ unsigned int
262
+ Pool::capacityUsed() const {
263
+ LockGuard l(syncher);
264
+ return capacityUsedUnlocked();
265
+ }
266
+
267
+ bool
268
+ Pool::atFullCapacity() const {
269
+ LockGuard l(syncher);
270
+ return atFullCapacityUnlocked();
271
+ }
272
+
273
+ /**
274
+ * Returns the total number of processes in the pool, including all disabling and
275
+ * disabled processes, but excluding processes that are shutting down and excluding
276
+ * processes that are being spawned.
277
+ */
278
+ unsigned int
279
+ Pool::getProcessCount(bool lock) const {
280
+ DynamicScopedLock l(syncher, lock);
281
+ unsigned int result = 0;
282
+ GroupMap::ConstIterator g_it(groups);
283
+ while (*g_it != NULL) {
284
+ const GroupPtr &group = g_it.getValue();
285
+ result += group->getProcessCount();
286
+ g_it.next();
287
+ }
288
+ return result;
289
+ }
290
+
291
+ unsigned int
292
+ Pool::getGroupCount() const {
293
+ LockGuard l(syncher);
294
+ return groups.size();
295
+ }
296
+
297
+
298
+ } // namespace ApplicationPool2
299
+ } // namespace Passenger