passenger 5.0.0.beta3 → 5.0.0.rc1
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/.editorconfig +11 -5
- data/CHANGELOG +38 -0
- data/CONTRIBUTING.md +1 -4
- data/Gemfile +0 -1
- data/Gemfile.lock +0 -2
- data/Rakefile +33 -33
- data/bin/passenger +1 -1
- data/bin/passenger-config +1 -1
- data/bin/passenger-install-apache2-module +800 -800
- data/bin/passenger-install-nginx-module +592 -592
- data/bin/passenger-memory-stats +127 -127
- data/bin/passenger-status +216 -216
- data/build/agents.rb +127 -127
- data/build/apache2.rb +87 -87
- data/build/basics.rb +60 -60
- data/build/common_library.rb +165 -165
- data/build/cplusplus_support.rb +51 -51
- data/build/cxx_tests.rb +268 -268
- data/build/debian.rb +143 -143
- data/build/documentation.rb +58 -58
- data/build/integration_tests.rb +81 -81
- data/build/misc.rb +132 -132
- data/build/nginx.rb +20 -20
- data/build/node_tests.rb +7 -7
- data/build/oxt_tests.rb +14 -14
- data/build/packaging.rb +570 -570
- data/build/preprocessor.rb +260 -260
- data/build/rake_extensions.rb +71 -71
- data/build/ruby_extension.rb +29 -29
- data/build/ruby_tests.rb +6 -6
- data/build/test_basics.rb +37 -37
- data/debian.template/control.template +3 -5
- data/dev/copy_boost_headers +134 -134
- data/dev/install_scripts_bootstrap_code.rb +25 -25
- data/dev/list_tests +20 -20
- data/dev/ruby_server.rb +223 -223
- data/dev/runner +18 -18
- data/doc/ServerOptimizationGuide.txt.md +55 -2
- data/doc/Users guide Nginx.txt +0 -26
- data/doc/Users guide Standalone.txt +5 -1
- data/doc/users_guide_snippets/tips.txt +9 -0
- data/ext/common/ApplicationPool2/Group.h +23 -11
- data/ext/common/ApplicationPool2/Implementation.cpp +32 -7
- data/ext/common/ApplicationPool2/Pool.h +22 -17
- data/ext/common/ApplicationPool2/SmartSpawner.h +4 -1
- data/ext/common/ApplicationPool2/Spawner.h +1 -1
- data/ext/common/Constants.h +1 -1
- data/ext/common/agents/Base.cpp +35 -20
- data/ext/common/agents/HelperAgent/Main.cpp +8 -1
- data/ext/common/agents/HelperAgent/OptionParser.h +18 -4
- data/ext/common/agents/HelperAgent/RequestHandler.h +2 -83
- data/ext/common/agents/HelperAgent/RequestHandler/ForwardResponse.cpp +54 -1
- data/ext/common/agents/HelperAgent/RequestHandler/InitRequest.cpp +7 -4
- data/ext/common/agents/Main.cpp +1 -1
- data/ext/common/agents/Watchdog/Main.cpp +54 -19
- data/ext/nginx/Configuration.c +7 -0
- data/ext/nginx/ContentHandler.c +9 -1
- data/helper-scripts/backtrace-sanitizer.rb +106 -87
- data/helper-scripts/crash-watch.rb +32 -0
- data/helper-scripts/download_binaries/extconf.rb +38 -38
- data/helper-scripts/meteor-loader.rb +107 -107
- data/helper-scripts/prespawn +101 -101
- data/helper-scripts/rack-loader.rb +96 -96
- data/helper-scripts/rack-preloader.rb +137 -137
- data/lib/phusion_passenger.rb +292 -292
- data/lib/phusion_passenger/abstract_installer.rb +438 -438
- data/lib/phusion_passenger/active_support3_extensions/init.rb +168 -170
- data/lib/phusion_passenger/admin_tools.rb +20 -20
- data/lib/phusion_passenger/admin_tools/instance.rb +178 -178
- data/lib/phusion_passenger/admin_tools/instance_registry.rb +61 -61
- data/lib/phusion_passenger/admin_tools/memory_stats.rb +267 -267
- data/lib/phusion_passenger/apache2/config_options.rb +182 -182
- data/lib/phusion_passenger/common_library.rb +479 -485
- data/lib/phusion_passenger/config/about_command.rb +161 -161
- data/lib/phusion_passenger/config/admin_command_command.rb +129 -129
- data/lib/phusion_passenger/config/agent_compiler.rb +121 -121
- data/lib/phusion_passenger/config/build_native_support_command.rb +43 -43
- data/lib/phusion_passenger/config/command.rb +25 -25
- data/lib/phusion_passenger/config/compile_agent_command.rb +62 -62
- data/lib/phusion_passenger/config/compile_nginx_engine_command.rb +88 -73
- data/lib/phusion_passenger/config/detach_process_command.rb +72 -72
- data/lib/phusion_passenger/config/download_agent_command.rb +246 -227
- data/lib/phusion_passenger/config/download_nginx_engine_command.rb +245 -224
- data/lib/phusion_passenger/config/install_agent_command.rb +144 -132
- data/lib/phusion_passenger/config/install_standalone_runtime_command.rb +205 -185
- data/lib/phusion_passenger/config/installation_utils.rb +204 -204
- data/lib/phusion_passenger/config/list_instances_command.rb +64 -64
- data/lib/phusion_passenger/config/main.rb +152 -152
- data/lib/phusion_passenger/config/nginx_engine_compiler.rb +319 -300
- data/lib/phusion_passenger/config/reopen_logs_command.rb +67 -67
- data/lib/phusion_passenger/config/restart_app_command.rb +155 -155
- data/lib/phusion_passenger/config/system_metrics_command.rb +13 -13
- data/lib/phusion_passenger/config/utils.rb +95 -95
- data/lib/phusion_passenger/config/validate_install_command.rb +198 -198
- data/lib/phusion_passenger/console_text_template.rb +25 -25
- data/lib/phusion_passenger/constants.rb +90 -90
- data/lib/phusion_passenger/debug_logging.rb +106 -106
- data/lib/phusion_passenger/loader_shared_helpers.rb +447 -432
- data/lib/phusion_passenger/message_channel.rb +312 -312
- data/lib/phusion_passenger/message_client.rb +176 -176
- data/lib/phusion_passenger/native_support.rb +369 -369
- data/lib/phusion_passenger/nginx/config_options.rb +297 -297
- data/lib/phusion_passenger/packaging.rb +131 -131
- data/lib/phusion_passenger/platform_info.rb +360 -360
- data/lib/phusion_passenger/platform_info/apache.rb +767 -767
- data/lib/phusion_passenger/platform_info/apache_detector.rb +199 -199
- data/lib/phusion_passenger/platform_info/binary_compatibility.rb +107 -107
- data/lib/phusion_passenger/platform_info/compiler.rb +570 -570
- data/lib/phusion_passenger/platform_info/curl.rb +32 -32
- data/lib/phusion_passenger/platform_info/cxx_portability.rb +188 -188
- data/lib/phusion_passenger/platform_info/depcheck.rb +372 -372
- data/lib/phusion_passenger/platform_info/depcheck_specs/apache2.rb +109 -109
- data/lib/phusion_passenger/platform_info/depcheck_specs/compiler_toolchain.rb +4 -4
- data/lib/phusion_passenger/platform_info/depcheck_specs/gems.rb +10 -34
- data/lib/phusion_passenger/platform_info/depcheck_specs/libs.rb +101 -101
- data/lib/phusion_passenger/platform_info/depcheck_specs/ruby.rb +5 -5
- data/lib/phusion_passenger/platform_info/depcheck_specs/utilities.rb +13 -13
- data/lib/phusion_passenger/platform_info/linux.rb +55 -55
- data/lib/phusion_passenger/platform_info/operating_system.rb +149 -149
- data/lib/phusion_passenger/platform_info/ruby.rb +468 -448
- data/lib/phusion_passenger/platform_info/zlib.rb +9 -9
- data/lib/phusion_passenger/plugin.rb +66 -66
- data/lib/phusion_passenger/preloader_shared_helpers.rb +126 -126
- data/lib/phusion_passenger/public_api.rb +191 -191
- data/lib/phusion_passenger/rack/out_of_band_gc.rb +93 -94
- data/lib/phusion_passenger/rack/thread_handler_extension.rb +231 -227
- data/lib/phusion_passenger/request_handler.rb +567 -577
- data/lib/phusion_passenger/request_handler/thread_handler.rb +379 -381
- data/lib/phusion_passenger/ruby_core_enhancements.rb +86 -86
- data/lib/phusion_passenger/ruby_core_io_enhancements.rb +74 -74
- data/lib/phusion_passenger/simple_benchmarking.rb +25 -25
- data/lib/phusion_passenger/standalone/app_finder.rb +153 -150
- data/lib/phusion_passenger/standalone/command.rb +44 -40
- data/lib/phusion_passenger/standalone/config_utils.rb +53 -53
- data/lib/phusion_passenger/standalone/control_utils.rb +38 -59
- data/lib/phusion_passenger/standalone/main.rb +73 -73
- data/lib/phusion_passenger/standalone/start_command.rb +697 -685
- data/lib/phusion_passenger/standalone/start_command/builtin_engine.rb +193 -155
- data/lib/phusion_passenger/standalone/start_command/nginx_engine.rb +162 -133
- data/lib/phusion_passenger/standalone/status_command.rb +64 -64
- data/lib/phusion_passenger/standalone/stop_command.rb +72 -72
- data/lib/phusion_passenger/standalone/version_command.rb +9 -9
- data/lib/phusion_passenger/union_station/connection.rb +32 -32
- data/lib/phusion_passenger/union_station/core.rb +251 -251
- data/lib/phusion_passenger/union_station/transaction.rb +126 -126
- data/lib/phusion_passenger/utils.rb +199 -167
- data/lib/phusion_passenger/utils/ansi_colors.rb +128 -128
- data/lib/phusion_passenger/utils/download.rb +196 -196
- data/lib/phusion_passenger/utils/file_system_watcher.rb +158 -158
- data/lib/phusion_passenger/utils/hosts_file_parser.rb +101 -101
- data/lib/phusion_passenger/utils/lock.rb +31 -31
- data/lib/phusion_passenger/utils/native_support_utils.rb +31 -31
- data/lib/phusion_passenger/utils/progress_bar.rb +26 -26
- data/lib/phusion_passenger/utils/shellwords.rb +20 -20
- data/lib/phusion_passenger/utils/terminal_choice_menu.rb +206 -206
- data/lib/phusion_passenger/utils/unseekable_socket.rb +272 -272
- data/lib/phusion_passenger/vendor/crash_watch/app.rb +129 -0
- data/lib/phusion_passenger/vendor/crash_watch/gdb_controller.rb +341 -0
- data/lib/phusion_passenger/vendor/crash_watch/version.rb +24 -0
- data/lib/phusion_passenger/vendor/daemon_controller.rb +877 -0
- data/lib/phusion_passenger/vendor/daemon_controller/lock_file.rb +127 -0
- data/lib/phusion_passenger/vendor/daemon_controller/spawn.rb +26 -0
- data/lib/phusion_passenger/vendor/daemon_controller/version.rb +29 -0
- data/packaging/rpm/passenger_spec/passenger.spec.template +0 -1
- data/passenger.gemspec +0 -1
- data/resources/templates/config/nginx_engine_compiler/possible_solutions_for_download_and_extraction_problems.txt.erb +27 -0
- data/resources/templates/standalone/config.erb +19 -15
- data/test/integration_tests/apache2_tests.rb +566 -566
- data/test/integration_tests/downloaded_binaries_tests.rb +126 -125
- data/test/integration_tests/native_packaging_spec.rb +296 -296
- data/test/integration_tests/nginx_tests.rb +393 -393
- data/test/integration_tests/shared/example_webapp_tests.rb +282 -280
- data/test/integration_tests/source_packaging_test.rb +138 -138
- data/test/integration_tests/spec_helper.rb +5 -5
- data/test/integration_tests/standalone_tests.rb +367 -367
- data/test/ruby/debug_logging_spec.rb +133 -133
- data/test/ruby/message_channel_spec.rb +186 -186
- data/test/ruby/rack/loader_spec.rb +28 -28
- data/test/ruby/rack/preloader_spec.rb +34 -34
- data/test/ruby/rails3.0/loader_spec.rb +12 -12
- data/test/ruby/rails3.0/preloader_spec.rb +18 -18
- data/test/ruby/rails3.1/loader_spec.rb +12 -12
- data/test/ruby/rails3.1/preloader_spec.rb +18 -18
- data/test/ruby/rails3.2/loader_spec.rb +12 -12
- data/test/ruby/rails3.2/preloader_spec.rb +18 -18
- data/test/ruby/rails4.0/loader_spec.rb +12 -12
- data/test/ruby/rails4.0/preloader_spec.rb +18 -18
- data/test/ruby/rails4.1/loader_spec.rb +12 -12
- data/test/ruby/rails4.1/preloader_spec.rb +18 -18
- data/test/ruby/request_handler_spec.rb +730 -730
- data/test/ruby/shared/loader_sharedspec.rb +224 -224
- data/test/ruby/shared/rails/union_station_extensions_sharedspec.rb +327 -327
- data/test/ruby/shared/ruby_loader_sharedspec.rb +47 -47
- data/test/ruby/spec_helper.rb +65 -65
- data/test/ruby/standalone/runtime_installer_spec.rb +384 -384
- data/test/ruby/union_station_spec.rb +276 -276
- data/test/ruby/utils/file_system_watcher_spec.rb +220 -220
- data/test/ruby/utils/hosts_file_parser.rb +248 -248
- data/test/ruby/utils/tee_input_spec.rb +215 -215
- data/test/ruby/utils/unseekable_socket_spec.rb +57 -57
- data/test/ruby/utils_spec.rb +21 -21
- data/test/stub/rack/config.ru +87 -87
- data/test/stub/rack/library.rb +8 -8
- data/test/stub/rack/start.rb +30 -30
- data/test/support/apache2_controller.rb +191 -191
- data/test/support/nginx_controller.rb +90 -99
- data/test/support/placebo-preloader.rb +57 -57
- data/test/support/test_helper.rb +435 -435
- metadata +11 -21
- metadata.gz.asc +7 -7
- data/lib/phusion_passenger/standalone/command2.rb +0 -292
- data/lib/phusion_passenger/standalone/start2_command.rb +0 -799
- data/resources/templates/standalone/download_tool_missing.txt.erb +0 -18
- data/resources/templates/standalone/possible_solutions_for_download_and_extraction_problems.txt.erb +0 -17
- data/resources/templates/standalone/run_installer_as_root.txt.erb +0 -8
data/test/ruby/utils_spec.rb
CHANGED
@@ -12,30 +12,30 @@ PhusionPassenger.require_passenger_lib 'utils/native_support_utils'
|
|
12
12
|
module PhusionPassenger
|
13
13
|
|
14
14
|
describe Utils do
|
15
|
-
|
16
|
-
|
15
|
+
include Utils
|
16
|
+
include Utils::NativeSupportUtils
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
18
|
+
specify "#to_boolean works" do
|
19
|
+
LoaderSharedHelpers.to_boolean(nil).should be_false
|
20
|
+
LoaderSharedHelpers.to_boolean(false).should be_false
|
21
|
+
LoaderSharedHelpers.to_boolean(true).should be_true
|
22
|
+
LoaderSharedHelpers.to_boolean(1).should be_true
|
23
|
+
LoaderSharedHelpers.to_boolean(0).should be_true
|
24
|
+
LoaderSharedHelpers.to_boolean("").should be_true
|
25
|
+
LoaderSharedHelpers.to_boolean("true").should be_true
|
26
|
+
LoaderSharedHelpers.to_boolean("false").should be_false
|
27
|
+
LoaderSharedHelpers.to_boolean("bla bla").should be_true
|
28
|
+
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
30
|
+
specify "#split_by_null_into_hash works" do
|
31
|
+
split_by_null_into_hash("").should == {}
|
32
|
+
split_by_null_into_hash("foo\0bar\0").should == { "foo" => "bar" }
|
33
|
+
split_by_null_into_hash("foo\0\0bar\0baz\0").should == { "foo" => "", "bar" => "baz" }
|
34
|
+
split_by_null_into_hash("foo\0bar\0baz\0\0").should == { "foo" => "bar", "baz" => "" }
|
35
|
+
split_by_null_into_hash("\0\0").should == { "" => "" }
|
36
|
+
end
|
37
37
|
|
38
|
-
|
38
|
+
######################
|
39
39
|
end
|
40
40
|
|
41
41
|
end # module PhusionPassenger
|
data/test/stub/rack/config.ru
CHANGED
@@ -3,93 +3,93 @@
|
|
3
3
|
require File.expand_path(File.dirname(__FILE__) + "/library")
|
4
4
|
|
5
5
|
app = lambda do |env|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
6
|
+
case env['PATH_INFO']
|
7
|
+
when '/'
|
8
|
+
if File.exist?("front_page.txt")
|
9
|
+
text_response(File.read("front_page.txt"))
|
10
|
+
else
|
11
|
+
text_response("front page")
|
12
|
+
end
|
13
|
+
when '/parameters'
|
14
|
+
req = Rack::Request.new(env)
|
15
|
+
method = env["REQUEST_METHOD"]
|
16
|
+
first = req.params["first"]
|
17
|
+
second = req.params["second"]
|
18
|
+
text_response("Method: #{method}\nFirst: #{first}\nSecond: #{second}\n")
|
19
|
+
when '/chunked'
|
20
|
+
chunks = ["7\r\nchunk1\n\r\n", "7\r\nchunk2\n\r\n", "7\r\nchunk3\n\r\n", "0\r\n\r\n"]
|
21
|
+
[200, { "Content-Type" => "text/html", "Transfer-Encoding" => "chunked" }, chunks]
|
22
|
+
when '/pid'
|
23
|
+
text_response(Process.pid)
|
24
|
+
when /^\/env/
|
25
|
+
body = ''
|
26
|
+
env.sort.each do |key, value|
|
27
|
+
body << "#{key} = #{value}\n"
|
28
|
+
end
|
29
|
+
text_response(body)
|
30
|
+
when '/system_env'
|
31
|
+
body = ''
|
32
|
+
ENV.sort.each do |key, value|
|
33
|
+
body << "#{key} = #{value}\n"
|
34
|
+
end
|
35
|
+
text_response(body)
|
36
|
+
when '/touch_file'
|
37
|
+
req = Rack::Request.new(env)
|
38
|
+
filename = req.params["file"]
|
39
|
+
File.open(filename, "w").close
|
40
|
+
text_response("ok")
|
41
|
+
when '/extra_header'
|
42
|
+
[200, { "Content-Type" => "text/html", "X-Foo" => "Bar" }, ["ok"]]
|
43
|
+
when '/cached'
|
44
|
+
text_response("This is the uncached version of /cached")
|
45
|
+
when '/upload_with_params'
|
46
|
+
req = Rack::Request.new(env)
|
47
|
+
name1 = binary_string(req.params["name1"])
|
48
|
+
name2 = binary_string(req.params["name2"])
|
49
|
+
file = req.params["data"][:tempfile]
|
50
|
+
file.binmode
|
51
|
+
text_response(
|
52
|
+
"name 1 = #{name1}\n" <<
|
53
|
+
"name 2 = #{name2}\n" <<
|
54
|
+
"data = #{file.read}")
|
55
|
+
when '/raw_upload_to_file'
|
56
|
+
File.open(env['HTTP_X_OUTPUT'], 'w') do |f|
|
57
|
+
while line = env['rack.input'].gets
|
58
|
+
f.write(line)
|
59
|
+
f.flush
|
60
|
+
end
|
61
|
+
end
|
62
|
+
text_response("ok")
|
63
|
+
when '/print_stderr'
|
64
|
+
STDERR.puts "hello world!"
|
65
|
+
text_response("ok")
|
66
|
+
when '/print_stdout_and_stderr'
|
67
|
+
STDOUT.puts "hello stdout!"
|
68
|
+
sleep 0.1 # Give HelperAgent the time to process stdout first.
|
69
|
+
STDERR.puts "hello stderr!"
|
70
|
+
text_response("ok")
|
71
|
+
when '/switch_protocol'
|
72
|
+
if env['HTTP_UPGRADE'] != 'raw' || env['HTTP_CONNECTION'].downcase != 'upgrade'
|
73
|
+
return [500, { "Content-Type" => "text/plain" }, ["Invalid headers"]]
|
74
|
+
end
|
75
|
+
env['rack.hijack'].call
|
76
|
+
io = env['rack.hijack_io']
|
77
|
+
begin
|
78
|
+
io.write("Status: 101 Switching Protocols\r\n")
|
79
|
+
io.write("Upgrade: raw\r\n")
|
80
|
+
io.write("Connection: Upgrade\r\n")
|
81
|
+
io.write("\r\n")
|
82
|
+
while !io.eof?
|
83
|
+
line = io.readline
|
84
|
+
io.write("Echo: #{line}")
|
85
|
+
io.flush
|
86
|
+
end
|
87
|
+
ensure
|
88
|
+
io.close
|
89
|
+
end
|
90
|
+
else
|
91
|
+
[404, { "Content-Type" => "text/plain" }, ["Unknown URI"]]
|
92
|
+
end
|
93
93
|
end
|
94
94
|
|
95
95
|
run app
|
data/test/stub/rack/library.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# encoding: binary
|
2
2
|
|
3
3
|
def text_response(body)
|
4
|
-
|
5
|
-
|
4
|
+
body = binary_string(body.to_s)
|
5
|
+
return [200, { "Content-Type" => "text/plain", "Content-Length" => body.size.to_s }, [body]]
|
6
6
|
end
|
7
7
|
|
8
8
|
if "".respond_to?(:force_encoding)
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
def binary_string(str)
|
10
|
+
return str.force_encoding("binary")
|
11
|
+
end
|
12
12
|
else
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
def binary_string(str)
|
14
|
+
return str
|
15
|
+
end
|
16
16
|
end
|
data/test/stub/rack/start.rb
CHANGED
@@ -8,13 +8,13 @@ abort "Invalid initialization header" if STDIN.readline != "You have control 1.0
|
|
8
8
|
|
9
9
|
options = {}
|
10
10
|
while (line = STDIN.readline) != "\n"
|
11
|
-
|
12
|
-
|
11
|
+
name, value = line.strip.split(/: */, 2)
|
12
|
+
options[name] = value
|
13
13
|
end
|
14
14
|
|
15
15
|
if ARGV[0] == "--execself"
|
16
|
-
|
17
|
-
|
16
|
+
# Used for testing https://code.google.com/p/phusion-passenger/issues/detail?id=842#c19
|
17
|
+
exec("ruby", $0)
|
18
18
|
end
|
19
19
|
|
20
20
|
server = TCPServer.new('127.0.0.1', 0)
|
@@ -23,30 +23,30 @@ puts "!> socket: main;tcp://127.0.0.1:#{server.addr[1]};session;1"
|
|
23
23
|
puts "!> "
|
24
24
|
|
25
25
|
while true
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
26
|
+
ios = select([server, STDIN])[0]
|
27
|
+
if ios.include?(server)
|
28
|
+
client = server.accept
|
29
|
+
line = client.readline
|
30
|
+
if line == "ping\n"
|
31
|
+
client.write("pong\n")
|
32
|
+
elsif line == "pid\n"
|
33
|
+
client.write("#{Process.pid}\n")
|
34
|
+
elsif line == "envvars\n"
|
35
|
+
str = ""
|
36
|
+
ENV.each_pair do |key, value|
|
37
|
+
str << "#{key} = #{value}\n"
|
38
|
+
end
|
39
|
+
client.write(str)
|
40
|
+
else
|
41
|
+
client.write("unknown request\n")
|
42
|
+
end
|
43
|
+
client.close
|
44
|
+
end
|
45
|
+
if ios.include?(STDIN)
|
46
|
+
begin
|
47
|
+
STDIN.readline
|
48
|
+
rescue EOFError
|
49
|
+
exit
|
50
|
+
end
|
51
|
+
end
|
52
52
|
end
|
@@ -41,218 +41,218 @@ PhusionPassenger.require_passenger_lib 'platform_info/ruby'
|
|
41
41
|
# apache.stop
|
42
42
|
# end
|
43
43
|
class Apache2Controller
|
44
|
-
|
45
|
-
|
44
|
+
include PhusionPassenger
|
45
|
+
STUB_DIR = File.expand_path(File.dirname(__FILE__) + "/../stub/apache2")
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
class VHost
|
48
|
+
attr_accessor :domain
|
49
|
+
attr_accessor :document_root
|
50
|
+
attr_accessor :additional_configs
|
51
51
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
def initialize(domain, document_root)
|
53
|
+
@domain = domain
|
54
|
+
@document_root = document_root
|
55
|
+
@additional_configs = []
|
56
|
+
end
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
58
|
+
def <<(config)
|
59
|
+
@additional_configs << config
|
60
|
+
end
|
61
|
+
end
|
62
62
|
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
attr_accessor :port
|
64
|
+
attr_accessor :vhosts
|
65
|
+
attr_reader :server_root
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
67
|
+
def initialize(options = nil)
|
68
|
+
set(options) if options
|
69
|
+
@port = 64506
|
70
|
+
@vhosts = []
|
71
|
+
@extra = []
|
72
|
+
@server_root = File.expand_path('tmp.apache2')
|
73
|
+
@passenger_root = File.expand_path(PhusionPassenger.install_spec)
|
74
|
+
@mod_passenger = PhusionPassenger.apache2_module_path
|
75
|
+
end
|
76
76
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
77
|
+
def set(options)
|
78
|
+
options.each_pair do |key, value|
|
79
|
+
instance_variable_set("@#{key}", value)
|
80
|
+
end
|
81
|
+
end
|
82
82
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
83
|
+
# Create an Apache configuration folder and start Apache on that
|
84
|
+
# configuration folder. This method does not return until Apache
|
85
|
+
# has done initializing.
|
86
|
+
#
|
87
|
+
# If Apache is already started, this this method will stop Apache first.
|
88
|
+
def start
|
89
|
+
if running?
|
90
|
+
stop
|
91
|
+
else
|
92
|
+
File.unlink("#{@server_root}/httpd.pid") rescue nil
|
93
|
+
end
|
94
94
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
95
|
+
if File.exist?(@server_root)
|
96
|
+
FileUtils.rm_r(@server_root)
|
97
|
+
end
|
98
|
+
FileUtils.mkdir_p(@server_root)
|
99
|
+
write_config_file
|
100
|
+
FileUtils.cp("#{STUB_DIR}/mime.types", @server_root)
|
101
101
|
|
102
|
-
|
103
|
-
|
104
|
-
|
102
|
+
if !system(PlatformInfo.httpd, "-f", "#{@server_root}/httpd.conf", "-k", "start")
|
103
|
+
raise "Could not start an Apache server."
|
104
|
+
end
|
105
105
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
106
|
+
begin
|
107
|
+
# Wait until the PID file has been created.
|
108
|
+
Timeout::timeout(20) do
|
109
|
+
while !File.exist?("#{@server_root}/httpd.pid")
|
110
|
+
sleep(0.1)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
# Wait until Apache is listening on the server port.
|
114
|
+
Timeout::timeout(7) do
|
115
|
+
done = false
|
116
|
+
while !done
|
117
|
+
begin
|
118
|
+
socket = TCPSocket.new('localhost', @port)
|
119
|
+
socket.close
|
120
|
+
done = true
|
121
|
+
rescue Errno::ECONNREFUSED
|
122
|
+
sleep(0.1)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
rescue Timeout::Error
|
127
|
+
raise "Could not start an Apache server."
|
128
|
+
end
|
129
|
+
Dir["#{@server_root}/*"].each do |filename|
|
130
|
+
if File.file?(filename)
|
131
|
+
File.chmod(0666, filename)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
135
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
136
|
+
def graceful_restart
|
137
|
+
write_config_file
|
138
|
+
if !system(PlatformInfo.httpd, "-f", "#{@server_root}/httpd.conf", "-k", "graceful")
|
139
|
+
raise "Cannot restart Apache."
|
140
|
+
end
|
141
|
+
end
|
142
142
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
143
|
+
# Stop Apache and delete its configuration folder. This method waits
|
144
|
+
# until Apache is done with its shutdown procedure.
|
145
|
+
#
|
146
|
+
# This method does nothing if Apache is already stopped.
|
147
|
+
def stop
|
148
|
+
pid_file = "#{@server_root}/httpd.pid"
|
149
|
+
if File.exist?(pid_file)
|
150
|
+
begin
|
151
|
+
pid = File.read(pid_file).strip.to_i
|
152
|
+
Process.kill('SIGTERM', pid)
|
153
|
+
rescue Errno::ESRCH
|
154
|
+
# Looks like a stale pid file.
|
155
|
+
FileUtils.rm_r(@server_root)
|
156
|
+
return
|
157
|
+
end
|
158
|
+
end
|
159
|
+
begin
|
160
|
+
# Wait until the PID file is removed.
|
161
|
+
Timeout::timeout(17) do
|
162
|
+
while File.exist?(pid_file)
|
163
|
+
sleep(0.1)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
# Wait until the server socket is closed.
|
167
|
+
Timeout::timeout(7) do
|
168
|
+
done = false
|
169
|
+
while !done
|
170
|
+
begin
|
171
|
+
socket = TCPSocket.new('localhost', @port)
|
172
|
+
socket.close
|
173
|
+
sleep(0.1)
|
174
|
+
rescue SystemCallError
|
175
|
+
done = true
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
rescue Timeout::Error
|
180
|
+
raise "Unable to stop Apache."
|
181
|
+
end
|
182
|
+
if File.exist?(@server_root)
|
183
|
+
FileUtils.chmod_R(0777, @server_root)
|
184
|
+
FileUtils.rm_r(@server_root)
|
185
|
+
end
|
186
|
+
end
|
187
187
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
188
|
+
# Define a virtual host configuration block for the Apache configuration
|
189
|
+
# file. If there was already a vhost definition with the same domain name,
|
190
|
+
# then it will be overwritten.
|
191
|
+
#
|
192
|
+
# The given document root will be created if it doesn't exist.
|
193
|
+
def set_vhost(domain, document_root)
|
194
|
+
FileUtils.mkdir_p(document_root)
|
195
|
+
vhost = VHost.new(domain, document_root)
|
196
|
+
if block_given?
|
197
|
+
yield vhost
|
198
|
+
end
|
199
|
+
vhosts.reject! {|host| host.domain == domain}
|
200
|
+
vhosts << vhost
|
201
|
+
end
|
202
202
|
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
203
|
+
# Checks whether this Apache instance is running.
|
204
|
+
def running?
|
205
|
+
if File.exist?("#{@server_root}/httpd.pid")
|
206
|
+
pid = File.read("#{@server_root}/httpd.pid").strip
|
207
|
+
begin
|
208
|
+
Process.kill(0, pid.to_i)
|
209
|
+
return true
|
210
|
+
rescue Errno::ESRCH
|
211
|
+
return false
|
212
|
+
rescue SystemCallError
|
213
|
+
return true
|
214
|
+
end
|
215
|
+
else
|
216
|
+
return false
|
217
|
+
end
|
218
|
+
end
|
219
219
|
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
220
|
+
# Defines a configuration snippet to be added to the Apache configuration file.
|
221
|
+
def <<(line)
|
222
|
+
@extra << line
|
223
|
+
end
|
224
224
|
|
225
225
|
private
|
226
|
-
|
227
|
-
|
228
|
-
|
226
|
+
def get_binding
|
227
|
+
return binding
|
228
|
+
end
|
229
229
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
230
|
+
def write_config_file
|
231
|
+
template = ERB.new(File.read("#{STUB_DIR}/httpd.conf.erb"))
|
232
|
+
File.open("#{@server_root}/httpd.conf", 'w') do |f|
|
233
|
+
f.write(template.result(get_binding))
|
234
|
+
end
|
235
|
+
end
|
236
236
|
|
237
|
-
|
238
|
-
|
239
|
-
|
237
|
+
def modules_dir
|
238
|
+
@@modules_dir ||= `#{PlatformInfo.apxs2} -q LIBEXECDIR`.strip
|
239
|
+
end
|
240
240
|
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
241
|
+
def builtin_modules
|
242
|
+
@@builtin_modules ||= `#{PlatformInfo.httpd} -l`.split("\n").grep(/\.c$/).map do |line|
|
243
|
+
line.strip
|
244
|
+
end
|
245
|
+
end
|
246
246
|
|
247
|
-
|
248
|
-
|
249
|
-
|
247
|
+
def has_builtin_module?(name)
|
248
|
+
return builtin_modules.include?(name)
|
249
|
+
end
|
250
250
|
|
251
|
-
|
252
|
-
|
253
|
-
|
251
|
+
def has_module?(name)
|
252
|
+
return File.exist?("#{modules_dir}/#{name}")
|
253
|
+
end
|
254
254
|
|
255
|
-
|
256
|
-
|
257
|
-
|
255
|
+
def we_are_root?
|
256
|
+
return Process.uid == 0
|
257
|
+
end
|
258
258
|
end
|