passenger 2.1.3 → 2.2.0
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.
- data/DEVELOPERS.TXT +2 -0
- data/INSTALL +3 -1
- data/LICENSE +19 -355
- data/NEWS +3 -0
- data/README +11 -4
- data/Rakefile +435 -236
- data/bin/passenger-config +20 -14
- data/bin/passenger-install-apache2-module +67 -201
- data/bin/passenger-install-nginx-module +477 -0
- data/bin/passenger-make-enterprisey +17 -12
- data/bin/passenger-memory-stats +33 -23
- data/bin/passenger-spawn-server +17 -12
- data/bin/passenger-status +18 -13
- data/bin/passenger-stress-test +17 -12
- data/doc/{Users guide.html → Users guide Apache.html } +79 -61
- data/doc/{Users guide.txt → Users guide Apache.txt } +43 -939
- data/doc/Users guide Nginx.html +2276 -0
- data/doc/Users guide Nginx.txt +776 -0
- data/doc/cxxapi/ApplicationPoolServer_8h-source.html +9 -4
- data/doc/cxxapi/ApplicationPool_8h-source.html +9 -4
- data/doc/cxxapi/Application_8h-source.html +26 -21
- data/doc/cxxapi/Bucket_8h-source.html +54 -44
- data/doc/cxxapi/CachedFileStat_8h-source.html +9 -4
- data/doc/cxxapi/Configuration_8h-source.html +357 -339
- data/doc/cxxapi/DirectoryMapper_8h-source.html +294 -280
- data/doc/cxxapi/DummySpawnManager_8h-source.html +9 -4
- data/doc/cxxapi/Exceptions_8h-source.html +9 -4
- data/doc/cxxapi/FileChecker_8h-source.html +9 -4
- data/doc/cxxapi/Hooks_8h-source.html +50 -40
- data/doc/cxxapi/Logging_8h-source.html +9 -4
- data/doc/cxxapi/MessageChannel_8h-source.html +20 -15
- data/doc/cxxapi/PoolOptions_8h-source.html +10 -5
- data/doc/cxxapi/SpawnManager_8h-source.html +9 -4
- data/doc/cxxapi/StandardApplicationPool_8h-source.html +10 -5
- data/doc/cxxapi/SystemTime_8h-source.html +9 -4
- data/doc/cxxapi/Utils_8h-source.html +242 -214
- data/doc/cxxapi/annotated.html +4 -28
- data/doc/cxxapi/classClient-members.html +4 -4
- data/doc/cxxapi/classClient.html +14 -11
- data/doc/cxxapi/classHooks-members.html +4 -5
- data/doc/cxxapi/classHooks.html +26 -24
- data/doc/cxxapi/classPassenger_1_1Application-members.html +4 -4
- data/doc/cxxapi/classPassenger_1_1Application.html +40 -37
- data/doc/cxxapi/classPassenger_1_1ApplicationPool-members.html +4 -4
- data/doc/cxxapi/classPassenger_1_1ApplicationPool.html +95 -92
- data/doc/cxxapi/classPassenger_1_1ApplicationPoolServer-members.html +4 -4
- data/doc/cxxapi/classPassenger_1_1ApplicationPoolServer.html +26 -23
- data/doc/cxxapi/classPassenger_1_1ApplicationPool__inherit__graph.map +1 -1
- data/doc/cxxapi/classPassenger_1_1ApplicationPool__inherit__graph.md5 +1 -1
- data/doc/cxxapi/classPassenger_1_1ApplicationPool__inherit__graph.png +0 -0
- data/doc/cxxapi/classPassenger_1_1Application_1_1Session-members.html +17 -17
- data/doc/cxxapi/classPassenger_1_1Application_1_1Session.html +139 -136
- data/doc/cxxapi/classPassenger_1_1BufferedUpload-members.html +4 -4
- data/doc/cxxapi/classPassenger_1_1BufferedUpload.html +13 -10
- data/doc/cxxapi/classPassenger_1_1BusyException-members.html +4 -4
- data/doc/cxxapi/classPassenger_1_1BusyException.html +11 -8
- data/doc/cxxapi/classPassenger_1_1ConfigurationException-members.html +4 -4
- data/doc/cxxapi/classPassenger_1_1ConfigurationException.html +11 -8
- data/doc/cxxapi/classPassenger_1_1DirectoryMapper-members.html +4 -5
- data/doc/cxxapi/classPassenger_1_1DirectoryMapper.html +45 -43
- data/doc/cxxapi/classPassenger_1_1DummySpawnManager-members.html +4 -4
- data/doc/cxxapi/classPassenger_1_1DummySpawnManager.html +13 -10
- data/doc/cxxapi/classPassenger_1_1FileChecker-members.html +4 -4
- data/doc/cxxapi/classPassenger_1_1FileChecker.html +22 -19
- data/doc/cxxapi/classPassenger_1_1FileNotFoundException-members.html +4 -4
- data/doc/cxxapi/classPassenger_1_1FileNotFoundException.html +12 -9
- data/doc/cxxapi/classPassenger_1_1FileNotFoundException__inherit__graph.map +1 -1
- data/doc/cxxapi/classPassenger_1_1FileNotFoundException__inherit__graph.md5 +1 -1
- data/doc/cxxapi/classPassenger_1_1FileNotFoundException__inherit__graph.png +0 -0
- data/doc/cxxapi/classPassenger_1_1FileSystemException-members.html +4 -4
- data/doc/cxxapi/classPassenger_1_1FileSystemException.html +14 -11
- data/doc/cxxapi/classPassenger_1_1FileSystemException__inherit__graph.map +1 -1
- data/doc/cxxapi/classPassenger_1_1FileSystemException__inherit__graph.md5 +1 -1
- data/doc/cxxapi/classPassenger_1_1FileSystemException__inherit__graph.png +0 -0
- data/doc/cxxapi/classPassenger_1_1IOException-members.html +4 -4
- data/doc/cxxapi/classPassenger_1_1IOException.html +12 -9
- data/doc/cxxapi/classPassenger_1_1IOException__inherit__graph.map +1 -1
- data/doc/cxxapi/classPassenger_1_1IOException__inherit__graph.md5 +1 -1
- data/doc/cxxapi/classPassenger_1_1IOException__inherit__graph.png +0 -0
- data/doc/cxxapi/classPassenger_1_1MessageChannel-members.html +4 -4
- data/doc/cxxapi/classPassenger_1_1MessageChannel.html +228 -225
- data/doc/cxxapi/classPassenger_1_1RuntimeException-members.html +4 -4
- data/doc/cxxapi/classPassenger_1_1RuntimeException.html +11 -8
- data/doc/cxxapi/classPassenger_1_1SpawnException-members.html +4 -4
- data/doc/cxxapi/classPassenger_1_1SpawnException.html +14 -11
- data/doc/cxxapi/classPassenger_1_1SpawnManager-members.html +4 -4
- data/doc/cxxapi/classPassenger_1_1SpawnManager.html +50 -47
- data/doc/cxxapi/classPassenger_1_1StandardApplicationPool-members.html +4 -4
- data/doc/cxxapi/classPassenger_1_1StandardApplicationPool.html +73 -70
- data/doc/cxxapi/classPassenger_1_1StandardApplicationPool__inherit__graph.map +1 -1
- data/doc/cxxapi/classPassenger_1_1StandardApplicationPool__inherit__graph.md5 +1 -1
- data/doc/cxxapi/classPassenger_1_1StandardApplicationPool__inherit__graph.png +0 -0
- data/doc/cxxapi/classPassenger_1_1SystemException-members.html +4 -4
- data/doc/cxxapi/classPassenger_1_1SystemException.html +17 -14
- data/doc/cxxapi/classPassenger_1_1SystemException__inherit__graph.map +1 -1
- data/doc/cxxapi/classPassenger_1_1SystemException__inherit__graph.md5 +1 -1
- data/doc/cxxapi/classPassenger_1_1SystemException__inherit__graph.png +0 -0
- data/doc/cxxapi/classPassenger_1_1SystemTime-members.html +4 -4
- data/doc/cxxapi/classPassenger_1_1SystemTime.html +14 -11
- data/doc/cxxapi/classes.html +35 -0
- data/doc/cxxapi/definitions_8h-source.html +9 -4
- data/doc/cxxapi/doxygen.css +311 -303
- data/doc/cxxapi/files.html +9 -18
- data/doc/cxxapi/functions.html +5 -224
- data/doc/cxxapi/functions_func.html +5 -185
- data/doc/cxxapi/functions_type.html +4 -4
- data/doc/cxxapi/functions_vars.html +4 -4
- data/doc/cxxapi/graph_legend.dot +19 -19
- data/doc/cxxapi/graph_legend.html +5 -5
- data/doc/cxxapi/graph_legend.png +0 -0
- data/doc/cxxapi/group__Configuration.html +11 -13
- data/doc/cxxapi/group__Configuration.png +0 -0
- data/doc/cxxapi/group__Core.html +10 -12
- data/doc/cxxapi/group__Core.png +0 -0
- data/doc/cxxapi/group__Exceptions.html +5 -7
- data/doc/cxxapi/group__Hooks.html +5 -7
- data/doc/cxxapi/group__Hooks.png +0 -0
- data/doc/cxxapi/group__Support.html +5 -624
- data/doc/cxxapi/hierarchy.html +6 -6
- data/doc/cxxapi/inherit__graph__0.map +1 -1
- data/doc/cxxapi/inherit__graph__0.md5 +1 -1
- data/doc/cxxapi/inherit__graph__0.png +0 -0
- data/doc/cxxapi/inherit__graph__1.map +1 -1
- data/doc/cxxapi/inherit__graph__1.md5 +1 -1
- data/doc/cxxapi/inherit__graph__1.png +0 -0
- data/doc/cxxapi/inherit__graph__10.map +1 -1
- data/doc/cxxapi/inherit__graph__10.md5 +1 -1
- data/doc/cxxapi/inherit__graph__10.png +0 -0
- data/doc/cxxapi/inherit__graph__11.map +1 -1
- data/doc/cxxapi/inherit__graph__11.md5 +1 -1
- data/doc/cxxapi/inherit__graph__11.png +0 -0
- data/doc/cxxapi/inherit__graph__12.map +1 -1
- data/doc/cxxapi/inherit__graph__12.md5 +1 -1
- data/doc/cxxapi/inherit__graph__12.png +0 -0
- data/doc/cxxapi/inherit__graph__13.map +1 -2
- data/doc/cxxapi/inherit__graph__13.md5 +1 -1
- data/doc/cxxapi/inherit__graph__13.png +0 -0
- data/doc/cxxapi/inherit__graph__14.map +2 -1
- data/doc/cxxapi/inherit__graph__14.md5 +1 -1
- data/doc/cxxapi/inherit__graph__14.png +0 -0
- data/doc/cxxapi/inherit__graph__15.map +1 -1
- data/doc/cxxapi/inherit__graph__15.md5 +1 -1
- data/doc/cxxapi/inherit__graph__15.png +0 -0
- data/doc/cxxapi/inherit__graph__16.map +1 -1
- data/doc/cxxapi/inherit__graph__16.md5 +1 -1
- data/doc/cxxapi/inherit__graph__16.png +0 -0
- data/doc/cxxapi/inherit__graph__17.map +1 -1
- data/doc/cxxapi/inherit__graph__17.md5 +1 -1
- data/doc/cxxapi/inherit__graph__17.png +0 -0
- data/doc/cxxapi/inherit__graph__18.map +1 -1
- data/doc/cxxapi/inherit__graph__18.md5 +1 -1
- data/doc/cxxapi/inherit__graph__18.png +0 -0
- data/doc/cxxapi/inherit__graph__19.map +1 -1
- data/doc/cxxapi/inherit__graph__19.md5 +1 -1
- data/doc/cxxapi/inherit__graph__19.png +0 -0
- data/doc/cxxapi/inherit__graph__2.map +1 -1
- data/doc/cxxapi/inherit__graph__2.md5 +1 -1
- data/doc/cxxapi/inherit__graph__2.png +0 -0
- data/doc/cxxapi/inherit__graph__20.map +2 -2
- data/doc/cxxapi/inherit__graph__20.md5 +1 -1
- data/doc/cxxapi/inherit__graph__20.png +0 -0
- data/doc/cxxapi/inherit__graph__21.map +1 -1
- data/doc/cxxapi/inherit__graph__21.md5 +1 -1
- data/doc/cxxapi/inherit__graph__21.png +0 -0
- data/doc/cxxapi/inherit__graph__3.map +1 -1
- data/doc/cxxapi/inherit__graph__3.md5 +1 -1
- data/doc/cxxapi/inherit__graph__3.png +0 -0
- data/doc/cxxapi/inherit__graph__4.map +1 -1
- data/doc/cxxapi/inherit__graph__4.md5 +1 -1
- data/doc/cxxapi/inherit__graph__4.png +0 -0
- data/doc/cxxapi/inherit__graph__5.map +1 -2
- data/doc/cxxapi/inherit__graph__5.md5 +1 -1
- data/doc/cxxapi/inherit__graph__5.png +0 -0
- data/doc/cxxapi/inherit__graph__6.map +2 -1
- data/doc/cxxapi/inherit__graph__6.md5 +1 -1
- data/doc/cxxapi/inherit__graph__6.png +0 -0
- data/doc/cxxapi/inherit__graph__7.map +1 -1
- data/doc/cxxapi/inherit__graph__7.md5 +1 -1
- data/doc/cxxapi/inherit__graph__7.png +0 -0
- data/doc/cxxapi/inherit__graph__8.map +1 -1
- data/doc/cxxapi/inherit__graph__8.md5 +1 -1
- data/doc/cxxapi/inherit__graph__8.png +0 -0
- data/doc/cxxapi/inherit__graph__9.map +1 -1
- data/doc/cxxapi/inherit__graph__9.md5 +1 -1
- data/doc/cxxapi/inherit__graph__9.png +0 -0
- data/doc/cxxapi/inherits.html +41 -41
- data/doc/cxxapi/main.html +4 -4
- data/doc/cxxapi/modules.html +4 -5
- data/doc/cxxapi/structPassenger_1_1AnythingToString-members.html +4 -4
- data/doc/cxxapi/structPassenger_1_1AnythingToString.html +13 -10
- data/doc/cxxapi/structPassenger_1_1AnythingToString_3_01vector_3_01string_01_4_01_4-members.html +5 -5
- data/doc/cxxapi/structPassenger_1_1AnythingToString_3_01vector_3_01string_01_4_01_4.html +16 -13
- data/doc/cxxapi/structPassenger_1_1PoolOptions-members.html +4 -4
- data/doc/cxxapi/structPassenger_1_1PoolOptions.html +63 -60
- data/doc/cxxapi/tabs.css +5 -2
- data/doc/cxxapi/tree.html +7 -81
- data/doc/rdoc/classes/ConditionVariable.html +59 -59
- data/doc/rdoc/classes/Exception.html +11 -11
- data/doc/rdoc/classes/GC.html +4 -4
- data/doc/rdoc/classes/IO.html +14 -14
- data/doc/rdoc/classes/PhusionPassenger.html +75 -20
- data/doc/rdoc/classes/PhusionPassenger/AbstractInstaller.html +153 -0
- data/doc/rdoc/classes/PhusionPassenger/AbstractRequestHandler.html +125 -130
- data/doc/rdoc/classes/PhusionPassenger/AbstractServer.html +236 -236
- data/doc/rdoc/classes/PhusionPassenger/AbstractServerCollection.html +213 -213
- data/doc/rdoc/classes/PhusionPassenger/AdminTools.html +28 -28
- data/doc/rdoc/classes/PhusionPassenger/AdminTools/ControlProcess.html +91 -75
- data/doc/rdoc/classes/PhusionPassenger/AppInitError.html +10 -10
- data/doc/rdoc/classes/PhusionPassenger/Application.html +64 -64
- data/doc/rdoc/classes/PhusionPassenger/ConsoleTextTemplate.html +34 -34
- data/doc/rdoc/classes/PhusionPassenger/FrameworkInitError.html +13 -13
- data/doc/rdoc/classes/PhusionPassenger/HTMLTemplate.html +30 -30
- data/doc/rdoc/classes/PhusionPassenger/InitializationError.html +10 -10
- data/doc/rdoc/classes/PhusionPassenger/MessageChannel.html +136 -136
- data/doc/rdoc/classes/PhusionPassenger/NativeSupport.html +24 -24
- data/doc/rdoc/classes/PhusionPassenger/Rack/ApplicationSpawner.html +42 -42
- data/doc/rdoc/classes/PhusionPassenger/Rack/RequestHandler.html +55 -53
- data/doc/rdoc/classes/PhusionPassenger/Railz.html +1 -1
- data/doc/rdoc/classes/PhusionPassenger/Railz/ApplicationSpawner.html +25 -30
- data/doc/rdoc/classes/PhusionPassenger/Railz/CGIFixed.html +23 -23
- data/doc/rdoc/classes/PhusionPassenger/Railz/FrameworkSpawner.html +116 -117
- data/doc/rdoc/classes/PhusionPassenger/Railz/RequestHandler.html +22 -22
- data/doc/rdoc/classes/PhusionPassenger/SpawnManager.html +118 -124
- data/doc/rdoc/classes/PhusionPassenger/UnknownError.html +10 -10
- data/doc/rdoc/classes/PhusionPassenger/Utils.html +354 -354
- data/doc/rdoc/classes/PhusionPassenger/VersionNotFound.html +9 -9
- data/doc/rdoc/classes/PhusionPassenger/WSGI/ApplicationSpawner.html +37 -37
- data/doc/rdoc/classes/PlatformInfo.html +282 -261
- data/doc/rdoc/classes/RakeExtensions.html +7 -7
- data/doc/rdoc/classes/Signal.html +26 -26
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/DEVELOPERS_TXT.html +6 -1
- data/doc/rdoc/files/README.html +15 -6
- data/doc/rdoc/files/ext/phusion_passenger/native_support_c.html +1 -1
- data/doc/rdoc/files/lib/phusion_passenger/abstract_installer_rb.html +129 -0
- data/doc/rdoc/files/lib/phusion_passenger/abstract_request_handler_rb.html +20 -13
- data/doc/rdoc/files/lib/phusion_passenger/abstract_server_collection_rb.html +19 -13
- data/doc/rdoc/files/lib/phusion_passenger/abstract_server_rb.html +19 -13
- data/doc/rdoc/files/lib/phusion_passenger/admin_tools/control_process_rb.html +31 -1
- data/doc/rdoc/files/lib/phusion_passenger/admin_tools_rb.html +31 -1
- data/doc/rdoc/files/lib/phusion_passenger/application_rb.html +19 -13
- data/doc/rdoc/files/lib/phusion_passenger/console_text_template_rb.html +19 -13
- data/doc/rdoc/files/lib/phusion_passenger/constants_rb.html +21 -12
- data/doc/rdoc/files/lib/phusion_passenger/dependencies_rb.html +19 -13
- data/doc/rdoc/files/lib/phusion_passenger/events_rb.html +19 -13
- data/doc/rdoc/files/lib/phusion_passenger/exceptions_rb.html +19 -13
- data/doc/rdoc/files/lib/phusion_passenger/html_template_rb.html +19 -13
- data/doc/rdoc/files/lib/phusion_passenger/message_channel_rb.html +19 -13
- data/doc/rdoc/files/lib/phusion_passenger/packaging_rb.html +122 -0
- data/doc/rdoc/files/lib/phusion_passenger/platform_info_rb.html +19 -13
- data/doc/rdoc/files/lib/phusion_passenger/rack/application_spawner_rb.html +22 -12
- data/doc/rdoc/files/lib/phusion_passenger/rack/request_handler_rb.html +21 -12
- data/doc/rdoc/files/lib/phusion_passenger/railz/application_spawner_rb.html +19 -13
- data/doc/rdoc/files/lib/phusion_passenger/railz/cgi_fixed_rb.html +1 -1
- data/doc/rdoc/files/lib/phusion_passenger/railz/framework_spawner_rb.html +19 -13
- data/doc/rdoc/files/lib/phusion_passenger/railz/request_handler_rb.html +21 -12
- data/doc/rdoc/files/lib/phusion_passenger/simple_benchmarking_rb.html +19 -13
- data/doc/rdoc/files/lib/phusion_passenger/spawn_manager_rb.html +19 -13
- data/doc/rdoc/files/lib/phusion_passenger/utils_rb.html +27 -21
- data/doc/rdoc/files/lib/phusion_passenger/wsgi/application_spawner_rb.html +21 -12
- data/doc/rdoc/files/misc/rake/extensions_rb.html +21 -12
- data/doc/rdoc/fr_class_index.html +1 -0
- data/doc/rdoc/fr_file_index.html +2 -0
- data/doc/rdoc/fr_method_index.html +116 -112
- data/doc/users_guide_snippets/analysis_and_system_maintenance_tools.txt +144 -0
- data/doc/users_guide_snippets/appendix_a_about.txt +13 -0
- data/doc/users_guide_snippets/appendix_b_terminology.txt +63 -0
- data/doc/users_guide_snippets/appendix_c_spawning_methods.txt +304 -0
- data/doc/users_guide_snippets/global_queueing_explained.txt +78 -0
- data/doc/users_guide_snippets/rackup_specifications.txt +75 -0
- data/doc/users_guide_snippets/rails_spawn_method.txt +48 -0
- data/doc/users_guide_snippets/tips.txt +173 -0
- data/ext/apache2/Bucket.cpp +17 -12
- data/ext/apache2/Bucket.h +17 -12
- data/ext/apache2/Configuration.cpp +17 -12
- data/ext/apache2/Configuration.h +27 -14
- data/ext/apache2/DirectoryMapper.h +21 -12
- data/ext/apache2/Hooks.cpp +67 -21
- data/ext/apache2/Hooks.h +17 -12
- data/ext/apache2/mod_passenger.c +17 -12
- data/ext/{apache2 → common}/Application.h +19 -14
- data/ext/{apache2 → common}/ApplicationPool.h +17 -12
- data/ext/{apache2 → common}/ApplicationPoolServer.h +18 -72
- data/ext/{apache2 → common}/ApplicationPoolServerExecutable.cpp +45 -104
- data/ext/common/ApplicationPoolStatusReporter.h +212 -0
- data/ext/{apache2 → common}/CachedFileStat.cpp +17 -12
- data/ext/{apache2 → common}/CachedFileStat.h +17 -12
- data/ext/{apache2 → common}/DummySpawnManager.h +17 -12
- data/ext/{apache2 → common}/Exceptions.h +17 -12
- data/ext/{apache2 → common}/FileChecker.h +17 -12
- data/ext/common/Logging.cpp +65 -0
- data/ext/{apache2 → common}/Logging.h +17 -12
- data/ext/{apache2 → common}/MessageChannel.h +17 -12
- data/ext/{apache2 → common}/PoolOptions.h +17 -12
- data/ext/{apache2 → common}/SpawnManager.h +17 -12
- data/ext/{apache2 → common}/StandardApplicationPool.h +17 -12
- data/ext/common/StaticString.h +147 -0
- data/ext/common/SystemTime.cpp +33 -0
- data/ext/{apache2 → common}/SystemTime.h +17 -12
- data/ext/{apache2 → common}/Utils.cpp +69 -12
- data/ext/{apache2 → common}/Utils.h +41 -12
- data/ext/nginx/Configuration.c +1091 -0
- data/ext/nginx/Configuration.h +71 -0
- data/ext/nginx/ContentHandler.c +1154 -0
- data/ext/nginx/ContentHandler.h +64 -0
- data/ext/nginx/HelperServer.cpp +857 -0
- data/ext/nginx/HttpStatusExtractor.h +161 -0
- data/ext/nginx/ScgiRequestParser.h +317 -0
- data/ext/nginx/StaticContentHandler.c +222 -0
- data/ext/nginx/StaticContentHandler.h +37 -0
- data/ext/nginx/config +41 -0
- data/ext/nginx/ngx_http_passenger_module.c +572 -0
- data/ext/nginx/ngx_http_passenger_module.h +72 -0
- data/ext/oxt/backtrace.cpp +8 -1
- data/ext/oxt/system_calls.cpp +40 -0
- data/ext/oxt/system_calls.hpp +14 -7
- data/ext/phusion_passenger/extconf.rb +17 -12
- data/ext/phusion_passenger/native_support.c +19 -12
- data/lib/phusion_passenger/abstract_installer.rb +196 -0
- data/lib/phusion_passenger/abstract_request_handler.rb +19 -24
- data/lib/phusion_passenger/abstract_server.rb +17 -12
- data/lib/phusion_passenger/abstract_server_collection.rb +17 -12
- data/lib/phusion_passenger/admin_tools.rb +23 -0
- data/lib/phusion_passenger/admin_tools/control_process.rb +39 -13
- data/lib/phusion_passenger/application.rb +17 -12
- data/lib/phusion_passenger/console_text_template.rb +17 -12
- data/lib/phusion_passenger/constants.rb +22 -11
- data/lib/phusion_passenger/dependencies.rb +47 -12
- data/lib/phusion_passenger/events.rb +17 -12
- data/lib/phusion_passenger/exceptions.rb +17 -12
- data/lib/phusion_passenger/html_template.rb +17 -12
- data/lib/phusion_passenger/message_channel.rb +17 -12
- data/lib/phusion_passenger/packaging.rb +39 -0
- data/lib/phusion_passenger/platform_info.rb +48 -22
- data/lib/phusion_passenger/rack/application_spawner.rb +22 -11
- data/lib/phusion_passenger/rack/request_handler.rb +21 -12
- data/lib/phusion_passenger/railz/application_spawner.rb +23 -23
- data/lib/phusion_passenger/railz/framework_spawner.rb +18 -14
- data/lib/phusion_passenger/railz/request_handler.rb +18 -11
- data/lib/phusion_passenger/simple_benchmarking.rb +17 -12
- data/lib/phusion_passenger/spawn_manager.rb +17 -20
- data/lib/phusion_passenger/templates/{apache_must_be_compiled_with_compatible_mpm.txt.erb → apache2/apache_must_be_compiled_with_compatible_mpm.txt.erb} +0 -0
- data/lib/phusion_passenger/templates/{apache2_config_snippets.txt.erb → apache2/config_snippets.txt.erb} +0 -0
- data/lib/phusion_passenger/templates/{deployment_example.txt.erb → apache2/deployment_example.txt.erb} +0 -0
- data/lib/phusion_passenger/templates/{no_write_permission_to_passenger_root.txt.erb → apache2/no_write_permission_to_passenger_root.txt.erb} +0 -0
- data/lib/phusion_passenger/templates/{possible_solutions_for_compilation_and_installation_problems.txt.erb → apache2/possible_solutions_for_compilation_and_installation_problems.txt.erb} +0 -0
- data/lib/phusion_passenger/templates/{run_installer_as_root.txt.erb → apache2/run_installer_as_root.txt.erb} +0 -0
- data/lib/phusion_passenger/templates/{welcome.txt.erb → apache2/welcome.txt.erb} +0 -0
- data/lib/phusion_passenger/templates/nginx/ask_for_extra_configure_flags.txt.erb +8 -0
- data/lib/phusion_passenger/templates/nginx/cannot_write_to_dir.txt.erb +11 -0
- data/lib/phusion_passenger/templates/nginx/config_snippets.txt.erb +17 -0
- data/lib/phusion_passenger/templates/nginx/config_snippets_inserted.txt.erb +20 -0
- data/lib/phusion_passenger/templates/nginx/confirm_extra_configure_flags.txt.erb +5 -0
- data/lib/phusion_passenger/templates/nginx/deployment_example.txt.erb +22 -0
- data/lib/phusion_passenger/templates/nginx/pcre_could_not_be_downloaded.txt.erb +11 -0
- data/lib/phusion_passenger/templates/nginx/pcre_could_not_be_extracted.txt.erb +11 -0
- data/lib/phusion_passenger/templates/nginx/possible_solutions_for_compilation_and_installation_problems.txt.erb +11 -0
- data/lib/phusion_passenger/templates/nginx/possible_solutions_for_download_and_extraction_problems.txt.erb +20 -0
- data/lib/phusion_passenger/templates/nginx/query_download_and_install.txt.erb +21 -0
- data/lib/phusion_passenger/templates/nginx/run_installer_as_root.txt.erb +8 -0
- data/lib/phusion_passenger/templates/nginx/welcome.txt.erb +15 -0
- data/lib/phusion_passenger/utils.rb +20 -15
- data/lib/phusion_passenger/wsgi/application_spawner.rb +18 -11
- data/lib/phusion_passenger/wsgi/request_handler.py +23 -0
- data/misc/copy_boost_headers.rb +23 -0
- data/misc/find_owner_pipe_leaks.rb +18 -11
- data/misc/rake/cplusplus.rb +18 -11
- data/misc/rake/extensions.rb +21 -14
- data/misc/render_error_pages.rb +18 -11
- data/test/ApplicationPoolServerTest.cpp +1 -3
- data/test/ApplicationPoolServer_ApplicationPoolTest.cpp +1 -1
- data/test/CxxTestMain.cpp +19 -3
- data/test/HttpStatusExtractorTest.cpp +181 -0
- data/test/ScgiRequestParserTest.cpp +337 -0
- data/test/StaticStringTest.cpp +51 -0
- data/test/UtilsTest.cpp +32 -0
- data/test/config.yml.example +5 -0
- data/test/{integration_tests.rb → integration_tests/apache2_tests.rb} +7 -299
- data/test/integration_tests/hello_world_rack_spec.rb +36 -0
- data/test/integration_tests/hello_world_wsgi_spec.rb +41 -0
- data/test/integration_tests/mycook_spec.rb +192 -0
- data/test/integration_tests/nginx_tests.rb +98 -0
- data/test/ruby/rack/application_spawner_spec.rb +40 -0
- data/test/stub/nginx/koi-utf +109 -0
- data/test/stub/nginx/koi-win +103 -0
- data/test/stub/nginx/mime.types +70 -0
- data/test/stub/nginx/nginx.conf.erb +57 -0
- data/test/stub/nginx/win-utf +126 -0
- data/test/stub/rails_apps/mycook/app/controllers/uploads_controller.rb +4 -0
- data/test/stub/rails_apps/mycook/config/routes.rb +1 -1
- data/test/stub/wsgi/passenger_wsgi.pyc +0 -0
- data/test/support/Support.h +40 -0
- data/test/support/nginx_controller.rb +98 -0
- data/test/support/test_helper.rb +79 -0
- metadata +1091 -1028
- data/benchmark/DummyRequestHandler.cpp +0 -101
- data/ext/apache2/Logging.cpp +0 -60
- data/ext/apache2/SystemTime.cpp +0 -28
@@ -0,0 +1,64 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) Igor Sysoev
|
3
|
+
* Copyright (C) 2007 Manlio Perillo (manlio.perillo@gmail.com)
|
4
|
+
* Copyright (C) 2008, 2009 Phusion
|
5
|
+
*
|
6
|
+
* Redistribution and use in source and binary forms, with or without
|
7
|
+
* modification, are permitted provided that the following conditions
|
8
|
+
* are met:
|
9
|
+
* 1. Redistributions of source code must retain the above copyright
|
10
|
+
* notice, this list of conditions and the following disclaimer.
|
11
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
12
|
+
* notice, this list of conditions and the following disclaimer in the
|
13
|
+
* documentation and/or other materials provided with the distribution.
|
14
|
+
*
|
15
|
+
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
16
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
17
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
18
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
19
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
20
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
21
|
+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
22
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
23
|
+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
24
|
+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
25
|
+
* SUCH DAMAGE.
|
26
|
+
*/
|
27
|
+
|
28
|
+
#ifndef _PASSENGER_NGINX_CONTENT_HANDLER_H_
|
29
|
+
#define _PASSENGER_NGINX_CONTENT_HANDLER_H_
|
30
|
+
|
31
|
+
#include <ngx_core.h>
|
32
|
+
#include <ngx_http.h>
|
33
|
+
|
34
|
+
|
35
|
+
typedef enum {
|
36
|
+
AP_RAILS,
|
37
|
+
AP_RACK,
|
38
|
+
AP_WSGI,
|
39
|
+
AP_NONE
|
40
|
+
} passenger_app_type_t;
|
41
|
+
|
42
|
+
typedef struct {
|
43
|
+
/** Proxy state. */
|
44
|
+
ngx_uint_t status;
|
45
|
+
ngx_uint_t status_count;
|
46
|
+
u_char *status_start;
|
47
|
+
u_char *status_end;
|
48
|
+
|
49
|
+
/** The backend application's 'public' directory. */
|
50
|
+
ngx_str_t public_dir;
|
51
|
+
|
52
|
+
/** The application's base URI. Points to an empty string if none. */
|
53
|
+
ngx_str_t base_uri;
|
54
|
+
|
55
|
+
/** The backend application's type. */
|
56
|
+
passenger_app_type_t app_type;
|
57
|
+
} passenger_context_t;
|
58
|
+
|
59
|
+
|
60
|
+
ngx_int_t passenger_content_handler(ngx_http_request_t *r);
|
61
|
+
|
62
|
+
|
63
|
+
#endif /* _PASSENGER_NGINX_CONTENT_HANDLER_H_ */
|
64
|
+
|
@@ -0,0 +1,857 @@
|
|
1
|
+
/*
|
2
|
+
* Phusion Passenger - http://www.modrails.com/
|
3
|
+
* Copyright (c) 2009 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
|
+
|
26
|
+
#include <sys/types.h>
|
27
|
+
#include <sys/socket.h>
|
28
|
+
#include <sys/stat.h>
|
29
|
+
#include <sys/un.h>
|
30
|
+
#include <cstring>
|
31
|
+
#include <unistd.h>
|
32
|
+
#include <errno.h>
|
33
|
+
#include <signal.h>
|
34
|
+
#include <pwd.h>
|
35
|
+
|
36
|
+
#include <set>
|
37
|
+
#include <vector>
|
38
|
+
#include <string>
|
39
|
+
|
40
|
+
#include <boost/thread.hpp>
|
41
|
+
#include <boost/shared_ptr.hpp>
|
42
|
+
#include "oxt/thread.hpp"
|
43
|
+
#include "oxt/system_calls.hpp"
|
44
|
+
|
45
|
+
#include "ScgiRequestParser.h"
|
46
|
+
#include "HttpStatusExtractor.h"
|
47
|
+
|
48
|
+
#include "StandardApplicationPool.h"
|
49
|
+
#include "ApplicationPoolStatusReporter.h"
|
50
|
+
#include "Application.h"
|
51
|
+
#include "PoolOptions.h"
|
52
|
+
#include "Exceptions.h"
|
53
|
+
#include "Utils.h"
|
54
|
+
|
55
|
+
using namespace boost;
|
56
|
+
using namespace oxt;
|
57
|
+
using namespace Passenger;
|
58
|
+
|
59
|
+
#define HELPER_SERVER_PASSWORD_SIZE 64
|
60
|
+
|
61
|
+
|
62
|
+
/**
|
63
|
+
* Wrapper class around a file descriptor integer, for RAII behavior.
|
64
|
+
*
|
65
|
+
* A FileDescriptor object behaves just like an int, so that you can pass it to
|
66
|
+
* system calls such as read(). It performs reference counting. When the last
|
67
|
+
* copy of a FileDescriptor has been destroyed, the underlying file descriptor
|
68
|
+
* will be automatically closed.
|
69
|
+
*/
|
70
|
+
class FileDescriptor {
|
71
|
+
private:
|
72
|
+
struct SharedData {
|
73
|
+
int fd;
|
74
|
+
|
75
|
+
/**
|
76
|
+
* Constructor to assign this file descriptor's handle.
|
77
|
+
*/
|
78
|
+
SharedData(int fd) {
|
79
|
+
this->fd = fd;
|
80
|
+
}
|
81
|
+
|
82
|
+
/**
|
83
|
+
* Attempts to close this file descriptor. When created on the stack,
|
84
|
+
* this destructor will automatically be invoked as a result of C++
|
85
|
+
* semantics when exiting the scope this object was created in. This
|
86
|
+
* ensures that stack created objects with destructors like these will
|
87
|
+
* de-allocate their resources upon leaving their corresponding scope.
|
88
|
+
* This pattern is also known Resource Acquisition Is Initialization (RAII).
|
89
|
+
*
|
90
|
+
* @throws SystemException File descriptor could not be closed.
|
91
|
+
*/
|
92
|
+
~SharedData() {
|
93
|
+
if (syscalls::close(fd) == -1) {
|
94
|
+
throw SystemException("Cannot close file descriptor", errno);
|
95
|
+
}
|
96
|
+
}
|
97
|
+
};
|
98
|
+
|
99
|
+
/* Shared pointer for reference counting on this file descriptor */
|
100
|
+
shared_ptr<SharedData> data;
|
101
|
+
|
102
|
+
public:
|
103
|
+
FileDescriptor() {
|
104
|
+
// Do nothing.
|
105
|
+
}
|
106
|
+
|
107
|
+
/**
|
108
|
+
* Creates a new FileDescriptor instance with the given fd as a handle.
|
109
|
+
*/
|
110
|
+
FileDescriptor(int fd) {
|
111
|
+
data = ptr(new SharedData(fd));
|
112
|
+
}
|
113
|
+
|
114
|
+
/**
|
115
|
+
* Overloads the integer cast operator so that it will return the file
|
116
|
+
* descriptor handle as an integer.
|
117
|
+
*
|
118
|
+
* @return This file descriptor's handle as an integer.
|
119
|
+
*/
|
120
|
+
operator int () const {
|
121
|
+
return data->fd;
|
122
|
+
}
|
123
|
+
};
|
124
|
+
|
125
|
+
/**
|
126
|
+
* A representation of a Client from the Server's point of view. This class
|
127
|
+
* contains the methods used to communicate from a server to a connected
|
128
|
+
* client, i.e. it is a client handler.
|
129
|
+
* These Client instances will communicate concurrently with the server through
|
130
|
+
* threads. Considering the overhead of these threads, i.e. setup and teardown
|
131
|
+
* costs and the volatility of client requests, these client instances will be
|
132
|
+
* pooled. It is for this reason that the State design pattern has been applied:
|
133
|
+
* this class can be considered as being a skeleton implemention whose state
|
134
|
+
* --e.g. the client file descriptor-- needs to be provided in order to function
|
135
|
+
* properly.
|
136
|
+
*/
|
137
|
+
class Client {
|
138
|
+
private:
|
139
|
+
/** The client thread stack size in bytes. */
|
140
|
+
static const int CLIENT_THREAD_STACK_SIZE = 1024 * 128;
|
141
|
+
|
142
|
+
/** The client number for this Client object, assigned by Server. */
|
143
|
+
unsigned int number;
|
144
|
+
|
145
|
+
/** The application pool to which this Client object belongs to. */
|
146
|
+
StandardApplicationPoolPtr pool;
|
147
|
+
|
148
|
+
/** This client's password. */
|
149
|
+
string password;
|
150
|
+
|
151
|
+
/** Whether privilege lowering should be used. */
|
152
|
+
bool lowerPrivilege;
|
153
|
+
|
154
|
+
/** The user that spawned processes should run as, if initial attempt
|
155
|
+
* at privilege lowering failed. */
|
156
|
+
string lowestUser;
|
157
|
+
|
158
|
+
/** The server socket file descriptor. */
|
159
|
+
int serverSocket;
|
160
|
+
|
161
|
+
/** This client's thread. */
|
162
|
+
oxt::thread *thr;
|
163
|
+
|
164
|
+
/**
|
165
|
+
* Attempts to accept a connection made by the client.
|
166
|
+
*
|
167
|
+
* @return The file descriptor corresponding to the accepted connection.
|
168
|
+
* @throws SystemException Could not accept new connection.
|
169
|
+
*/
|
170
|
+
FileDescriptor acceptConnection() {
|
171
|
+
TRACE_POINT();
|
172
|
+
struct sockaddr_un addr;
|
173
|
+
socklen_t addrlen = sizeof(addr);
|
174
|
+
int fd = syscalls::accept(serverSocket,
|
175
|
+
(struct sockaddr *) &addr,
|
176
|
+
&addrlen);
|
177
|
+
if (fd == -1) {
|
178
|
+
throw SystemException("Cannot accept new connection", errno);
|
179
|
+
} else {
|
180
|
+
return FileDescriptor(fd);
|
181
|
+
}
|
182
|
+
}
|
183
|
+
|
184
|
+
/**
|
185
|
+
* Reads and checks the password of a client message channel identified by the given file descriptor.
|
186
|
+
* The HelperServer makes extensive use of Unix Sockets that would normally allow other processes to
|
187
|
+
* connect to it as well. In our case, we just want to limit this to Nginx and it is for this reason
|
188
|
+
* that we've secured communication channels between this server and its clients with passwords.
|
189
|
+
* This method indicates whether or not the password of this client channel matches the one known to
|
190
|
+
* the server.
|
191
|
+
*
|
192
|
+
* @param fd The file descriptor identifying the client message channel.
|
193
|
+
* @return True if the password of the client channel indicated by the given file descriptor
|
194
|
+
* matches the password known to the server. False will be returned if either the
|
195
|
+
* passwords don't match or EOF has been encountered.
|
196
|
+
*/
|
197
|
+
bool readAndCheckPassword(FileDescriptor &fd) {
|
198
|
+
TRACE_POINT();
|
199
|
+
MessageChannel channel(fd);
|
200
|
+
char buf[HELPER_SERVER_PASSWORD_SIZE];
|
201
|
+
|
202
|
+
if (channel.readRaw(buf, sizeof(buf))) {
|
203
|
+
const char *password_data;
|
204
|
+
|
205
|
+
password_data = const_cast<const string &>(password).c_str();
|
206
|
+
return memcmp(password_data, buf, sizeof(buf)) == 0;
|
207
|
+
} else {
|
208
|
+
return false;
|
209
|
+
}
|
210
|
+
}
|
211
|
+
|
212
|
+
/**
|
213
|
+
* Reads and parses the request headers from the given file descriptor with the given SCGI request parser
|
214
|
+
* and if succesful, assigns the remainder of the request (i.e. non SCGI header data) to the given
|
215
|
+
* requestBody.
|
216
|
+
*
|
217
|
+
* @param fd The file descriptor to read and parse from.
|
218
|
+
* @param parser The ScgiRequestParser to use for parsing the SCGI headers.
|
219
|
+
* @param requestBody The requestBody that was extracted as a result from parsing the SCGI headers.
|
220
|
+
* @return True if the request was succesfully read and parsed. False if an invalid SCGI header was
|
221
|
+
* received by the parser or if the header information was invalid.
|
222
|
+
* @throws SystemException Request header could not be read.
|
223
|
+
*/
|
224
|
+
bool readAndParseRequestHeaders(FileDescriptor &fd, ScgiRequestParser &parser, string &requestBody) {
|
225
|
+
TRACE_POINT();
|
226
|
+
char buf[1024 * 16];
|
227
|
+
ssize_t size;
|
228
|
+
unsigned int accepted = 0;
|
229
|
+
|
230
|
+
do {
|
231
|
+
size = syscalls::read(fd, buf, sizeof(buf));
|
232
|
+
if (size == -1) {
|
233
|
+
throw SystemException("Cannot read request header", errno);
|
234
|
+
} else if (size == 0) {
|
235
|
+
break;
|
236
|
+
} else {
|
237
|
+
accepted = parser.feed(buf, size);
|
238
|
+
}
|
239
|
+
} while (parser.acceptingInput());
|
240
|
+
|
241
|
+
if (parser.getState() != ScgiRequestParser::DONE) {
|
242
|
+
P_ERROR("Invalid SCGI header received.");
|
243
|
+
return false;
|
244
|
+
} else if (!parser.hasHeader("DOCUMENT_ROOT")) {
|
245
|
+
P_ERROR("DOCUMENT_ROOT header is missing.");
|
246
|
+
return false;
|
247
|
+
} else {
|
248
|
+
requestBody.assign(buf + accepted, size - accepted);
|
249
|
+
return true;
|
250
|
+
}
|
251
|
+
}
|
252
|
+
|
253
|
+
/**
|
254
|
+
* Sends a request body to this client. The <tt>partialRequestBody</tt> will first be
|
255
|
+
* sent to the specified <tt>session</tt>, but if the specified <tt>contentLength</tt>
|
256
|
+
* is larger than the size of the <tt>partialRequestBody</tt>, then this method will
|
257
|
+
* attempt to read the remaining bytes from the specified <tt>clientFd</tt> and send it
|
258
|
+
* to the <tt>session</tt> as well until <tt>contentLength</tt> bytes have been sent in
|
259
|
+
* total.
|
260
|
+
*
|
261
|
+
* @param session The Ruby on Rails application instance.
|
262
|
+
* @param clientFd The client file descriptor to send the request body to.
|
263
|
+
* @param partialRequestBody The partial request body to send to this client.
|
264
|
+
* @param contentLength The content length of the request body in bytes.
|
265
|
+
* @throws SystemException Request body could not be read from the specified
|
266
|
+
* <tt>clientFd</tt>.
|
267
|
+
*/
|
268
|
+
void sendRequestBody(Application::SessionPtr &session,
|
269
|
+
FileDescriptor &clientFd,
|
270
|
+
const string &partialRequestBody,
|
271
|
+
unsigned long contentLength) {
|
272
|
+
TRACE_POINT();
|
273
|
+
char buf[1024 * 16];
|
274
|
+
ssize_t size;
|
275
|
+
size_t bytesToRead;
|
276
|
+
unsigned long bytesForwarded = 0;
|
277
|
+
|
278
|
+
if (partialRequestBody.size() > 0) {
|
279
|
+
UPDATE_TRACE_POINT();
|
280
|
+
session->sendBodyBlock(partialRequestBody.c_str(),
|
281
|
+
partialRequestBody.size());
|
282
|
+
bytesForwarded = partialRequestBody.size();
|
283
|
+
}
|
284
|
+
|
285
|
+
bool done = bytesForwarded == contentLength;
|
286
|
+
while (!done) {
|
287
|
+
UPDATE_TRACE_POINT();
|
288
|
+
|
289
|
+
bytesToRead = contentLength - bytesForwarded;
|
290
|
+
if (bytesToRead > sizeof(buf)) {
|
291
|
+
bytesToRead = sizeof(buf);
|
292
|
+
}
|
293
|
+
size = syscalls::read(clientFd, buf, bytesToRead);
|
294
|
+
|
295
|
+
if (size == 0) {
|
296
|
+
done = true;
|
297
|
+
} else if (size == -1) {
|
298
|
+
throw SystemException("Cannot read request body", errno);
|
299
|
+
} else {
|
300
|
+
UPDATE_TRACE_POINT();
|
301
|
+
session->sendBodyBlock(buf, size);
|
302
|
+
bytesForwarded += size;
|
303
|
+
done = bytesForwarded == contentLength;
|
304
|
+
}
|
305
|
+
}
|
306
|
+
}
|
307
|
+
|
308
|
+
/**
|
309
|
+
* Forwards an HTTP response from the given (Rails) <tt>session</tt> to the
|
310
|
+
* given <tt>clientFd</tt>.
|
311
|
+
*
|
312
|
+
* @param session The Ruby on Rails session to read the response from.
|
313
|
+
* @param clientFd The client file descriptor to write the response to.
|
314
|
+
* @throws SystemException Response could not be read from backend (Rails) process.
|
315
|
+
*/
|
316
|
+
void forwardResponse(Application::SessionPtr &session, FileDescriptor &clientFd) {
|
317
|
+
TRACE_POINT();
|
318
|
+
HttpStatusExtractor ex;
|
319
|
+
int stream = session->getStream();
|
320
|
+
int eof = false;
|
321
|
+
MessageChannel output(clientFd);
|
322
|
+
char buf[1024 * 32];
|
323
|
+
ssize_t size;
|
324
|
+
|
325
|
+
/* Read data from the backend process until we're able to
|
326
|
+
* extract the HTTP status line from it.
|
327
|
+
*/
|
328
|
+
while (!eof) {
|
329
|
+
UPDATE_TRACE_POINT();
|
330
|
+
size = syscalls::read(stream, buf, sizeof(buf));
|
331
|
+
if (size == 0) {
|
332
|
+
eof = true;
|
333
|
+
} else if (size == -1) {
|
334
|
+
throw SystemException("Cannot read response from backend process", errno);
|
335
|
+
} else if (ex.feed(buf, size)) {
|
336
|
+
/* We now have an HTTP status line. Send back
|
337
|
+
* a proper HTTP response, then exit this while
|
338
|
+
* loop and continue with forwarding the rest
|
339
|
+
* of the response data.
|
340
|
+
*/
|
341
|
+
UPDATE_TRACE_POINT();
|
342
|
+
string statusLine("HTTP/1.1 ");
|
343
|
+
statusLine.append(ex.getStatusLine());
|
344
|
+
UPDATE_TRACE_POINT();
|
345
|
+
output.writeRaw(statusLine.c_str(), statusLine.size());
|
346
|
+
UPDATE_TRACE_POINT();
|
347
|
+
output.writeRaw(ex.getBuffer().c_str(), ex.getBuffer().size());
|
348
|
+
break;
|
349
|
+
}
|
350
|
+
}
|
351
|
+
|
352
|
+
UPDATE_TRACE_POINT();
|
353
|
+
while (!eof) {
|
354
|
+
UPDATE_TRACE_POINT();
|
355
|
+
size = syscalls::read(stream, buf, sizeof(buf));
|
356
|
+
if (size == 0) {
|
357
|
+
eof = true;
|
358
|
+
} else if (size == -1) {
|
359
|
+
throw SystemException("Cannot read response from backend process", errno);
|
360
|
+
} else {
|
361
|
+
UPDATE_TRACE_POINT();
|
362
|
+
output.writeRaw(buf, size);
|
363
|
+
}
|
364
|
+
}
|
365
|
+
}
|
366
|
+
|
367
|
+
/**
|
368
|
+
* Handles a spawn related exception by writing an appropriate HTTP error response (500)
|
369
|
+
* for the given spawn exception <tt>e</ee> to given file descriptor <tt>fd</tt>'s message
|
370
|
+
* channel.
|
371
|
+
*
|
372
|
+
* @param fd The file descriptor identifying the message channel to write the given
|
373
|
+
* spawn exception <tt>e</tt> to.
|
374
|
+
* @param e The spawn exception to be written to the given <tt>fd</tt>'s message
|
375
|
+
* channel.
|
376
|
+
*/
|
377
|
+
void handleSpawnException(FileDescriptor &fd, const SpawnException &e) {
|
378
|
+
MessageChannel channel(fd);
|
379
|
+
channel.writeRaw("HTTP/1.1 500 Internal Server Error\x0D\x0A");
|
380
|
+
channel.writeRaw("Status: 500 Internal Server Error\x0D\x0A");
|
381
|
+
channel.writeRaw("Connection: close\x0D\x0A");
|
382
|
+
channel.writeRaw("Content-Type: text/html; charset=utf-8\x0D\x0A");
|
383
|
+
|
384
|
+
if (e.hasErrorPage()) {
|
385
|
+
channel.writeRaw("Content-Length: " +
|
386
|
+
toString(e.getErrorPage().size()) +
|
387
|
+
"\x0D\x0A");
|
388
|
+
channel.writeRaw("\x0D\x0A");
|
389
|
+
channel.writeRaw(e.getErrorPage());
|
390
|
+
} else {
|
391
|
+
channel.writeRaw("Content-Length: " +
|
392
|
+
toString(strlen(e.what())) + "\x0D\x0A");
|
393
|
+
channel.writeRaw("\x0D\x0A");
|
394
|
+
channel.writeRaw(e.what());
|
395
|
+
}
|
396
|
+
}
|
397
|
+
|
398
|
+
/**
|
399
|
+
* Handles an SCGI request from a client whose identity is derived by the given <tt>clientFd</tt>.
|
400
|
+
*
|
401
|
+
* @param clientFd The file descriptor identifying the client to handle the request from.
|
402
|
+
* @return True if an error occurred while trying to handle the request of the client. False if
|
403
|
+
* the request was succesfully processed.
|
404
|
+
*/
|
405
|
+
bool handleRequest(FileDescriptor &clientFd) {
|
406
|
+
TRACE_POINT();
|
407
|
+
ScgiRequestParser parser;
|
408
|
+
string partialRequestBody;
|
409
|
+
unsigned long contentLength;
|
410
|
+
|
411
|
+
if (!readAndCheckPassword(clientFd)) {
|
412
|
+
P_ERROR("Client did not send a correct password.");
|
413
|
+
return true;
|
414
|
+
}
|
415
|
+
if (!readAndParseRequestHeaders(clientFd, parser, partialRequestBody)) {
|
416
|
+
return true;
|
417
|
+
}
|
418
|
+
|
419
|
+
try {
|
420
|
+
PoolOptions options;
|
421
|
+
if (parser.getHeader("RAILS_RELATIVE_URL_ROOT").empty()) {
|
422
|
+
options.appRoot = extractDirName(parser.getHeader("DOCUMENT_ROOT"));
|
423
|
+
} else {
|
424
|
+
options.appRoot = extractDirName(resolveSymlink(parser.getHeader("DOCUMENT_ROOT")));
|
425
|
+
}
|
426
|
+
options.useGlobalQueue = parser.getHeader("PASSENGER_USE_GLOBAL_QUEUE") == "true";
|
427
|
+
options.environment = parser.getHeader("PASSENGER_ENVIRONMENT");
|
428
|
+
options.spawnMethod = parser.getHeader("PASSENGER_SPAWN_METHOD");
|
429
|
+
options.lowerPrivilege = lowerPrivilege;
|
430
|
+
options.lowestUser = lowestUser;
|
431
|
+
options.appType = parser.getHeader("PASSENGER_APP_TYPE");
|
432
|
+
options.frameworkSpawnerTimeout = atol(parser.getHeader("PASSENGER_FRAMEWORK_SPAWNER_IDLE_TIME"));
|
433
|
+
options.appSpawnerTimeout = atol(parser.getHeader("PASSENGER_APP_SPAWNER_IDLE_TIME"));
|
434
|
+
|
435
|
+
try {
|
436
|
+
Application::SessionPtr session(pool->get(options));
|
437
|
+
|
438
|
+
UPDATE_TRACE_POINT();
|
439
|
+
session->sendHeaders(parser.getHeaderData().c_str(),
|
440
|
+
parser.getHeaderData().size());
|
441
|
+
|
442
|
+
contentLength = atol(
|
443
|
+
parser.getHeader("CONTENT_LENGTH").c_str());
|
444
|
+
sendRequestBody(session,
|
445
|
+
clientFd,
|
446
|
+
partialRequestBody,
|
447
|
+
contentLength);
|
448
|
+
|
449
|
+
session->shutdownWriter();
|
450
|
+
forwardResponse(session, clientFd);
|
451
|
+
} catch (const SpawnException &e) {
|
452
|
+
handleSpawnException(clientFd, e);
|
453
|
+
}
|
454
|
+
return false;
|
455
|
+
} catch (const boost::thread_interrupted &) {
|
456
|
+
throw;
|
457
|
+
} catch (const tracable_exception &e) {
|
458
|
+
P_ERROR("Uncaught exception in PassengerServer client thread:\n"
|
459
|
+
<< " exception: " << e.what() << "\n"
|
460
|
+
<< " backtrace:\n" << e.backtrace());
|
461
|
+
return true;
|
462
|
+
} catch (const exception &e) {
|
463
|
+
P_ERROR("Uncaught exception in PassengerServer client thread:\n"
|
464
|
+
<< " exception: " << e.what() << "\n"
|
465
|
+
<< " backtrace: not available");
|
466
|
+
return true;
|
467
|
+
} catch (...) {
|
468
|
+
P_ERROR("Uncaught unknown exception in PassengerServer client thread.");
|
469
|
+
return true;
|
470
|
+
}
|
471
|
+
}
|
472
|
+
|
473
|
+
/**
|
474
|
+
* This client's main thread, responsible for accepting connections made by a client
|
475
|
+
* to the server and to handle its request.
|
476
|
+
*
|
477
|
+
* @see acceptConnection(void)
|
478
|
+
* @see handleRequest(FileDescriptor)
|
479
|
+
*/
|
480
|
+
void threadMain() {
|
481
|
+
TRACE_POINT();
|
482
|
+
try {
|
483
|
+
while (true) {
|
484
|
+
UPDATE_TRACE_POINT();
|
485
|
+
FileDescriptor fd(acceptConnection());
|
486
|
+
handleRequest(fd);
|
487
|
+
}
|
488
|
+
} catch (const boost::thread_interrupted &) {
|
489
|
+
P_TRACE(2, "Client thread " << this << " interrupted.");
|
490
|
+
} catch (const tracable_exception &e) {
|
491
|
+
P_ERROR("Uncaught exception in PassengerServer client thread:\n"
|
492
|
+
<< " exception: " << e.what() << "\n"
|
493
|
+
<< " backtrace:\n" << e.backtrace());
|
494
|
+
abort();
|
495
|
+
} catch (const exception &e) {
|
496
|
+
P_ERROR("Uncaught exception in PassengerServer client thread:\n"
|
497
|
+
<< " exception: " << e.what() << "\n"
|
498
|
+
<< " backtrace: not available");
|
499
|
+
abort();
|
500
|
+
} catch (...) {
|
501
|
+
P_ERROR("Uncaught unknown exception in PassengerServer client thread.");
|
502
|
+
throw;
|
503
|
+
}
|
504
|
+
}
|
505
|
+
|
506
|
+
public:
|
507
|
+
/**
|
508
|
+
* Constructs a client handler for the server with the given arguments and runs
|
509
|
+
* it in its own thread.
|
510
|
+
*
|
511
|
+
* @param number The id assigned by the server to identify this client by.
|
512
|
+
* @param pool The application pool where this client belongs to.
|
513
|
+
* @param password The password that is required to connect to this client handler.
|
514
|
+
* This value is determined and assigned by the server.
|
515
|
+
* @param lowerPrivilege Whether privilege lowering should be used.
|
516
|
+
* @param lowestUser The user that spawned processes should run as, if
|
517
|
+
* initial attempt at privilege lowering failed.
|
518
|
+
* @param serverSocket The server socket to accept this clients connection from.
|
519
|
+
*/
|
520
|
+
Client(unsigned int number, StandardApplicationPoolPtr &pool,
|
521
|
+
const string &password, bool lowerPrivilege,
|
522
|
+
const string &lowestUser, int serverSocket) {
|
523
|
+
this->number = number;
|
524
|
+
this->pool = pool;
|
525
|
+
this->password = password;
|
526
|
+
this->lowerPrivilege = lowerPrivilege;
|
527
|
+
this->lowestUser = lowestUser;
|
528
|
+
this->serverSocket = serverSocket;
|
529
|
+
thr = new oxt::thread(
|
530
|
+
bind(&Client::threadMain, this),
|
531
|
+
"Client thread " + toString(number),
|
532
|
+
CLIENT_THREAD_STACK_SIZE
|
533
|
+
);
|
534
|
+
}
|
535
|
+
|
536
|
+
/**
|
537
|
+
* Destroys this client and its thread.
|
538
|
+
*/
|
539
|
+
~Client() {
|
540
|
+
TRACE_POINT();
|
541
|
+
this_thread::disable_syscall_interruption dsi;
|
542
|
+
this_thread::disable_interruption di;
|
543
|
+
|
544
|
+
thr->interrupt_and_join();
|
545
|
+
delete thr;
|
546
|
+
}
|
547
|
+
};
|
548
|
+
|
549
|
+
typedef shared_ptr<Client> ClientPtr;
|
550
|
+
|
551
|
+
/**
|
552
|
+
* A representation of the Server responsible for handling Client instances.
|
553
|
+
*
|
554
|
+
* @see Client
|
555
|
+
*/
|
556
|
+
class Server {
|
557
|
+
private:
|
558
|
+
static const unsigned int BACKLOG_SIZE = 50;
|
559
|
+
|
560
|
+
string password;
|
561
|
+
int adminPipe;
|
562
|
+
int serverSocket;
|
563
|
+
bool userSwitching;
|
564
|
+
string defaultUser;
|
565
|
+
unsigned int numberOfThreads;
|
566
|
+
set<ClientPtr> clients;
|
567
|
+
StandardApplicationPoolPtr pool;
|
568
|
+
shared_ptr<ApplicationPoolStatusReporter> reporter;
|
569
|
+
|
570
|
+
/**
|
571
|
+
* Starts listening for client connections from this server's <tt>serverSocket</tt>.
|
572
|
+
* This server will first attempt to create an unconnected Unix socket on which it will
|
573
|
+
* attempt to bind on. Once it is bound, it will start listening for incoming client
|
574
|
+
* activity.
|
575
|
+
*
|
576
|
+
* @throws SystemException Could not create unconnected Unix socket or bind on Unix socket.
|
577
|
+
*/
|
578
|
+
void startListening() {
|
579
|
+
this_thread::disable_syscall_interruption dsi;
|
580
|
+
string socketName = getPassengerTempDir() + "/master/helper_server.sock";
|
581
|
+
struct sockaddr_un addr;
|
582
|
+
int ret;
|
583
|
+
|
584
|
+
serverSocket = syscalls::socket(PF_UNIX, SOCK_STREAM, 0);
|
585
|
+
if (serverSocket == -1) {
|
586
|
+
throw SystemException("Cannot create an unconnected Unix socket", errno);
|
587
|
+
}
|
588
|
+
|
589
|
+
addr.sun_family = AF_UNIX;
|
590
|
+
strncpy(addr.sun_path, socketName.c_str(), sizeof(addr.sun_path));
|
591
|
+
addr.sun_path[sizeof(addr.sun_path) - 1] = '\0';
|
592
|
+
|
593
|
+
ret = syscalls::bind(serverSocket, (const struct sockaddr *) &addr, sizeof(addr));
|
594
|
+
if (ret == -1) {
|
595
|
+
int e = errno;
|
596
|
+
syscalls::close(serverSocket);
|
597
|
+
|
598
|
+
string message("Cannot bind on Unix socket '");
|
599
|
+
message.append(socketName);
|
600
|
+
message.append("'");
|
601
|
+
throw SystemException(message, e);
|
602
|
+
}
|
603
|
+
|
604
|
+
ret = syscalls::listen(serverSocket, BACKLOG_SIZE);
|
605
|
+
if (ret == -1) {
|
606
|
+
int e = errno;
|
607
|
+
syscalls::close(serverSocket);
|
608
|
+
|
609
|
+
string message("Cannot bind on Unix socket '");
|
610
|
+
message.append(socketName);
|
611
|
+
message.append("'");
|
612
|
+
throw SystemException(message, e);
|
613
|
+
}
|
614
|
+
|
615
|
+
do {
|
616
|
+
ret = chmod(socketName.c_str(), S_ISVTX |
|
617
|
+
S_IRUSR | S_IWUSR | S_IXUSR |
|
618
|
+
S_IRGRP | S_IWGRP | S_IXGRP |
|
619
|
+
S_IROTH | S_IWOTH | S_IXOTH);
|
620
|
+
} while (ret == -1 && errno == EINTR);
|
621
|
+
}
|
622
|
+
|
623
|
+
/**
|
624
|
+
* Starts the client handler threads that are responsible for handling the communication
|
625
|
+
* between the client and this Server.
|
626
|
+
*
|
627
|
+
* @see Client
|
628
|
+
*/
|
629
|
+
void startClientHandlerThreads() {
|
630
|
+
for (unsigned int i = 0; i < numberOfThreads; i++) {
|
631
|
+
ClientPtr client(new Client(i + 1, pool, password,
|
632
|
+
userSwitching, defaultUser, serverSocket));
|
633
|
+
clients.insert(client);
|
634
|
+
}
|
635
|
+
}
|
636
|
+
|
637
|
+
/**
|
638
|
+
* Lowers this process's privilege to that of <em>username</em>.
|
639
|
+
*/
|
640
|
+
void lowerPrivilege(const string &username) {
|
641
|
+
struct passwd *entry;
|
642
|
+
|
643
|
+
entry = getpwnam(username.c_str());
|
644
|
+
if (entry != NULL) {
|
645
|
+
if (initgroups(username.c_str(), entry->pw_gid) != 0) {
|
646
|
+
int e = errno;
|
647
|
+
P_WARN("WARNING: Unable to lower Passenger HelperServer's "
|
648
|
+
"privilege to that of user '" << username <<
|
649
|
+
"': cannot set supplementary groups for this "
|
650
|
+
"user: " << strerror(e) << " (" << e << ")");
|
651
|
+
}
|
652
|
+
if (setgid(entry->pw_gid) != 0) {
|
653
|
+
int e = errno;
|
654
|
+
P_WARN("WARNING: Unable to lower Passenger HelperServer's "
|
655
|
+
"privilege to that of user '" << username <<
|
656
|
+
"': cannot set group ID: " << strerror(e) <<
|
657
|
+
" (" << e << ")");
|
658
|
+
}
|
659
|
+
if (setuid(entry->pw_uid) != 0) {
|
660
|
+
int e = errno;
|
661
|
+
P_WARN("WARNING: Unable to lower Passenger HelperServer's "
|
662
|
+
"privilege to that of user '" << username <<
|
663
|
+
"': cannot set user ID: " << strerror(e) <<
|
664
|
+
" (" << e << ")");
|
665
|
+
}
|
666
|
+
} else {
|
667
|
+
P_WARN("WARNING: Unable to lower Passenger HelperServer's "
|
668
|
+
"privilege to that of user '" << username <<
|
669
|
+
"': user does not exist.");
|
670
|
+
}
|
671
|
+
}
|
672
|
+
|
673
|
+
public:
|
674
|
+
/**
|
675
|
+
* Creates a server instance based on the given parameters, which starts to listen
|
676
|
+
* for clients.
|
677
|
+
*
|
678
|
+
* @param password The password this server uses for its clients.
|
679
|
+
* @param rootDir The Passenger root folder.
|
680
|
+
* @param ruby The filename of the Ruby interpreter to use.
|
681
|
+
* @param adminPipe The pipe that is used to receive this Server's password and to see if Nginx
|
682
|
+
* has exited.
|
683
|
+
* @param feedbackPipe The feedback pipe, used for telling the web server that we're done
|
684
|
+
* initializing.
|
685
|
+
* @param maxPoolSize The maximum number of simultaneously alive application instances.
|
686
|
+
* @param maxInstancesPerApp The maximum number of simultaneously alive Rails instances that
|
687
|
+
* a single Rails application may occupy.
|
688
|
+
* @param poolIdleTime The maximum number of seconds that an application may be idle before
|
689
|
+
* it gets terminated.
|
690
|
+
* @param userSwitching Whether user switching should be used.
|
691
|
+
* @param defaultUser If user switching is turned on, then this is the
|
692
|
+
* username that a process should lower its privilege to if the
|
693
|
+
* initial attempt at user switching fails. If user switching is off,
|
694
|
+
* then this is the username that HelperServer and all spawned
|
695
|
+
* processes should run as.
|
696
|
+
* @param workerUid The UID of the web server's worker processes. Used for determining
|
697
|
+
* the optimal permissions for some temp files.
|
698
|
+
* @param workerGid The GID of the web server's worker processes. Used for determining
|
699
|
+
* the optimal permissions for some temp files.
|
700
|
+
*/
|
701
|
+
Server(const string &password, const string &rootDir, const string &ruby,
|
702
|
+
int adminPipe, int feedbackPipe, unsigned int maxPoolSize,
|
703
|
+
unsigned int maxInstancesPerApp, unsigned int poolIdleTime,
|
704
|
+
bool userSwitching, const string &defaultUser, uid_t workerUid,
|
705
|
+
gid_t workerGid) {
|
706
|
+
this->password = password;
|
707
|
+
this->adminPipe = adminPipe;
|
708
|
+
this->userSwitching = userSwitching;
|
709
|
+
this->defaultUser = defaultUser;
|
710
|
+
numberOfThreads = maxPoolSize * 4;
|
711
|
+
|
712
|
+
removeDirTree(getPassengerTempDir());
|
713
|
+
createPassengerTempDir(getSystemTempDir(), userSwitching, defaultUser,
|
714
|
+
workerUid, workerGid);
|
715
|
+
startListening();
|
716
|
+
|
717
|
+
if (!userSwitching && geteuid() == 0) {
|
718
|
+
lowerPrivilege(defaultUser);
|
719
|
+
}
|
720
|
+
|
721
|
+
pool = ptr(new StandardApplicationPool(
|
722
|
+
rootDir + "/bin/passenger-spawn-server",
|
723
|
+
"", ruby
|
724
|
+
));
|
725
|
+
pool->setMax(maxPoolSize);
|
726
|
+
pool->setMaxPerApp(maxInstancesPerApp);
|
727
|
+
pool->setMaxIdleTime(poolIdleTime);
|
728
|
+
|
729
|
+
reporter = ptr(new ApplicationPoolStatusReporter(pool, userSwitching,
|
730
|
+
S_IRUSR | S_IWUSR));
|
731
|
+
|
732
|
+
// Tell the web server that we're done initializing.
|
733
|
+
syscalls::close(feedbackPipe);
|
734
|
+
}
|
735
|
+
|
736
|
+
~Server() {
|
737
|
+
TRACE_POINT();
|
738
|
+
this_thread::disable_syscall_interruption dsi;
|
739
|
+
this_thread::disable_interruption di;
|
740
|
+
|
741
|
+
P_DEBUG("Shutting down helper server...");
|
742
|
+
clients.clear();
|
743
|
+
P_TRACE(2, "All threads have been shut down.");
|
744
|
+
syscalls::close(serverSocket);
|
745
|
+
syscalls::close(adminPipe);
|
746
|
+
}
|
747
|
+
|
748
|
+
/**
|
749
|
+
* Starts this server by starting the client handlers threads.
|
750
|
+
*
|
751
|
+
* @see startCientHandlerThreads
|
752
|
+
*/
|
753
|
+
void start() {
|
754
|
+
TRACE_POINT();
|
755
|
+
char buf;
|
756
|
+
|
757
|
+
startClientHandlerThreads();
|
758
|
+
|
759
|
+
try {
|
760
|
+
// Wait until the web server has exited.
|
761
|
+
syscalls::read(adminPipe, &buf, 1);
|
762
|
+
} catch (const boost::thread_interrupted &) {
|
763
|
+
// Do nothing.
|
764
|
+
}
|
765
|
+
}
|
766
|
+
};
|
767
|
+
|
768
|
+
/**
|
769
|
+
* Ignores the SIGPIPE signal that in general is raised when a computer program attempts
|
770
|
+
* to write to a pipe without a processes connected to the other end. This is used to
|
771
|
+
* prevent Nginx from getting killed by the default signal handler when it attempts to
|
772
|
+
* write the server password to the HelperServer in the situation that the HelperServer
|
773
|
+
* failed to start.
|
774
|
+
*/
|
775
|
+
static void
|
776
|
+
ignoreSigpipe() {
|
777
|
+
struct sigaction action;
|
778
|
+
action.sa_handler = SIG_IGN;
|
779
|
+
action.sa_flags = 0;
|
780
|
+
sigemptyset(&action.sa_mask);
|
781
|
+
sigaction(SIGPIPE, &action, NULL);
|
782
|
+
}
|
783
|
+
|
784
|
+
/**
|
785
|
+
* Extracts and returns the password from the given <tt>adminPipe</tt>. This password is
|
786
|
+
* used to determine which processes may connect with this server's Unix socket, as unix
|
787
|
+
* sockets would normally allow any process to connect to it. In this case, we strictly
|
788
|
+
* want Nginx to be able to connect to it, and it is for this reason that we maintain a
|
789
|
+
* password system.
|
790
|
+
*
|
791
|
+
* @param adminPipe The pipe used to read the password for this server from.
|
792
|
+
* @return The password for this server.
|
793
|
+
*/
|
794
|
+
static string
|
795
|
+
receivePassword(int adminPipe) {
|
796
|
+
TRACE_POINT();
|
797
|
+
MessageChannel channel(adminPipe);
|
798
|
+
char buf[HELPER_SERVER_PASSWORD_SIZE];
|
799
|
+
|
800
|
+
if (!channel.readRaw(buf, HELPER_SERVER_PASSWORD_SIZE)) {
|
801
|
+
throw IOException("Could not read password from the admin pipe.");
|
802
|
+
}
|
803
|
+
return string(buf, HELPER_SERVER_PASSWORD_SIZE);
|
804
|
+
}
|
805
|
+
|
806
|
+
/**
|
807
|
+
* Initializes and starts the helper server that is responsible for handling communication
|
808
|
+
* between Nginx and the backend Rails processes.
|
809
|
+
*
|
810
|
+
* @see Server
|
811
|
+
* @see Client
|
812
|
+
*/
|
813
|
+
int
|
814
|
+
main(int argc, char *argv[]) {
|
815
|
+
TRACE_POINT();
|
816
|
+
try {
|
817
|
+
setup_syscall_interruption_support();
|
818
|
+
ignoreSigpipe();
|
819
|
+
|
820
|
+
string password;
|
821
|
+
string rootDir = argv[1];
|
822
|
+
string ruby = argv[2];
|
823
|
+
int adminPipe = atoi(argv[3]);
|
824
|
+
int feedbackPipe = atoi(argv[4]);
|
825
|
+
int logLevel = atoi(argv[5]);
|
826
|
+
int maxPoolSize = atoi(argv[6]);
|
827
|
+
int maxInstancesPerApp = atoi(argv[7]);
|
828
|
+
int poolIdleTime = atoi(argv[8]);
|
829
|
+
bool userSwitching = strcmp(argv[9], "1") == 0;
|
830
|
+
string defaultUser = argv[10];
|
831
|
+
uid_t workerUid = (uid_t) atoll(argv[11]);
|
832
|
+
gid_t workerGid = (gid_t) atoll(argv[12]);
|
833
|
+
|
834
|
+
setLogLevel(logLevel);
|
835
|
+
P_DEBUG("Passenger helper server started on PID " << getpid());
|
836
|
+
|
837
|
+
password = receivePassword(adminPipe);
|
838
|
+
P_TRACE(2, "Password received.");
|
839
|
+
|
840
|
+
Server(password, rootDir, ruby, adminPipe, feedbackPipe, maxPoolSize,
|
841
|
+
maxInstancesPerApp, poolIdleTime, userSwitching,
|
842
|
+
defaultUser, workerUid, workerGid).start();
|
843
|
+
} catch (const tracable_exception &e) {
|
844
|
+
P_ERROR(e.what() << "\n" << e.backtrace());
|
845
|
+
return 1;
|
846
|
+
} catch (const exception &e) {
|
847
|
+
P_ERROR(e.what());
|
848
|
+
return 1;
|
849
|
+
} catch (...) {
|
850
|
+
P_ERROR("Unknown exception thrown in main thread.");
|
851
|
+
throw;
|
852
|
+
}
|
853
|
+
|
854
|
+
P_TRACE(2, "Helper server exited.");
|
855
|
+
return 0;
|
856
|
+
}
|
857
|
+
|