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.
- checksums.yaml +8 -8
- checksums.yaml.gz.asc +7 -7
- data.tar.gz.asc +7 -7
- data/CHANGELOG +15 -0
- data/CONTRIBUTORS +6 -0
- data/README.md +1 -1
- data/bin/passenger-install-apache2-module +24 -11
- data/bin/passenger-status +29 -14
- data/build/agents.rb +12 -10
- data/build/cxx_tests.rb +30 -30
- data/doc/Design and Architecture.html +1 -10
- data/doc/Design and Architecture.txt +1 -6
- data/doc/Users guide Apache.html +1 -19
- data/doc/Users guide Apache.txt +1 -1
- data/doc/Users guide Nginx.html +2 -20
- data/doc/Users guide Nginx.txt +2 -2
- data/doc/users_guide_snippets/tips.txt +0 -9
- data/ext/common/ApplicationPool2/ApiKey.h +158 -0
- data/ext/common/ApplicationPool2/BasicGroupInfo.h +81 -0
- data/ext/common/ApplicationPool2/BasicProcessInfo.h +106 -0
- data/ext/common/ApplicationPool2/Common.h +5 -44
- data/ext/common/ApplicationPool2/Context.h +94 -0
- data/ext/common/ApplicationPool2/Group.h +130 -1205
- data/ext/common/ApplicationPool2/Group/InitializationAndShutdown.cpp +190 -0
- data/ext/common/ApplicationPool2/Group/InternalUtils.cpp +329 -0
- data/ext/common/ApplicationPool2/Group/LifetimeAndBasics.cpp +103 -0
- data/ext/common/ApplicationPool2/{Pool/Debug.h → Group/Miscellaneous.cpp} +40 -38
- data/ext/common/ApplicationPool2/Group/OutOfBandWork.cpp +323 -0
- data/ext/common/ApplicationPool2/Group/ProcessListManagement.cpp +606 -0
- data/ext/common/ApplicationPool2/Group/SessionManagement.cpp +337 -0
- data/ext/common/ApplicationPool2/Group/SpawningAndRestarting.cpp +478 -0
- data/ext/common/ApplicationPool2/Group/StateInspection.cpp +197 -0
- data/ext/common/ApplicationPool2/Group/Verification.cpp +159 -0
- data/ext/common/ApplicationPool2/Implementation.cpp +19 -1401
- data/ext/common/ApplicationPool2/Options.h +5 -5
- data/ext/common/ApplicationPool2/Pool.h +260 -815
- data/ext/common/ApplicationPool2/Pool/{AnalyticsCollection.h → AnalyticsCollection.cpp} +55 -56
- data/ext/common/ApplicationPool2/Pool/{GarbageCollection.h → GarbageCollection.cpp} +49 -49
- data/ext/common/ApplicationPool2/Pool/GeneralUtils.cpp +241 -0
- data/ext/common/ApplicationPool2/Pool/GroupUtils.cpp +276 -0
- data/ext/common/ApplicationPool2/Pool/InitializationAndShutdown.cpp +145 -0
- data/ext/common/ApplicationPool2/Pool/Miscellaneous.cpp +244 -0
- data/ext/common/ApplicationPool2/Pool/ProcessUtils.cpp +330 -0
- data/ext/common/ApplicationPool2/Pool/StateInspection.cpp +299 -0
- data/ext/common/ApplicationPool2/Process.h +399 -205
- data/ext/common/ApplicationPool2/Session.h +70 -28
- data/ext/common/ApplicationPool2/Socket.h +1 -0
- data/ext/common/Constants.h +11 -3
- data/ext/common/Exceptions.h +1 -1
- data/ext/common/Logging.cpp +9 -4
- data/ext/common/Logging.h +6 -0
- data/ext/common/ServerKit/HttpServer.h +225 -215
- data/ext/common/ServerKit/Server.h +57 -57
- data/ext/common/SpawningKit/BackgroundIOCapturer.h +160 -0
- data/ext/common/SpawningKit/Config.h +107 -0
- data/ext/common/{ApplicationPool2 → SpawningKit}/DirectSpawner.h +17 -16
- data/ext/common/{ApplicationPool2 → SpawningKit}/DummySpawner.h +33 -33
- data/ext/common/{ApplicationPool2/SpawnerFactory.h → SpawningKit/Factory.h} +17 -17
- data/ext/common/{ApplicationPool2/ComponentInfo.h → SpawningKit/Options.h} +8 -21
- data/ext/common/SpawningKit/PipeWatcher.h +148 -0
- data/ext/common/{ApplicationPool2/PipeWatcher.h → SpawningKit/Result.h} +15 -33
- data/ext/common/{ApplicationPool2 → SpawningKit}/SmartSpawner.h +52 -57
- data/ext/common/{ApplicationPool2 → SpawningKit}/Spawner.h +83 -371
- data/ext/common/SpawningKit/UserSwitchingRules.h +265 -0
- data/ext/common/Utils/BufferedIO.h +24 -0
- data/ext/common/{ApplicationPool2/SpawnObject.h → Utils/ClassUtils.h} +24 -51
- data/ext/common/Utils/IOUtils.cpp +70 -0
- data/ext/common/Utils/IOUtils.h +19 -0
- data/ext/common/Utils/JsonUtils.h +113 -0
- data/ext/common/Utils/StrIntUtils.h +29 -0
- data/ext/common/Utils/json.h +1 -1
- data/ext/common/agents/ApiServerUtils.h +941 -0
- data/ext/common/agents/HelperAgent/{AdminServer.h → ApiServer.h} +163 -365
- data/ext/common/agents/HelperAgent/Main.cpp +86 -88
- data/ext/common/agents/HelperAgent/OptionParser.h +9 -10
- data/ext/common/agents/HelperAgent/RequestHandler/BufferBody.cpp +3 -0
- data/ext/common/agents/HelperAgent/RequestHandler/ForwardResponse.cpp +2 -0
- data/ext/common/agents/HelperAgent/RequestHandler/Hooks.cpp +1 -1
- data/ext/common/agents/HelperAgent/RequestHandler/SendRequest.cpp +2 -2
- data/ext/common/agents/LoggingAgent/ApiServer.h +279 -0
- data/ext/common/agents/LoggingAgent/Main.cpp +41 -51
- data/ext/common/agents/LoggingAgent/OptionParser.h +11 -11
- data/ext/common/agents/Watchdog/ApiServer.h +311 -0
- data/ext/common/agents/Watchdog/Main.cpp +91 -65
- data/helper-scripts/prespawn +2 -0
- data/lib/phusion_passenger.rb +1 -1
- data/lib/phusion_passenger/admin_tools/instance.rb +1 -1
- data/lib/phusion_passenger/common_library.rb +27 -14
- data/lib/phusion_passenger/config/{admin_command_command.rb → api_call_command.rb} +19 -16
- data/lib/phusion_passenger/config/detach_process_command.rb +6 -3
- data/lib/phusion_passenger/config/main.rb +3 -5
- data/lib/phusion_passenger/config/reopen_logs_command.rb +29 -7
- data/lib/phusion_passenger/config/restart_app_command.rb +13 -4
- data/lib/phusion_passenger/config/utils.rb +15 -8
- data/lib/phusion_passenger/constants.rb +6 -2
- data/lib/phusion_passenger/platform_info/apache.rb +4 -0
- data/lib/phusion_passenger/platform_info/apache_detector.rb +18 -3
- data/resources/templates/apache2/mpm_unknown.txt.erb +20 -0
- metadata +42 -21
- metadata.gz.asc +7 -7
- data/ext/common/ApplicationPool2/Pool/GeneralUtils.h +0 -127
- data/ext/common/ApplicationPool2/Pool/Inspection.h +0 -219
- data/ext/common/ApplicationPool2/Pool/ProcessUtils.h +0 -85
- data/ext/common/ApplicationPool2/SuperGroup.h +0 -706
- data/ext/common/agents/LoggingAgent/AdminServer.h +0 -435
- data/ext/common/agents/Watchdog/AdminServer.h +0 -432
@@ -219,11 +219,6 @@ The main interface into the subsystem is the Pool class, with its `asyncGet()` m
|
|
219
219
|
|
220
220
|
The Pool class is the core of the subsystem. It contains high-level process management logic but not low-level details, such as the details of spawning processes. The code is further divided into the following classes, each of which contain the core code managing its respective domain:
|
221
221
|
|
222
|
-
**SuperGroup**::
|
223
|
-
A logical collection of different applications. It's designed to be able to contain one or more Groups, but currently it always contains exactly 1 Group.
|
224
|
-
+
|
225
|
-
SuperGroup was originally introduced as a building block for a future feature: polyglot, multi-language applications. The idea was that, as more and more programming languages are introduced and become popular, there would be more and more demand to write applications in multiple languages. This would be done by splitting applications into multiple parts, with each part implemented in a different language. We wanted to introduce a feature that makes it super-easy to make such polyglot applications as a single whole. However, as time went on, we realized that we were mistaken and that most developers actually don't want to bother with multiple programming languages: they'd rather stick with a single one. So nowadays, SuperGroup is actually obsolete, but it's still kept in the codebase because it's not harmful, and removing it is too much work.
|
226
|
-
|
227
222
|
**Group**::
|
228
223
|
Represents an application. It can contain multiple processes, all belonging to the same application.
|
229
224
|
|
@@ -239,7 +234,7 @@ SuperGroup was originally introduced as a building block for a future feature: p
|
|
239
234
|
**Options (not shown in diagram)**::
|
240
235
|
A configuration object for the `Pool::asyncGet()` method.
|
241
236
|
|
242
|
-
If you look at the diagram, then you see that
|
237
|
+
If you look at the diagram, then you see that Group and Process all have 0..1 associations with their containing classes. An object that has a NULL association with its containing object, is considered invalid and should not be used. The fact that the association can be NULL is a detail of the memory management scheme that we employ.
|
243
238
|
|
244
239
|
[[spawner_subsystem]]
|
245
240
|
=== The Spawner subsystem
|
data/doc/Users guide Apache.html
CHANGED
@@ -4431,7 +4431,7 @@ stay that way until someone visits <em>foobar.com</em>. Suppose that there is on
|
|
4431
4431
|
be spawned in the background. After 10 seconds, when the idle timeout has
|
4432
4432
|
been reached, these 3 application processes will not be cleaned up.</p></div>
|
4433
4433
|
<div class="paragraph"><p>Now suppose that there’s a sudden spike of traffic, and 100 users visit <em>foobar.com</em>
|
4434
|
-
|
4434
|
+
simultaneously. Phusion Passenger will start 12 more application processes. After the idle
|
4435
4435
|
timeout of 10 seconds have passed, Phusion Passenger will clean up 12 application
|
4436
4436
|
processes, keeping 3 processes around.</p></div>
|
4437
4437
|
<div class="paragraph"><p>The PassengerMinInstances option may occur in the following places:</p></div>
|
@@ -7201,24 +7201,6 @@ The application taking too long to start, and hitting Phusion Passenger’s time
|
|
7201
7201
|
<div class="paragraph"><p>This hook does not block because it’s always run in an extra background thread. Errors in the hook script are ignored.</p></div>
|
7202
7202
|
</dd>
|
7203
7203
|
<dt class="hdlist1">
|
7204
|
-
<span class="monospaced">after_initialize_supergroup</span>
|
7205
|
-
</dt>
|
7206
|
-
<dd>
|
7207
|
-
<p>
|
7208
|
-
Called right after Phusion Passenger has allocated data structures for an application, and is about to spawn a process for the first time for this application. Errors in the hook script are ignored. Extra environment variables: <span class="monospaced">PASSENGER_APP_ROOT</span>.
|
7209
|
-
</p>
|
7210
|
-
</dd>
|
7211
|
-
<dt class="hdlist1">
|
7212
|
-
<span class="monospaced">before_destroy_supergroup</span>
|
7213
|
-
</dt>
|
7214
|
-
<dd>
|
7215
|
-
<p>
|
7216
|
-
Called right before Phusion Passenger decallocates data structures for an application. Errors in the hook script are ignored.
|
7217
|
-
</p>
|
7218
|
-
<div class="paragraph"><p>Note that the <span class="monospaced">after_initialize_supergroup</span> hook may be called while this hook is still being executed, so make sure that operations don’t conflict with each other.</p></div>
|
7219
|
-
<div class="paragraph"><p>Extra environment variables: <span class="monospaced">PASSENGER_APP_ROOT</span>.</p></div>
|
7220
|
-
</dd>
|
7221
|
-
<dt class="hdlist1">
|
7222
7204
|
<span class="monospaced">max_request_time_reached</span> (since 5.0.2, Enterprise-only)
|
7223
7205
|
</dt>
|
7224
7206
|
<dd>
|
data/doc/Users guide Apache.txt
CHANGED
@@ -1135,7 +1135,7 @@ be spawned in the background. After 10 seconds, when the idle timeout has
|
|
1135
1135
|
been reached, these 3 application processes will not be cleaned up.
|
1136
1136
|
|
1137
1137
|
Now suppose that there's a sudden spike of traffic, and 100 users visit 'foobar.com'
|
1138
|
-
|
1138
|
+
simultaneously. Phusion Passenger will start 12 more application processes. After the idle
|
1139
1139
|
timeout of 10 seconds have passed, Phusion Passenger will clean up 12 application
|
1140
1140
|
processes, keeping 3 processes around.
|
1141
1141
|
|
data/doc/Users guide Nginx.html
CHANGED
@@ -4470,7 +4470,7 @@ In an <em>if</em> configuration scope.
|
|
4470
4470
|
<div class="sect3">
|
4471
4471
|
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerMaxPoolSize"></span><h4 data-comment-topic="passenger-max-pool-size-integer--3jzefs" data-anchor="PassengerMaxPoolSize">7.5.1. passenger_max_pool_size <integer></h4>
|
4472
4472
|
<div class="paragraph"><p>The maximum number of <a href="#application_process">application processes</a> that may
|
4473
|
-
|
4473
|
+
simultaneously exist. A larger number results in higher memory usage,
|
4474
4474
|
but improves the ability to handle concurrent HTTP requests.</p></div>
|
4475
4475
|
<div class="paragraph"><p>The optimal value depends on your system’s hardware and your workload. You can learn more at the Phusion article <a href="http://blog.phusion.nl/2013/03/12/tuning-phusion-passengers-concurrency-settings/">Tuning Phusion Passenger’s concurrency settings</a>.</p></div>
|
4476
4476
|
<div class="paragraph"><p>If you find that your server is running out of memory then you should lower this value.</p></div>
|
@@ -4532,7 +4532,7 @@ stay that way until someone visits <em>foobar.com</em>. Suppose that there is on
|
|
4532
4532
|
be spawned in the background. After 10 seconds, when the idle timeout has
|
4533
4533
|
been reached, these 3 application processes will not be cleaned up.</p></div>
|
4534
4534
|
<div class="paragraph"><p>Now suppose that there’s a sudden spike of traffic, and 100 users visit <em>foobar.com</em>
|
4535
|
-
|
4535
|
+
simultaneously. Phusion Passenger will start 12 more application processes. After the idle
|
4536
4536
|
timeout of 10 seconds have passed, Phusion Passenger will clean up 12 application
|
4537
4537
|
processes, keeping 3 processes around.</p></div>
|
4538
4538
|
<div class="paragraph"><p>The passenger_min_instances option may occur in the following places:</p></div>
|
@@ -7186,24 +7186,6 @@ The application taking too long to start, and hitting Phusion Passenger’s time
|
|
7186
7186
|
<div class="paragraph"><p>This hook does not block because it’s always run in an extra background thread. Errors in the hook script are ignored.</p></div>
|
7187
7187
|
</dd>
|
7188
7188
|
<dt class="hdlist1">
|
7189
|
-
<span class="monospaced">after_initialize_supergroup</span>
|
7190
|
-
</dt>
|
7191
|
-
<dd>
|
7192
|
-
<p>
|
7193
|
-
Called right after Phusion Passenger has allocated data structures for an application, and is about to spawn a process for the first time for this application. Errors in the hook script are ignored. Extra environment variables: <span class="monospaced">PASSENGER_APP_ROOT</span>.
|
7194
|
-
</p>
|
7195
|
-
</dd>
|
7196
|
-
<dt class="hdlist1">
|
7197
|
-
<span class="monospaced">before_destroy_supergroup</span>
|
7198
|
-
</dt>
|
7199
|
-
<dd>
|
7200
|
-
<p>
|
7201
|
-
Called right before Phusion Passenger decallocates data structures for an application. Errors in the hook script are ignored.
|
7202
|
-
</p>
|
7203
|
-
<div class="paragraph"><p>Note that the <span class="monospaced">after_initialize_supergroup</span> hook may be called while this hook is still being executed, so make sure that operations don’t conflict with each other.</p></div>
|
7204
|
-
<div class="paragraph"><p>Extra environment variables: <span class="monospaced">PASSENGER_APP_ROOT</span>.</p></div>
|
7205
|
-
</dd>
|
7206
|
-
<dt class="hdlist1">
|
7207
7189
|
<span class="monospaced">max_request_time_reached</span> (since 5.0.2, Enterprise-only)
|
7208
7190
|
</dt>
|
7209
7191
|
<dd>
|
data/doc/Users guide Nginx.txt
CHANGED
@@ -1084,7 +1084,7 @@ In each place, it may be specified at most once. The default value depends on <<
|
|
1084
1084
|
[[PassengerMaxPoolSize]]
|
1085
1085
|
==== passenger_max_pool_size <integer> ====
|
1086
1086
|
The maximum number of <<application_process,application processes>> that may
|
1087
|
-
|
1087
|
+
simultaneously exist. A larger number results in higher memory usage,
|
1088
1088
|
but improves the ability to handle concurrent HTTP requests.
|
1089
1089
|
|
1090
1090
|
The optimal value depends on your system's hardware and your workload. You can learn more at the Phusion article link:http://blog.phusion.nl/2013/03/12/tuning-phusion-passengers-concurrency-settings/[Tuning Phusion Passenger's concurrency settings].
|
@@ -1139,7 +1139,7 @@ be spawned in the background. After 10 seconds, when the idle timeout has
|
|
1139
1139
|
been reached, these 3 application processes will not be cleaned up.
|
1140
1140
|
|
1141
1141
|
Now suppose that there's a sudden spike of traffic, and 100 users visit 'foobar.com'
|
1142
|
-
|
1142
|
+
simultaneously. Phusion Passenger will start 12 more application processes. After the idle
|
1143
1143
|
timeout of 10 seconds have passed, Phusion Passenger will clean up 12 application
|
1144
1144
|
processes, keeping 3 processes around.
|
1145
1145
|
|
@@ -554,15 +554,6 @@ Extra environment variables:
|
|
554
554
|
+
|
555
555
|
This hook does not block because it's always run in an extra background thread. Errors in the hook script are ignored.
|
556
556
|
|
557
|
-
`after_initialize_supergroup`::
|
558
|
-
Called right after Phusion Passenger has allocated data structures for an application, and is about to spawn a process for the first time for this application. Errors in the hook script are ignored. Extra environment variables: `PASSENGER_APP_ROOT`.
|
559
|
-
`before_destroy_supergroup`::
|
560
|
-
Called right before Phusion Passenger decallocates data structures for an application. Errors in the hook script are ignored.
|
561
|
-
+
|
562
|
-
Note that the `after_initialize_supergroup` hook may be called while this hook is still being executed, so make sure that operations don't conflict with each other.
|
563
|
-
+
|
564
|
-
Extra environment variables: `PASSENGER_APP_ROOT`.
|
565
|
-
|
566
557
|
`max_request_time_reached` (since 5.0.2, Enterprise-only)::
|
567
558
|
Called when a <<PassengerMaxRequestTime,max request time limit>> has been reached. Please note that as soon as this hook has finished executing, the application process will be killed with SIGKILL. So if you want to perform any diagnostics on the process in question (e.g. with strace, gdb, etc), please do not exit your hook script until you've obtained all the diagnostics you want.
|
568
559
|
+
|
@@ -0,0 +1,158 @@
|
|
1
|
+
/*
|
2
|
+
* Phusion Passenger - https://www.phusionpassenger.com/
|
3
|
+
* Copyright (c) 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
|
+
#ifndef _PASSENGER_APPLICATION_POOL2_API_KEY_H_
|
26
|
+
#define _PASSENGER_APPLICATION_POOL2_API_KEY_H_
|
27
|
+
|
28
|
+
#include <oxt/macros.hpp>
|
29
|
+
#include <string>
|
30
|
+
#include <cstring>
|
31
|
+
#include <Exceptions.h>
|
32
|
+
#include <StaticString.h>
|
33
|
+
#include <Utils/StrIntUtils.h>
|
34
|
+
|
35
|
+
namespace Passenger {
|
36
|
+
namespace ApplicationPool2 {
|
37
|
+
|
38
|
+
using namespace std;
|
39
|
+
|
40
|
+
|
41
|
+
/**
|
42
|
+
* An API key is a string that determines which app a particular ApiServer
|
43
|
+
* client may access. It is automatically generated by a Group and passed to
|
44
|
+
* all application processes that it spawns. Application processes can then
|
45
|
+
* use that API key to perform API calls by connecting to the ApiServer.
|
46
|
+
*
|
47
|
+
* An API key is transient, not persistent. That is, it is only valid during
|
48
|
+
* the life time of a Group. It is not pre-generated by the user.
|
49
|
+
*
|
50
|
+
* An API key is unique per Pool, so may be used to uniquely identify a Group
|
51
|
+
* object within a Pool.
|
52
|
+
*
|
53
|
+
* An API key may be null, which means that it's not given.
|
54
|
+
*
|
55
|
+
* There also exists a special "super" API key. This API key doesn't have a
|
56
|
+
* particular value, so it cannot be used to uniquely identify a Group. Instead,
|
57
|
+
* its purpose is to signal that the client is authorized to access all apps in
|
58
|
+
* the Pool. Super API keys are associated with ApiServer clients that are
|
59
|
+
* authenticated with one of the API accounts.
|
60
|
+
*/
|
61
|
+
class ApiKey {
|
62
|
+
public:
|
63
|
+
static const unsigned int SIZE = 16;
|
64
|
+
|
65
|
+
private:
|
66
|
+
/*
|
67
|
+
* On x86_64 the value is as big as a StaticString,
|
68
|
+
* so might as well directly embed the data instead.
|
69
|
+
*/
|
70
|
+
char value[SIZE];
|
71
|
+
|
72
|
+
OXT_FORCE_INLINE
|
73
|
+
bool validateNonSuperKeyValueChar(const char ch) const {
|
74
|
+
return (ch >= 'a' && ch <= 'z')
|
75
|
+
|| (ch >= 'A' && ch <= 'Z')
|
76
|
+
|| (ch >= '0' && ch <= '9');
|
77
|
+
}
|
78
|
+
|
79
|
+
void validateNonSuperKeyValue(const StaticString &value) const {
|
80
|
+
const char *data = value.data();
|
81
|
+
const char *end = value.data() + value.size();
|
82
|
+
while (data < end) {
|
83
|
+
if (!validateNonSuperKeyValueChar(*data)) {
|
84
|
+
throw ArgumentException("API keys may only contain the characters a-z, A-Z and 0-9.");
|
85
|
+
}
|
86
|
+
data++;
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
public:
|
91
|
+
ApiKey() {
|
92
|
+
value[0] = '\0';
|
93
|
+
}
|
94
|
+
|
95
|
+
ApiKey(const StaticString &other) {
|
96
|
+
if (other.size() != SIZE) {
|
97
|
+
throw ArgumentException("API keys must be exactly "
|
98
|
+
+ Passenger::toString(SIZE) + " characters in length");
|
99
|
+
}
|
100
|
+
validateNonSuperKeyValue(other);
|
101
|
+
memcpy(value, other.data(), SIZE);
|
102
|
+
}
|
103
|
+
|
104
|
+
ApiKey(const ApiKey &other) {
|
105
|
+
memcpy(value, other.value, SIZE);
|
106
|
+
}
|
107
|
+
|
108
|
+
static ApiKey makeSuper() {
|
109
|
+
ApiKey key;
|
110
|
+
key.value[0] = '!';
|
111
|
+
assert(key.isSuper());
|
112
|
+
return key;
|
113
|
+
}
|
114
|
+
|
115
|
+
bool isNull() const {
|
116
|
+
return value[0] == '\0';
|
117
|
+
}
|
118
|
+
|
119
|
+
bool isSuper() const {
|
120
|
+
return value[0] == '!';
|
121
|
+
}
|
122
|
+
|
123
|
+
bool constantTimeCompare(const StaticString &other) const {
|
124
|
+
return Passenger::constantTimeCompare(toStaticString(), other);
|
125
|
+
}
|
126
|
+
|
127
|
+
bool constantTimeCompare(const ApiKey &other) const {
|
128
|
+
return Passenger::constantTimeCompare(toStaticString(), other.toStaticString());
|
129
|
+
}
|
130
|
+
|
131
|
+
string toString() const {
|
132
|
+
return toStaticString().toString();
|
133
|
+
}
|
134
|
+
|
135
|
+
StaticString toStaticString() const {
|
136
|
+
if (value[0] == '\0') {
|
137
|
+
return StaticString();
|
138
|
+
} else if (value[0] == '!') {
|
139
|
+
return StaticString("superkey");
|
140
|
+
} else {
|
141
|
+
return StaticString(value, SIZE);
|
142
|
+
}
|
143
|
+
}
|
144
|
+
|
145
|
+
bool operator==(const StaticString &other) const {
|
146
|
+
return other.size() == SIZE && memcmp(value, other.data(), SIZE) == 0;
|
147
|
+
}
|
148
|
+
|
149
|
+
bool operator==(const ApiKey &other) const {
|
150
|
+
return memcmp(value, other.value, SIZE) == 0;
|
151
|
+
}
|
152
|
+
};
|
153
|
+
|
154
|
+
|
155
|
+
} // namespace ApplicationPool2
|
156
|
+
} // namespace Passenger
|
157
|
+
|
158
|
+
#endif /* _PASSENGER_APPLICATION_POOL2_API_KEY_H_ */
|
@@ -0,0 +1,81 @@
|
|
1
|
+
/*
|
2
|
+
* Phusion Passenger - https://www.phusionpassenger.com/
|
3
|
+
* Copyright (c) 2014-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
|
+
#ifndef _PASSENGER_APPLICATION_POOL2_BASIC_GROUP_INFO_H_
|
26
|
+
#define _PASSENGER_APPLICATION_POOL2_BASIC_GROUP_INFO_H_
|
27
|
+
|
28
|
+
#include <string>
|
29
|
+
#include <cstddef>
|
30
|
+
#include <ApplicationPool2/Context.h>
|
31
|
+
#include <ApplicationPool2/ApiKey.h>
|
32
|
+
|
33
|
+
namespace Passenger {
|
34
|
+
namespace ApplicationPool2 {
|
35
|
+
|
36
|
+
|
37
|
+
class Group;
|
38
|
+
|
39
|
+
/**
|
40
|
+
* Contains basic Group information. This information is set during the
|
41
|
+
* initialization of a Group and never changed afterwards. This struct
|
42
|
+
* encapsulates that information. It is contained inside `Group` as a const
|
43
|
+
* object. Because of the immutable nature of the information, multithreaded
|
44
|
+
* access is safe.
|
45
|
+
*
|
46
|
+
* Since Process and Session sometimes need to look up this basic group
|
47
|
+
* information, this struct also serves to ensure that Process and Session do
|
48
|
+
* not have a direct dependency on Group, but on GroupImmutableInfo instead.
|
49
|
+
*/
|
50
|
+
class BasicGroupInfo {
|
51
|
+
public:
|
52
|
+
Context *context;
|
53
|
+
|
54
|
+
/**
|
55
|
+
* A back pointer to the Group that this BasicGroupInfo is contained in.
|
56
|
+
* May be NULL in unit tests.
|
57
|
+
*/
|
58
|
+
Group *group;
|
59
|
+
|
60
|
+
/**
|
61
|
+
* This name uniquely identifies this Group within its Pool. It can
|
62
|
+
* also be used as the display name.
|
63
|
+
*/
|
64
|
+
std::string name;
|
65
|
+
|
66
|
+
/**
|
67
|
+
* This Group's unique API key.
|
68
|
+
*/
|
69
|
+
ApiKey apiKey;
|
70
|
+
|
71
|
+
BasicGroupInfo()
|
72
|
+
: context(NULL),
|
73
|
+
group(NULL)
|
74
|
+
{ }
|
75
|
+
};
|
76
|
+
|
77
|
+
|
78
|
+
} // namespace ApplicationPool2
|
79
|
+
} // namespace Passenger
|
80
|
+
|
81
|
+
#endif /* _PASSENGER_APPLICATION_POOL2_BASIC_GROUP_INFO_H_ */
|
@@ -0,0 +1,106 @@
|
|
1
|
+
/*
|
2
|
+
* Phusion Passenger - https://www.phusionpassenger.com/
|
3
|
+
* Copyright (c) 2014-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
|
+
#ifndef _PASSENGER_APPLICATION_POOL2_BASIC_PROCESS_INFO_H_
|
26
|
+
#define _PASSENGER_APPLICATION_POOL2_BASIC_PROCESS_INFO_H_
|
27
|
+
|
28
|
+
#include <sys/types.h>
|
29
|
+
#include <cstring>
|
30
|
+
|
31
|
+
#include <StaticString.h>
|
32
|
+
#include <Exceptions.h>
|
33
|
+
#include <ApplicationPool2/BasicGroupInfo.h>
|
34
|
+
#include <Utils/json.h>
|
35
|
+
#include <Utils/JsonUtils.h>
|
36
|
+
|
37
|
+
namespace Passenger {
|
38
|
+
namespace ApplicationPool2 {
|
39
|
+
|
40
|
+
using namespace std;
|
41
|
+
|
42
|
+
|
43
|
+
class Process;
|
44
|
+
|
45
|
+
/**
|
46
|
+
* Contains a subset of the information in Process. This subset consists only
|
47
|
+
* of information that is:
|
48
|
+
*
|
49
|
+
* 1. ...read-only and set during Process constructions.
|
50
|
+
* 2. ...needed by Session.
|
51
|
+
*
|
52
|
+
* This class is contained inside `Process` as a const object. Because the
|
53
|
+
* information is read-only, and because Process outlives all related Session
|
54
|
+
* objects, Session can access it without grabbing the lock on Process.
|
55
|
+
*
|
56
|
+
* This class also serves to ensure that Session does not have a direct
|
57
|
+
* dependency on Process.
|
58
|
+
*/
|
59
|
+
class BasicProcessInfo {
|
60
|
+
public:
|
61
|
+
static const unsigned int GUPID_MAX_SIZE = 20;
|
62
|
+
|
63
|
+
/** The Process that this BasicProcessInfo is contained in. */
|
64
|
+
Process *process;
|
65
|
+
|
66
|
+
/** The basic information of the Group that the associated Process is contained in. */
|
67
|
+
const BasicGroupInfo *groupInfo;
|
68
|
+
|
69
|
+
/**
|
70
|
+
* The operating system process ID.
|
71
|
+
*/
|
72
|
+
pid_t pid;
|
73
|
+
|
74
|
+
/**
|
75
|
+
* An ID that uniquely identifies this Process in the Group, for
|
76
|
+
* use in implementing sticky sessions. Set by Group::attach().
|
77
|
+
*/
|
78
|
+
unsigned int stickySessionId;
|
79
|
+
|
80
|
+
/**
|
81
|
+
* UUID for this process, randomly generated and extremely unlikely to ever
|
82
|
+
* appear again in this universe.
|
83
|
+
*/
|
84
|
+
char gupid[GUPID_MAX_SIZE];
|
85
|
+
unsigned int gupidSize;
|
86
|
+
|
87
|
+
|
88
|
+
BasicProcessInfo(Process *_process, const BasicGroupInfo *_groupInfo,
|
89
|
+
const Json::Value &json)
|
90
|
+
: process(_process),
|
91
|
+
groupInfo(_groupInfo),
|
92
|
+
pid(getJsonIntField(json, "pid"))
|
93
|
+
//stickySessionId(getJsonUintField(json, "sticky_session_id", 0))
|
94
|
+
{
|
95
|
+
StaticString gupid = getJsonStaticStringField(json, "gupid");
|
96
|
+
assert(gupid.size() <= GUPID_MAX_SIZE);
|
97
|
+
memcpy(this->gupid, gupid.data(), gupid.size());
|
98
|
+
gupidSize = gupid.size();
|
99
|
+
}
|
100
|
+
};
|
101
|
+
|
102
|
+
|
103
|
+
} // namespace ApplicationPool2
|
104
|
+
} // namespace Passenger
|
105
|
+
|
106
|
+
#endif /* _PASSENGER_APPLICATION_POOL2_BASIC_PROCESS_INFO_H_ */
|