passenger 5.0.21 → 5.0.22

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 (203) hide show
  1. checksums.yaml +8 -8
  2. checksums.yaml.gz.asc +7 -7
  3. data.tar.gz.asc +7 -7
  4. data/CHANGELOG +38 -2
  5. data/CONTRIBUTORS +3 -0
  6. data/README.md +5 -1
  7. data/bin/passenger-status +2 -7
  8. data/build/agent.rb +2 -0
  9. data/build/cxx_dependency_map.rb +1464 -162
  10. data/build/node_tests.rb +1 -1
  11. data/build/packaging.rb +1 -1
  12. data/dev/ci/run_travis.sh +1 -1
  13. data/dev/vagrant/provision.sh +1 -1
  14. data/npm-shrinkwrap.json +635 -125
  15. data/package.json +1 -1
  16. data/resources/templates/standalone/config.erb +33 -161
  17. data/resources/templates/standalone/global.erb +15 -0
  18. data/resources/templates/standalone/http.erb +40 -0
  19. data/resources/templates/standalone/mass_deployment_default_server.erb +11 -0
  20. data/resources/templates/standalone/rails_asset_pipeline.erb +22 -0
  21. data/resources/templates/standalone/server.erb +58 -0
  22. data/src/agent/Core/ApiServer.h +37 -32
  23. data/src/agent/Core/ApplicationPool/BasicGroupInfo.h +1 -1
  24. data/src/agent/Core/ApplicationPool/BasicProcessInfo.h +6 -0
  25. data/src/agent/Core/ApplicationPool/Common.h +1 -1
  26. data/src/agent/Core/ApplicationPool/Group/OutOfBandWork.cpp +1 -1
  27. data/src/agent/Core/ApplicationPool/Group/ProcessListManagement.cpp +4 -0
  28. data/src/agent/Core/ApplicationPool/Implementation.cpp +2 -2
  29. data/src/agent/Core/ApplicationPool/Options.h +18 -1
  30. data/src/agent/Core/ApplicationPool/Pool.h +1 -1
  31. data/src/agent/Core/ApplicationPool/Pool/AnalyticsCollection.cpp +6 -6
  32. data/src/agent/Core/ApplicationPool/Pool/GeneralUtils.cpp +3 -3
  33. data/src/agent/Core/ApplicationPool/Pool/InitializationAndShutdown.cpp +1 -1
  34. data/src/agent/Core/ApplicationPool/Pool/Miscellaneous.cpp +6 -0
  35. data/src/agent/Core/ApplicationPool/Process.h +6 -1
  36. data/src/agent/Core/ApplicationPool/Socket.h +9 -12
  37. data/src/agent/Core/Controller.h +422 -0
  38. data/src/agent/Core/{RequestHandler → Controller}/AppResponse.h +2 -0
  39. data/src/agent/Core/{RequestHandler → Controller}/BufferBody.cpp +27 -5
  40. data/src/agent/Core/{RequestHandler → Controller}/CheckoutSession.cpp +61 -31
  41. data/src/agent/Core/{RequestHandler → Controller}/Client.h +5 -2
  42. data/src/agent/Core/{RequestHandler → Controller}/ForwardResponse.cpp +93 -42
  43. data/src/agent/Core/{RequestHandler → Controller}/Hooks.cpp +107 -60
  44. data/src/agent/Core/Controller/Implementation.cpp +38 -0
  45. data/src/agent/Core/{RequestHandler → Controller}/InitRequest.cpp +134 -80
  46. data/src/agent/Core/Controller/InitializationAndShutdown.cpp +165 -0
  47. data/src/agent/Core/{RequestHandler/Utils.cpp → Controller/InternalUtils.cpp} +49 -32
  48. data/src/agent/Core/Controller/Miscellaneous.cpp +116 -0
  49. data/src/agent/Core/{RequestHandler → Controller}/Request.h +6 -4
  50. data/src/agent/Core/{RequestHandler → Controller}/SendRequest.cpp +205 -130
  51. data/src/agent/Core/Controller/StateInspectionAndConfiguration.cpp +161 -0
  52. data/src/agent/Core/{RequestHandler → Controller}/TurboCaching.h +3 -0
  53. data/src/agent/Core/CoreMain.cpp +62 -51
  54. data/src/agent/Core/OptionParser.h +24 -0
  55. data/src/agent/Core/ResponseCache.h +5 -5
  56. data/src/agent/Core/SpawningKit/Config.h +2 -2
  57. data/src/agent/Core/SpawningKit/SmartSpawner.h +1 -1
  58. data/src/agent/Core/UnionStation/{Core.h → Context.h} +14 -18
  59. data/src/agent/Core/UnionStation/StopwatchLog.h +3 -2
  60. data/src/agent/Core/UnionStation/Transaction.h +7 -7
  61. data/src/agent/Shared/ApiServerUtils.h +9 -1
  62. data/src/agent/UstRouter/ApiServer.h +5 -2
  63. data/src/agent/UstRouter/Controller.h +27 -9
  64. data/src/agent/UstRouter/UstRouterMain.cpp +1 -0
  65. data/src/agent/Watchdog/ApiServer.h +5 -2
  66. data/src/apache2_module/ConfigurationCommands.cpp +7 -0
  67. data/src/apache2_module/ConfigurationFields.hpp +2 -0
  68. data/src/apache2_module/ConfigurationSetters.cpp +24 -0
  69. data/src/apache2_module/CreateDirConfig.cpp +1 -0
  70. data/src/apache2_module/Hooks.cpp +6 -5
  71. data/src/apache2_module/MergeDirConfig.cpp +7 -0
  72. data/src/apache2_module/SetHeaders.cpp +5 -0
  73. data/src/cxx_supportlib/Constants.h +5 -3
  74. data/src/cxx_supportlib/SafeLibev.h +2 -1
  75. data/src/cxx_supportlib/UnionStationFilterSupport.h +2 -1
  76. data/src/cxx_supportlib/Utils/ReleaseableScopedPointer.h +70 -0
  77. data/src/cxx_supportlib/vendor-modified/boost/libs/regex/src/regex_raw_buffer.cpp +6 -6
  78. data/src/helper-scripts/node-loader.js +59 -0
  79. data/src/nginx_module/CacheLocationConfig.c +48 -0
  80. data/src/nginx_module/ConfigurationCommands.c +20 -0
  81. data/src/nginx_module/ConfigurationFields.h +4 -0
  82. data/src/nginx_module/CreateLocationConfig.c +8 -0
  83. data/src/nginx_module/MergeLocationConfig.c +12 -0
  84. data/src/nodejs_supportlib/phusion_passenger/log_express.js +106 -0
  85. data/src/nodejs_supportlib/phusion_passenger/log_mongodb.js +203 -0
  86. data/src/nodejs_supportlib/phusion_passenger/ustreporter.js +227 -0
  87. data/src/nodejs_supportlib/phusion_passenger/ustrouter_connector.js +446 -0
  88. data/src/nodejs_supportlib/vendor-copy/codify/codify.js +44 -0
  89. data/src/nodejs_supportlib/vendor-copy/codify/package.json +29 -0
  90. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/context.js +200 -0
  91. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/glue.js +488 -0
  92. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/index.js +407 -0
  93. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/node_modules/shimmer/index.js +90 -0
  94. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/node_modules/shimmer/package.json +40 -0
  95. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/package.json +54 -0
  96. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/emitter-listener/listener.js +160 -0
  97. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/emitter-listener/node_modules/shimmer/index.js +90 -0
  98. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/emitter-listener/node_modules/shimmer/package.json +40 -0
  99. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/emitter-listener/package.json +46 -0
  100. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/package.json +56 -0
  101. data/src/nodejs_supportlib/vendor-copy/network-byte-order/lib/index.js +102 -0
  102. data/src/nodejs_supportlib/vendor-copy/network-byte-order/package.json +51 -0
  103. data/src/nodejs_supportlib/vendor-copy/winston/LICENSE +19 -0
  104. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston.js +165 -0
  105. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/common.js +483 -0
  106. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/config.js +62 -0
  107. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/config/cli-config.js +35 -0
  108. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/config/npm-config.js +27 -0
  109. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/config/syslog-config.js +31 -0
  110. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/container.js +127 -0
  111. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/exception.js +56 -0
  112. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/logger.js +701 -0
  113. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports.js +34 -0
  114. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/console.js +128 -0
  115. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/daily-rotate-file.js +601 -0
  116. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/file.js +675 -0
  117. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/http.js +232 -0
  118. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/memory.js +89 -0
  119. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/transport.js +135 -0
  120. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/webhook.js +146 -0
  121. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/async/LICENSE +19 -0
  122. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/async/lib/async.js +1283 -0
  123. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/async/package.json +66 -0
  124. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/async/support/sync-package-managers.js +53 -0
  125. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/MIT-LICENSE.txt +23 -0
  126. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/colors.js +176 -0
  127. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/custom/trap.js +45 -0
  128. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/custom/zalgo.js +104 -0
  129. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/extendStringPrototype.js +118 -0
  130. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/index.js +12 -0
  131. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/maps/america.js +12 -0
  132. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/maps/rainbow.js +13 -0
  133. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/maps/random.js +8 -0
  134. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/maps/zebra.js +5 -0
  135. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/styles.js +77 -0
  136. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/system/supports-colors.js +61 -0
  137. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/package.json +35 -0
  138. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/safe.js +9 -0
  139. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/themes/generic-logging.js +12 -0
  140. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/cycle/cycle.js +170 -0
  141. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/cycle/package.json +30 -0
  142. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/eyes/LICENSE +20 -0
  143. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/eyes/lib/eyes.js +236 -0
  144. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/eyes/package.json +42 -0
  145. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/isstream/LICENSE.md +11 -0
  146. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/isstream/isstream.js +27 -0
  147. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/isstream/package.json +42 -0
  148. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/pkginfo/LICENSE +19 -0
  149. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/pkginfo/lib/pkginfo.js +136 -0
  150. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/pkginfo/package.json +56 -0
  151. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/stack-trace/License +19 -0
  152. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/stack-trace/lib/stack-trace.js +111 -0
  153. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/stack-trace/package.json +33 -0
  154. data/src/nodejs_supportlib/vendor-copy/winston/package.json +87 -0
  155. data/src/ruby_supportlib/phusion_passenger.rb +3 -4
  156. data/src/ruby_supportlib/phusion_passenger/admin_tools/instance.rb +19 -2
  157. data/src/ruby_supportlib/phusion_passenger/apache2/config_options.rb +8 -0
  158. data/src/ruby_supportlib/phusion_passenger/config/list_instances_command.rb +2 -6
  159. data/src/ruby_supportlib/phusion_passenger/config/reopen_logs_command.rb +13 -0
  160. data/src/ruby_supportlib/phusion_passenger/config/restart_app_command.rb +3 -0
  161. data/src/ruby_supportlib/phusion_passenger/config/utils.rb +9 -7
  162. data/src/ruby_supportlib/phusion_passenger/config/validate_install_command.rb +8 -1
  163. data/src/ruby_supportlib/phusion_passenger/constants.rb +3 -1
  164. data/src/ruby_supportlib/phusion_passenger/native_support.rb +20 -4
  165. data/src/ruby_supportlib/phusion_passenger/nginx/config_options.rb +8 -0
  166. data/src/ruby_supportlib/phusion_passenger/packaging.rb +1 -0
  167. data/src/ruby_supportlib/phusion_passenger/platform_info/apache_detector.rb +1 -1
  168. data/src/ruby_supportlib/phusion_passenger/platform_info/operating_system.rb +11 -4
  169. data/src/ruby_supportlib/phusion_passenger/rack/thread_handler_extension.rb +1 -1
  170. data/src/ruby_supportlib/phusion_passenger/standalone/config_options_list.rb +647 -0
  171. data/src/ruby_supportlib/phusion_passenger/standalone/config_utils.rb +229 -15
  172. data/src/ruby_supportlib/phusion_passenger/standalone/start_command.rb +35 -323
  173. data/src/ruby_supportlib/phusion_passenger/standalone/start_command/builtin_engine.rb +36 -12
  174. data/src/ruby_supportlib/phusion_passenger/standalone/start_command/nginx_engine.rb +123 -14
  175. data/src/ruby_supportlib/phusion_passenger/standalone/status_command.rb +32 -17
  176. data/src/ruby_supportlib/phusion_passenger/standalone/stop_command.rb +32 -21
  177. data/src/ruby_supportlib/phusion_passenger/standalone/version_command.rb +5 -5
  178. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/README.md +2 -2
  179. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/Rakefile +5 -1
  180. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core.rb +68 -24
  181. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/api.rb +9 -1
  182. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/context.rb +9 -7
  183. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/request_reporter.rb +3 -2
  184. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/request_reporter/basics.rb +8 -5
  185. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/simple_json.rb +395 -0
  186. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/transaction.rb +10 -7
  187. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/utils.rb +14 -0
  188. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/version_data.rb +2 -2
  189. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml +4 -2
  190. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.example +2 -2
  191. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.travis +2 -2
  192. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.travis-with-sudo +16 -0
  193. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/Gemfile +1 -1
  194. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/Gemfile.lock +2 -2
  195. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/README.md +1 -1
  196. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails.rb +44 -17
  197. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/active_support_cache_subscriber.rb +16 -7
  198. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/version_data.rb +2 -2
  199. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/union_station_hooks_rails.gemspec +1 -1
  200. metadata +99 -16
  201. metadata.gz.asc +7 -7
  202. data/resources/oss-binaries.phusionpassenger.com.crt +0 -248
  203. data/src/agent/Core/RequestHandler.h +0 -471
@@ -26,7 +26,8 @@
26
26
  require 'etc'
27
27
  PhusionPassenger.require_passenger_lib 'constants'
28
28
  PhusionPassenger.require_passenger_lib 'standalone/control_utils'
29
- PhusionPassenger.require_passenger_lib 'utils'
29
+ PhusionPassenger.require_passenger_lib 'platform_info'
30
+ PhusionPassenger.require_passenger_lib 'platform_info/operating_system'
30
31
  PhusionPassenger.require_passenger_lib 'utils/shellwords'
31
32
  PhusionPassenger.require_passenger_lib 'utils/json'
32
33
 
@@ -43,9 +44,17 @@ module PhusionPassenger
43
44
  end
44
45
 
45
46
  def wait_until_engine_has_exited
46
- lock = DaemonController::LockFile.new(read_watchdog_lock_file_path!)
47
- lock.shared_lock do
48
- # Do nothing
47
+ read_and_delete_report_file!
48
+ if PlatformInfo.supports_flock?
49
+ lock = DaemonController::LockFile.new(@watchdog_lock_file_path)
50
+ lock.shared_lock do
51
+ # Do nothing
52
+ end
53
+ else
54
+ pid = @engine.pid
55
+ while process_is_alive?(pid)
56
+ sleep 1
57
+ end
49
58
  end
50
59
  end
51
60
 
@@ -136,14 +145,20 @@ module PhusionPassenger
136
145
  if @options[:turbocaching] == false
137
146
  command << " --disable-turbocaching"
138
147
  end
148
+ if @options[:abort_websockets_on_process_shutdown] == false
149
+ command << " --no-abort-websockets-on-process-shutdown"
150
+ end
151
+ add_param(command, :force_max_concurrent_requests_per_process, "--force-max-concurrent-requests-per-process")
139
152
  add_flag_param(command, :load_shell_envvars, "--load-shell-envvars")
140
153
  add_param(command, :max_pool_size, "--max-pool-size")
141
154
  add_param(command, :min_instances, "--min-instances")
142
155
  add_param(command, :pool_idle_time, "--pool-idle-time")
143
156
  add_param(command, :max_preloader_idle_time, "--max-preloader-idle-time")
157
+ add_param(command, :max_request_queue_size, "--max-request-queue-size")
144
158
  add_enterprise_param(command, :concurrency_model, "--concurrency-model")
145
159
  add_enterprise_param(command, :thread_count, "--app-thread-count")
146
160
  add_enterprise_param(command, :max_request_time, "--max-request-time")
161
+ add_enterprise_param(command, :memory_limit, "--memory-limit")
147
162
  add_enterprise_flag_param(command, :rolling_restarts, "--rolling-restarts")
148
163
  add_enterprise_flag_param(command, :resist_deployment_errors, "--resist-deployment-errors")
149
164
  add_enterprise_flag_param(command, :debugger, "--debugger")
@@ -216,14 +231,23 @@ module PhusionPassenger
216
231
  @report_file_path ||= "#{@working_dir}/report.json"
217
232
  end
218
233
 
219
- def read_watchdog_lock_file_path!
220
- @watchdog_lock_file_path ||= begin
221
- report = File.open(report_file_path, "r:utf-8") do |f|
222
- Utils::JSON.parse(f.read)
223
- end
224
- # The report file may contain sensitive information, so delete it.
225
- File.unlink(report_file_path)
226
- report["instance_dir"] + "/lock"
234
+ def read_and_delete_report_file!
235
+ report = File.open(report_file_path, "r:utf-8") do |f|
236
+ Utils::JSON.parse(f.read)
237
+ end
238
+ # The report file may contain sensitive information, so delete it.
239
+ File.unlink(report_file_path)
240
+ @watchdog_lock_file_path = report["instance_dir"] + "/lock"
241
+ end
242
+
243
+ def process_is_alive?(pid)
244
+ begin
245
+ Process.kill(0, pid)
246
+ true
247
+ rescue Errno::ESRCH
248
+ false
249
+ rescue SystemCallError => e
250
+ true
227
251
  end
228
252
  end
229
253
 
@@ -25,6 +25,7 @@
25
25
  require 'erb'
26
26
  require 'etc'
27
27
  PhusionPassenger.require_passenger_lib 'constants'
28
+ PhusionPassenger.require_passenger_lib 'platform_info'
28
29
  PhusionPassenger.require_passenger_lib 'platform_info/ruby'
29
30
  PhusionPassenger.require_passenger_lib 'standalone/control_utils'
30
31
  PhusionPassenger.require_passenger_lib 'utils/tmpio'
@@ -37,9 +38,12 @@ module PhusionPassenger
37
38
  module NginxEngine
38
39
  private
39
40
  def start_engine_real
41
+ write_nginx_config_file(nginx_config_path)
42
+ maybe_debug_nginx_config
43
+ test_nginx_config
44
+
40
45
  Standalone::ControlUtils.require_daemon_controller
41
46
  @engine = DaemonController.new(build_daemon_controller_options)
42
- write_nginx_config_file(nginx_config_path)
43
47
 
44
48
  begin
45
49
  @engine.start
@@ -84,10 +88,60 @@ module PhusionPassenger
84
88
  end
85
89
  end
86
90
  end
87
- rescue Errno::ECONNREFUSED, Errno::ECONNRESET
91
+ rescue Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ENOENT
88
92
  end
89
93
 
90
94
 
95
+ def maybe_debug_nginx_config
96
+ if @options[:debug_nginx_config]
97
+ File.open(nginx_config_path, 'rb') do |f|
98
+ puts(f.read)
99
+ end
100
+ exit
101
+ end
102
+ end
103
+
104
+ def test_nginx_config
105
+ command = "#{Shellwords.escape @nginx_binary}" \
106
+ " -c #{Shellwords.escape nginx_config_path}" \
107
+ " -p #{Shellwords.escape @working_dir}" \
108
+ " -t"
109
+ output = `#{command} 2>&1`
110
+ if $? && $?.exitstatus != 0
111
+ output.gsub!(nginx_config_path, 'nginx.conf')
112
+ output = PlatformInfo.send(:reindent, output, 4)
113
+
114
+ message = "*** ERROR: the Nginx configuration that #{PROGRAM_NAME}" \
115
+ " Standalone generated internally contains problems. The error " \
116
+ "message returned by the Nginx engine is:\n\n" \
117
+ "#{output}\n\n"
118
+ if @options[:nginx_config_template]
119
+ message << "This probably means that you have a problem in your " \
120
+ "Nginx configuration template. Please fix your template.\n\n" \
121
+ "Tip: to debug your template, re-run #{SHORT_PROGRAM_NAME} " \
122
+ "Standalone with the `--debug-nginx-config` option. This " \
123
+ "allows you to see how the final Nginx config file looks like."
124
+ else
125
+ debug_log_file = Utils::TmpIO.new('passenger-standalone',
126
+ :suffix => '.log', :binary => true, :unlink_immediately => false)
127
+ begin
128
+ File.open(nginx_config_path, 'rb') do |f|
129
+ debug_log_file.write(f.read)
130
+ end
131
+ ensure
132
+ debug_log_file.close
133
+ end
134
+ message << "This probably means that you have found a bug in " \
135
+ "#{PROGRAM_NAME} Standalone. Please report this bug to our " \
136
+ "Github issue tracker: https://github.com/phusion/passenger/issues\n\n" \
137
+ "In the bug report, please include this error message, as " \
138
+ "well as the contents of the file #{debug_log_file.path}"
139
+ end
140
+
141
+ abort(message)
142
+ end
143
+ end
144
+
91
145
  def build_daemon_controller_options
92
146
  if @options[:socket_file]
93
147
  ping_spec = [:unix, @options[:socket_file]]
@@ -96,7 +150,7 @@ module PhusionPassenger
96
150
  end
97
151
  return {
98
152
  :identifier => 'Nginx',
99
- :start_command => "#{@nginx_binary} " +
153
+ :start_command => "#{Shellwords.escape @nginx_binary} " +
100
154
  "-c #{Shellwords.escape nginx_config_path} " +
101
155
  "-p #{Shellwords.escape @working_dir}",
102
156
  :ping_command => ping_spec,
@@ -113,14 +167,17 @@ module PhusionPassenger
113
167
  def write_nginx_config_file(path)
114
168
  File.open(path, 'w') do |f|
115
169
  f.chmod(0644)
116
- erb = ERB.new(File.read(nginx_config_template_filename), nil, "-")
170
+ erb = ERB.new(File.read(nginx_config_template_filename), nil,
171
+ "-", next_eoutvar)
117
172
  erb.filename = nginx_config_template_filename
118
- current_user = Etc.getpwuid(Process.uid).name
119
173
 
120
174
  # The template requires some helper methods which are defined in start_command.rb.
121
- output = erb.result(binding)
175
+ output = erb.result(get_binding)
122
176
  f.write(output)
123
- puts output if debugging?
177
+
178
+ if debugging? && !@options[:debug_nginx_config]
179
+ puts output
180
+ end
124
181
  end
125
182
  end
126
183
 
@@ -137,6 +194,12 @@ module PhusionPassenger
137
194
  return ENV['PASSENGER_DEBUG'] && !ENV['PASSENGER_DEBUG'].empty?
138
195
  end
139
196
 
197
+ def next_eoutvar
198
+ @next_eoutvar_index ||= 0
199
+ @next_eoutvar_index += 1
200
+ "_erbout#{@next_eoutvar_index}"
201
+ end
202
+
140
203
  #### Config file template helpers ####
141
204
 
142
205
  def nginx_listen_address(options = @options)
@@ -161,9 +224,27 @@ module PhusionPassenger
161
224
  return group.name
162
225
  end
163
226
 
164
- def nginx_option(nginx_config_name, option_name)
165
- if @options.has_key?(option_name)
166
- value = @options[option_name]
227
+ def nginx_http_option(option_name)
228
+ nginx_option(@options, option_name)
229
+ end
230
+
231
+ def nginx_option(options, option_name, nginx_config_name = nil)
232
+ if options.is_a?(Symbol)
233
+ # Support old syntax for backward compatibility:
234
+ # nginx_option(nginx_config_name, option_name)
235
+ nginx_config_name = options
236
+ options = @options
237
+ end
238
+
239
+ if options.key?(option_name)
240
+ nginx_config_name ||= begin
241
+ if option_name.to_s =~ /^union_station_/
242
+ option_name
243
+ else
244
+ "passenger_#{option_name}"
245
+ end
246
+ end
247
+ value = options[option_name]
167
248
  if value.is_a?(String)
168
249
  value = "'#{value}'"
169
250
  elsif value == true
@@ -175,16 +256,44 @@ module PhusionPassenger
175
256
  end
176
257
  end
177
258
 
259
+ # Method exists for backward compatiblity with old Nginx config templates
260
+ def boolean_config_value(val)
261
+ val ? "on" : "off"
262
+ end
263
+
264
+ def include_passenger_internal_template(name, indent = 0, fix_existing_indenting = true, the_binding = get_binding)
265
+ path = "#{PhusionPassenger.resources_dir}/templates/standalone/#{name}"
266
+ erb = ERB.new(File.read(path), nil, "-", next_eoutvar)
267
+ erb.filename = path
268
+ result = erb.result(the_binding)
269
+
270
+ if fix_existing_indenting
271
+ # Remove extraneous indenting by 'if' blocks
272
+ # and collapse multiple empty newlines
273
+ result.gsub!(/;[\n ]+/, ";\n")
274
+ end
275
+
276
+ # Set indenting
277
+ result.gsub!(/^/, " " * indent)
278
+ result.gsub!(/\A +/, '')
279
+
280
+ result
281
+ end
282
+
283
+ def current_user
284
+ Etc.getpwuid(Process.uid).name
285
+ end
286
+
287
+ def get_binding
288
+ binding
289
+ end
290
+
178
291
  def default_group_for(username)
179
292
  user = Etc.getpwnam(username)
180
293
  group = Etc.getgrgid(user.gid)
181
294
  return group.name
182
295
  end
183
296
 
184
- def boolean_config_value(val)
185
- return val ? "on" : "off"
186
- end
187
-
188
297
  def serialize_strset(*items)
189
298
  if "".respond_to?(:force_encoding)
190
299
  items = items.map { |x| x.force_encoding('binary') }
@@ -1,5 +1,5 @@
1
1
  # Phusion Passenger - https://www.phusionpassenger.com/
2
- # Copyright (c) 2010-2014 Phusion Holding B.V.
2
+ # Copyright (c) 2010-2015 Phusion Holding B.V.
3
3
  #
4
4
  # "Passenger", "Phusion Passenger" and "Union Station" are registered
5
5
  # trademarks of Phusion Holding B.V.
@@ -34,8 +34,11 @@ module PhusionPassenger
34
34
 
35
35
  class StatusCommand < Command
36
36
  def run
37
- @options = { :port => 3000 }
38
37
  parse_options
38
+ load_local_config_file
39
+ load_env_config
40
+ remerge_all_options
41
+
39
42
  find_pid_file
40
43
  create_controller
41
44
  begin
@@ -54,15 +57,16 @@ module PhusionPassenger
54
57
  private
55
58
  def self.create_option_parser(options)
56
59
  OptionParser.new do |opts|
60
+ defaults = CONFIG_DEFAULTS
57
61
  nl = "\n" + ' ' * 37
58
- opts.banner = "Usage: passenger status [OPTIONS]\n"
62
+ opts.banner = "Usage: passenger status [OPTIONS] [APP DIR]\n"
59
63
  opts.separator "Shows the status of a running #{PROGRAM_NAME} Standalone instance."
60
64
  opts.separator ""
61
65
 
62
66
  opts.separator "Options:"
63
67
  opts.on("-p", "--port NUMBER", Integer,
64
68
  "The port number of the #{PROGRAM_NAME}#{nl}" +
65
- "instance. Default: 3000") do |value|
69
+ "instance. Default: #{defaults[:port]}") do |value|
66
70
  options[:port] = value
67
71
  end
68
72
  opts.on("--pid-file FILE", String,
@@ -73,23 +77,34 @@ module PhusionPassenger
73
77
  end
74
78
  end
75
79
 
76
- def find_pid_file
77
- return if @options[:pid_file]
80
+ def load_local_config_file
81
+ @local_options = ConfigUtils.
82
+ load_local_config_file_from_app_dir_param!(@argv)
83
+ end
84
+
85
+ def load_env_config
86
+ @env_options = ConfigUtils.load_env_config!
87
+ end
78
88
 
79
- logical_pwd = Dir.logical_pwd
89
+ def remerge_all_options
90
+ @options = ConfigUtils.remerge_all_config(@global_options,
91
+ @local_options, @env_options, @parsed_options)
92
+ end
93
+
94
+ def execution_root
95
+ @argv[0] || Dir.logical_pwd
96
+ end
80
97
 
81
- ["tmp/pids", "."].each do |dir|
82
- path = File.absolute_logical_path(
83
- "#{dir}/passenger.#{@options[:port]}.pid",
84
- logical_pwd)
85
- if File.exist?(path)
86
- @options[:pid_file] = path
87
- return
98
+ def find_pid_file
99
+ ConfigUtils.find_pid_and_log_file(execution_root, @options)
100
+ if !@options[:pid_file]
101
+ if @options[:ignore_pid_not_found]
102
+ exit
103
+ else
104
+ Standalone::ControlUtils.warn_pid_file_not_found(@options)
105
+ exit 1
88
106
  end
89
107
  end
90
-
91
- Standalone::ControlUtils.warn_pid_file_not_found(@options)
92
- exit 1
93
108
  end
94
109
 
95
110
  def create_controller
@@ -1,5 +1,5 @@
1
1
  # Phusion Passenger - https://www.phusionpassenger.com/
2
- # Copyright (c) 2010-2014 Phusion Holding B.V.
2
+ # Copyright (c) 2010-2015 Phusion Holding B.V.
3
3
  #
4
4
  # "Passenger", "Phusion Passenger" and "Union Station" are registered
5
5
  # trademarks of Phusion Holding B.V.
@@ -34,8 +34,11 @@ module PhusionPassenger
34
34
 
35
35
  class StopCommand < Command
36
36
  def run
37
- @options = { :port => 3000 }
38
37
  parse_options
38
+ load_local_config_file
39
+ load_env_config
40
+ remerge_all_options
41
+
39
42
  find_pid_file
40
43
  create_controller
41
44
  begin
@@ -54,15 +57,16 @@ module PhusionPassenger
54
57
  private
55
58
  def self.create_option_parser(options)
56
59
  OptionParser.new do |opts|
60
+ defaults = CONFIG_DEFAULTS
57
61
  nl = "\n" + ' ' * 37
58
- opts.banner = "Usage: passenger stop [OPTIONS]\n"
62
+ opts.banner = "Usage: passenger stop [OPTIONS] [APP DIR]\n"
59
63
  opts.separator "Stops a running #{PROGRAM_NAME} Standalone instance."
60
64
  opts.separator ""
61
65
 
62
66
  opts.separator "Options:"
63
67
  opts.on("-p", "--port NUMBER", Integer,
64
68
  "The port number of the #{PROGRAM_NAME}#{nl}" +
65
- "instance. Default: 3000") do |value|
69
+ "instance. Default: #{defaults[:port]}") do |value|
66
70
  options[:port] = value
67
71
  end
68
72
  opts.on("--pid-file FILE", String,
@@ -77,26 +81,33 @@ module PhusionPassenger
77
81
  end
78
82
  end
79
83
 
80
- def find_pid_file
81
- return if @options[:pid_file]
84
+ def load_local_config_file
85
+ @local_options = ConfigUtils.
86
+ load_local_config_file_from_app_dir_param!(@argv)
87
+ end
82
88
 
83
- logical_pwd = Dir.logical_pwd
89
+ def load_env_config
90
+ @env_options = ConfigUtils.load_env_config!
91
+ end
84
92
 
85
- ["tmp/pids", "."].each do |dir|
86
- path = File.absolute_logical_path(
87
- "#{dir}/passenger.#{@options[:port]}.pid",
88
- logical_pwd)
89
- if File.exist?(path)
90
- @options[:pid_file] = path
91
- return
92
- end
93
- end
93
+ def remerge_all_options
94
+ @options = ConfigUtils.remerge_all_config(@global_options,
95
+ @local_options, @env_options, @parsed_options)
96
+ end
94
97
 
95
- if @options[:ignore_pid_not_found]
96
- exit
97
- else
98
- Standalone::ControlUtils.warn_pid_file_not_found(@options)
99
- exit 1
98
+ def execution_root
99
+ @argv[0] || Dir.logical_pwd
100
+ end
101
+
102
+ def find_pid_file
103
+ ConfigUtils.find_pid_and_log_file(execution_root, @options)
104
+ if !@options[:pid_file]
105
+ if @options[:ignore_pid_not_found]
106
+ exit
107
+ else
108
+ Standalone::ControlUtils.warn_pid_file_not_found(@options)
109
+ exit 1
110
+ end
100
111
  end
101
112
  end
102
113