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.

Files changed (218) hide show
  1. checksums.yaml +8 -8
  2. checksums.yaml.gz.asc +7 -7
  3. data.tar.gz.asc +7 -7
  4. data/.editorconfig +11 -5
  5. data/CHANGELOG +38 -0
  6. data/CONTRIBUTING.md +1 -4
  7. data/Gemfile +0 -1
  8. data/Gemfile.lock +0 -2
  9. data/Rakefile +33 -33
  10. data/bin/passenger +1 -1
  11. data/bin/passenger-config +1 -1
  12. data/bin/passenger-install-apache2-module +800 -800
  13. data/bin/passenger-install-nginx-module +592 -592
  14. data/bin/passenger-memory-stats +127 -127
  15. data/bin/passenger-status +216 -216
  16. data/build/agents.rb +127 -127
  17. data/build/apache2.rb +87 -87
  18. data/build/basics.rb +60 -60
  19. data/build/common_library.rb +165 -165
  20. data/build/cplusplus_support.rb +51 -51
  21. data/build/cxx_tests.rb +268 -268
  22. data/build/debian.rb +143 -143
  23. data/build/documentation.rb +58 -58
  24. data/build/integration_tests.rb +81 -81
  25. data/build/misc.rb +132 -132
  26. data/build/nginx.rb +20 -20
  27. data/build/node_tests.rb +7 -7
  28. data/build/oxt_tests.rb +14 -14
  29. data/build/packaging.rb +570 -570
  30. data/build/preprocessor.rb +260 -260
  31. data/build/rake_extensions.rb +71 -71
  32. data/build/ruby_extension.rb +29 -29
  33. data/build/ruby_tests.rb +6 -6
  34. data/build/test_basics.rb +37 -37
  35. data/debian.template/control.template +3 -5
  36. data/dev/copy_boost_headers +134 -134
  37. data/dev/install_scripts_bootstrap_code.rb +25 -25
  38. data/dev/list_tests +20 -20
  39. data/dev/ruby_server.rb +223 -223
  40. data/dev/runner +18 -18
  41. data/doc/ServerOptimizationGuide.txt.md +55 -2
  42. data/doc/Users guide Nginx.txt +0 -26
  43. data/doc/Users guide Standalone.txt +5 -1
  44. data/doc/users_guide_snippets/tips.txt +9 -0
  45. data/ext/common/ApplicationPool2/Group.h +23 -11
  46. data/ext/common/ApplicationPool2/Implementation.cpp +32 -7
  47. data/ext/common/ApplicationPool2/Pool.h +22 -17
  48. data/ext/common/ApplicationPool2/SmartSpawner.h +4 -1
  49. data/ext/common/ApplicationPool2/Spawner.h +1 -1
  50. data/ext/common/Constants.h +1 -1
  51. data/ext/common/agents/Base.cpp +35 -20
  52. data/ext/common/agents/HelperAgent/Main.cpp +8 -1
  53. data/ext/common/agents/HelperAgent/OptionParser.h +18 -4
  54. data/ext/common/agents/HelperAgent/RequestHandler.h +2 -83
  55. data/ext/common/agents/HelperAgent/RequestHandler/ForwardResponse.cpp +54 -1
  56. data/ext/common/agents/HelperAgent/RequestHandler/InitRequest.cpp +7 -4
  57. data/ext/common/agents/Main.cpp +1 -1
  58. data/ext/common/agents/Watchdog/Main.cpp +54 -19
  59. data/ext/nginx/Configuration.c +7 -0
  60. data/ext/nginx/ContentHandler.c +9 -1
  61. data/helper-scripts/backtrace-sanitizer.rb +106 -87
  62. data/helper-scripts/crash-watch.rb +32 -0
  63. data/helper-scripts/download_binaries/extconf.rb +38 -38
  64. data/helper-scripts/meteor-loader.rb +107 -107
  65. data/helper-scripts/prespawn +101 -101
  66. data/helper-scripts/rack-loader.rb +96 -96
  67. data/helper-scripts/rack-preloader.rb +137 -137
  68. data/lib/phusion_passenger.rb +292 -292
  69. data/lib/phusion_passenger/abstract_installer.rb +438 -438
  70. data/lib/phusion_passenger/active_support3_extensions/init.rb +168 -170
  71. data/lib/phusion_passenger/admin_tools.rb +20 -20
  72. data/lib/phusion_passenger/admin_tools/instance.rb +178 -178
  73. data/lib/phusion_passenger/admin_tools/instance_registry.rb +61 -61
  74. data/lib/phusion_passenger/admin_tools/memory_stats.rb +267 -267
  75. data/lib/phusion_passenger/apache2/config_options.rb +182 -182
  76. data/lib/phusion_passenger/common_library.rb +479 -485
  77. data/lib/phusion_passenger/config/about_command.rb +161 -161
  78. data/lib/phusion_passenger/config/admin_command_command.rb +129 -129
  79. data/lib/phusion_passenger/config/agent_compiler.rb +121 -121
  80. data/lib/phusion_passenger/config/build_native_support_command.rb +43 -43
  81. data/lib/phusion_passenger/config/command.rb +25 -25
  82. data/lib/phusion_passenger/config/compile_agent_command.rb +62 -62
  83. data/lib/phusion_passenger/config/compile_nginx_engine_command.rb +88 -73
  84. data/lib/phusion_passenger/config/detach_process_command.rb +72 -72
  85. data/lib/phusion_passenger/config/download_agent_command.rb +246 -227
  86. data/lib/phusion_passenger/config/download_nginx_engine_command.rb +245 -224
  87. data/lib/phusion_passenger/config/install_agent_command.rb +144 -132
  88. data/lib/phusion_passenger/config/install_standalone_runtime_command.rb +205 -185
  89. data/lib/phusion_passenger/config/installation_utils.rb +204 -204
  90. data/lib/phusion_passenger/config/list_instances_command.rb +64 -64
  91. data/lib/phusion_passenger/config/main.rb +152 -152
  92. data/lib/phusion_passenger/config/nginx_engine_compiler.rb +319 -300
  93. data/lib/phusion_passenger/config/reopen_logs_command.rb +67 -67
  94. data/lib/phusion_passenger/config/restart_app_command.rb +155 -155
  95. data/lib/phusion_passenger/config/system_metrics_command.rb +13 -13
  96. data/lib/phusion_passenger/config/utils.rb +95 -95
  97. data/lib/phusion_passenger/config/validate_install_command.rb +198 -198
  98. data/lib/phusion_passenger/console_text_template.rb +25 -25
  99. data/lib/phusion_passenger/constants.rb +90 -90
  100. data/lib/phusion_passenger/debug_logging.rb +106 -106
  101. data/lib/phusion_passenger/loader_shared_helpers.rb +447 -432
  102. data/lib/phusion_passenger/message_channel.rb +312 -312
  103. data/lib/phusion_passenger/message_client.rb +176 -176
  104. data/lib/phusion_passenger/native_support.rb +369 -369
  105. data/lib/phusion_passenger/nginx/config_options.rb +297 -297
  106. data/lib/phusion_passenger/packaging.rb +131 -131
  107. data/lib/phusion_passenger/platform_info.rb +360 -360
  108. data/lib/phusion_passenger/platform_info/apache.rb +767 -767
  109. data/lib/phusion_passenger/platform_info/apache_detector.rb +199 -199
  110. data/lib/phusion_passenger/platform_info/binary_compatibility.rb +107 -107
  111. data/lib/phusion_passenger/platform_info/compiler.rb +570 -570
  112. data/lib/phusion_passenger/platform_info/curl.rb +32 -32
  113. data/lib/phusion_passenger/platform_info/cxx_portability.rb +188 -188
  114. data/lib/phusion_passenger/platform_info/depcheck.rb +372 -372
  115. data/lib/phusion_passenger/platform_info/depcheck_specs/apache2.rb +109 -109
  116. data/lib/phusion_passenger/platform_info/depcheck_specs/compiler_toolchain.rb +4 -4
  117. data/lib/phusion_passenger/platform_info/depcheck_specs/gems.rb +10 -34
  118. data/lib/phusion_passenger/platform_info/depcheck_specs/libs.rb +101 -101
  119. data/lib/phusion_passenger/platform_info/depcheck_specs/ruby.rb +5 -5
  120. data/lib/phusion_passenger/platform_info/depcheck_specs/utilities.rb +13 -13
  121. data/lib/phusion_passenger/platform_info/linux.rb +55 -55
  122. data/lib/phusion_passenger/platform_info/operating_system.rb +149 -149
  123. data/lib/phusion_passenger/platform_info/ruby.rb +468 -448
  124. data/lib/phusion_passenger/platform_info/zlib.rb +9 -9
  125. data/lib/phusion_passenger/plugin.rb +66 -66
  126. data/lib/phusion_passenger/preloader_shared_helpers.rb +126 -126
  127. data/lib/phusion_passenger/public_api.rb +191 -191
  128. data/lib/phusion_passenger/rack/out_of_band_gc.rb +93 -94
  129. data/lib/phusion_passenger/rack/thread_handler_extension.rb +231 -227
  130. data/lib/phusion_passenger/request_handler.rb +567 -577
  131. data/lib/phusion_passenger/request_handler/thread_handler.rb +379 -381
  132. data/lib/phusion_passenger/ruby_core_enhancements.rb +86 -86
  133. data/lib/phusion_passenger/ruby_core_io_enhancements.rb +74 -74
  134. data/lib/phusion_passenger/simple_benchmarking.rb +25 -25
  135. data/lib/phusion_passenger/standalone/app_finder.rb +153 -150
  136. data/lib/phusion_passenger/standalone/command.rb +44 -40
  137. data/lib/phusion_passenger/standalone/config_utils.rb +53 -53
  138. data/lib/phusion_passenger/standalone/control_utils.rb +38 -59
  139. data/lib/phusion_passenger/standalone/main.rb +73 -73
  140. data/lib/phusion_passenger/standalone/start_command.rb +697 -685
  141. data/lib/phusion_passenger/standalone/start_command/builtin_engine.rb +193 -155
  142. data/lib/phusion_passenger/standalone/start_command/nginx_engine.rb +162 -133
  143. data/lib/phusion_passenger/standalone/status_command.rb +64 -64
  144. data/lib/phusion_passenger/standalone/stop_command.rb +72 -72
  145. data/lib/phusion_passenger/standalone/version_command.rb +9 -9
  146. data/lib/phusion_passenger/union_station/connection.rb +32 -32
  147. data/lib/phusion_passenger/union_station/core.rb +251 -251
  148. data/lib/phusion_passenger/union_station/transaction.rb +126 -126
  149. data/lib/phusion_passenger/utils.rb +199 -167
  150. data/lib/phusion_passenger/utils/ansi_colors.rb +128 -128
  151. data/lib/phusion_passenger/utils/download.rb +196 -196
  152. data/lib/phusion_passenger/utils/file_system_watcher.rb +158 -158
  153. data/lib/phusion_passenger/utils/hosts_file_parser.rb +101 -101
  154. data/lib/phusion_passenger/utils/lock.rb +31 -31
  155. data/lib/phusion_passenger/utils/native_support_utils.rb +31 -31
  156. data/lib/phusion_passenger/utils/progress_bar.rb +26 -26
  157. data/lib/phusion_passenger/utils/shellwords.rb +20 -20
  158. data/lib/phusion_passenger/utils/terminal_choice_menu.rb +206 -206
  159. data/lib/phusion_passenger/utils/unseekable_socket.rb +272 -272
  160. data/lib/phusion_passenger/vendor/crash_watch/app.rb +129 -0
  161. data/lib/phusion_passenger/vendor/crash_watch/gdb_controller.rb +341 -0
  162. data/lib/phusion_passenger/vendor/crash_watch/version.rb +24 -0
  163. data/lib/phusion_passenger/vendor/daemon_controller.rb +877 -0
  164. data/lib/phusion_passenger/vendor/daemon_controller/lock_file.rb +127 -0
  165. data/lib/phusion_passenger/vendor/daemon_controller/spawn.rb +26 -0
  166. data/lib/phusion_passenger/vendor/daemon_controller/version.rb +29 -0
  167. data/packaging/rpm/passenger_spec/passenger.spec.template +0 -1
  168. data/passenger.gemspec +0 -1
  169. data/resources/templates/config/nginx_engine_compiler/possible_solutions_for_download_and_extraction_problems.txt.erb +27 -0
  170. data/resources/templates/standalone/config.erb +19 -15
  171. data/test/integration_tests/apache2_tests.rb +566 -566
  172. data/test/integration_tests/downloaded_binaries_tests.rb +126 -125
  173. data/test/integration_tests/native_packaging_spec.rb +296 -296
  174. data/test/integration_tests/nginx_tests.rb +393 -393
  175. data/test/integration_tests/shared/example_webapp_tests.rb +282 -280
  176. data/test/integration_tests/source_packaging_test.rb +138 -138
  177. data/test/integration_tests/spec_helper.rb +5 -5
  178. data/test/integration_tests/standalone_tests.rb +367 -367
  179. data/test/ruby/debug_logging_spec.rb +133 -133
  180. data/test/ruby/message_channel_spec.rb +186 -186
  181. data/test/ruby/rack/loader_spec.rb +28 -28
  182. data/test/ruby/rack/preloader_spec.rb +34 -34
  183. data/test/ruby/rails3.0/loader_spec.rb +12 -12
  184. data/test/ruby/rails3.0/preloader_spec.rb +18 -18
  185. data/test/ruby/rails3.1/loader_spec.rb +12 -12
  186. data/test/ruby/rails3.1/preloader_spec.rb +18 -18
  187. data/test/ruby/rails3.2/loader_spec.rb +12 -12
  188. data/test/ruby/rails3.2/preloader_spec.rb +18 -18
  189. data/test/ruby/rails4.0/loader_spec.rb +12 -12
  190. data/test/ruby/rails4.0/preloader_spec.rb +18 -18
  191. data/test/ruby/rails4.1/loader_spec.rb +12 -12
  192. data/test/ruby/rails4.1/preloader_spec.rb +18 -18
  193. data/test/ruby/request_handler_spec.rb +730 -730
  194. data/test/ruby/shared/loader_sharedspec.rb +224 -224
  195. data/test/ruby/shared/rails/union_station_extensions_sharedspec.rb +327 -327
  196. data/test/ruby/shared/ruby_loader_sharedspec.rb +47 -47
  197. data/test/ruby/spec_helper.rb +65 -65
  198. data/test/ruby/standalone/runtime_installer_spec.rb +384 -384
  199. data/test/ruby/union_station_spec.rb +276 -276
  200. data/test/ruby/utils/file_system_watcher_spec.rb +220 -220
  201. data/test/ruby/utils/hosts_file_parser.rb +248 -248
  202. data/test/ruby/utils/tee_input_spec.rb +215 -215
  203. data/test/ruby/utils/unseekable_socket_spec.rb +57 -57
  204. data/test/ruby/utils_spec.rb +21 -21
  205. data/test/stub/rack/config.ru +87 -87
  206. data/test/stub/rack/library.rb +8 -8
  207. data/test/stub/rack/start.rb +30 -30
  208. data/test/support/apache2_controller.rb +191 -191
  209. data/test/support/nginx_controller.rb +90 -99
  210. data/test/support/placebo-preloader.rb +57 -57
  211. data/test/support/test_helper.rb +435 -435
  212. metadata +11 -21
  213. metadata.gz.asc +7 -7
  214. data/lib/phusion_passenger/standalone/command2.rb +0 -292
  215. data/lib/phusion_passenger/standalone/start2_command.rb +0 -799
  216. data/resources/templates/standalone/download_tool_missing.txt.erb +0 -18
  217. data/resources/templates/standalone/possible_solutions_for_download_and_extraction_problems.txt.erb +0 -17
  218. data/resources/templates/standalone/run_installer_as_root.txt.erb +0 -8
@@ -12,30 +12,30 @@ PhusionPassenger.require_passenger_lib 'utils/native_support_utils'
12
12
  module PhusionPassenger
13
13
 
14
14
  describe Utils do
15
- include Utils
16
- include Utils::NativeSupportUtils
15
+ include Utils
16
+ include Utils::NativeSupportUtils
17
17
 
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
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
- 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
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
@@ -3,93 +3,93 @@
3
3
  require File.expand_path(File.dirname(__FILE__) + "/library")
4
4
 
5
5
  app = lambda do |env|
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
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
@@ -1,16 +1,16 @@
1
1
  # encoding: binary
2
2
 
3
3
  def text_response(body)
4
- body = binary_string(body.to_s)
5
- return [200, { "Content-Type" => "text/plain", "Content-Length" => body.size.to_s }, [body]]
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
- def binary_string(str)
10
- return str.force_encoding("binary")
11
- end
9
+ def binary_string(str)
10
+ return str.force_encoding("binary")
11
+ end
12
12
  else
13
- def binary_string(str)
14
- return str
15
- end
13
+ def binary_string(str)
14
+ return str
15
+ end
16
16
  end
@@ -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
- name, value = line.strip.split(/: */, 2)
12
- options[name] = value
11
+ name, value = line.strip.split(/: */, 2)
12
+ options[name] = value
13
13
  end
14
14
 
15
15
  if ARGV[0] == "--execself"
16
- # Used for testing https://code.google.com/p/phusion-passenger/issues/detail?id=842#c19
17
- exec("ruby", $0)
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
- 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
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
- include PhusionPassenger
45
- STUB_DIR = File.expand_path(File.dirname(__FILE__) + "/../stub/apache2")
44
+ include PhusionPassenger
45
+ STUB_DIR = File.expand_path(File.dirname(__FILE__) + "/../stub/apache2")
46
46
 
47
- class VHost
48
- attr_accessor :domain
49
- attr_accessor :document_root
50
- attr_accessor :additional_configs
47
+ class VHost
48
+ attr_accessor :domain
49
+ attr_accessor :document_root
50
+ attr_accessor :additional_configs
51
51
 
52
- def initialize(domain, document_root)
53
- @domain = domain
54
- @document_root = document_root
55
- @additional_configs = []
56
- end
52
+ def initialize(domain, document_root)
53
+ @domain = domain
54
+ @document_root = document_root
55
+ @additional_configs = []
56
+ end
57
57
 
58
- def <<(config)
59
- @additional_configs << config
60
- end
61
- end
58
+ def <<(config)
59
+ @additional_configs << config
60
+ end
61
+ end
62
62
 
63
- attr_accessor :port
64
- attr_accessor :vhosts
65
- attr_reader :server_root
63
+ attr_accessor :port
64
+ attr_accessor :vhosts
65
+ attr_reader :server_root
66
66
 
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
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
- def set(options)
78
- options.each_pair do |key, value|
79
- instance_variable_set("@#{key}", value)
80
- end
81
- end
77
+ def set(options)
78
+ options.each_pair do |key, value|
79
+ instance_variable_set("@#{key}", value)
80
+ end
81
+ end
82
82
 
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
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
- 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)
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
- if !system(PlatformInfo.httpd, "-f", "#{@server_root}/httpd.conf", "-k", "start")
103
- raise "Could not start an Apache server."
104
- end
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
- 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
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
- 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
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
- # 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
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
- # 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
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
- # 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
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
- # Defines a configuration snippet to be added to the Apache configuration file.
221
- def <<(line)
222
- @extra << line
223
- end
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
- def get_binding
227
- return binding
228
- end
226
+ def get_binding
227
+ return binding
228
+ end
229
229
 
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
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
- def modules_dir
238
- @@modules_dir ||= `#{PlatformInfo.apxs2} -q LIBEXECDIR`.strip
239
- end
237
+ def modules_dir
238
+ @@modules_dir ||= `#{PlatformInfo.apxs2} -q LIBEXECDIR`.strip
239
+ end
240
240
 
241
- def builtin_modules
242
- @@builtin_modules ||= `#{PlatformInfo.httpd} -l`.split("\n").grep(/\.c$/).map do |line|
243
- line.strip
244
- end
245
- end
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
- def has_builtin_module?(name)
248
- return builtin_modules.include?(name)
249
- end
247
+ def has_builtin_module?(name)
248
+ return builtin_modules.include?(name)
249
+ end
250
250
 
251
- def has_module?(name)
252
- return File.exist?("#{modules_dir}/#{name}")
253
- end
251
+ def has_module?(name)
252
+ return File.exist?("#{modules_dir}/#{name}")
253
+ end
254
254
 
255
- def we_are_root?
256
- return Process.uid == 0
257
- end
255
+ def we_are_root?
256
+ return Process.uid == 0
257
+ end
258
258
  end