passenger 5.0.0.beta3 → 5.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of passenger might be problematic. Click here for more details.
- checksums.yaml +8 -8
- checksums.yaml.gz.asc +7 -7
- data.tar.gz.asc +7 -7
- data/.editorconfig +11 -5
- data/CHANGELOG +38 -0
- data/CONTRIBUTING.md +1 -4
- data/Gemfile +0 -1
- data/Gemfile.lock +0 -2
- data/Rakefile +33 -33
- data/bin/passenger +1 -1
- data/bin/passenger-config +1 -1
- data/bin/passenger-install-apache2-module +800 -800
- data/bin/passenger-install-nginx-module +592 -592
- data/bin/passenger-memory-stats +127 -127
- data/bin/passenger-status +216 -216
- data/build/agents.rb +127 -127
- data/build/apache2.rb +87 -87
- data/build/basics.rb +60 -60
- data/build/common_library.rb +165 -165
- data/build/cplusplus_support.rb +51 -51
- data/build/cxx_tests.rb +268 -268
- data/build/debian.rb +143 -143
- data/build/documentation.rb +58 -58
- data/build/integration_tests.rb +81 -81
- data/build/misc.rb +132 -132
- data/build/nginx.rb +20 -20
- data/build/node_tests.rb +7 -7
- data/build/oxt_tests.rb +14 -14
- data/build/packaging.rb +570 -570
- data/build/preprocessor.rb +260 -260
- data/build/rake_extensions.rb +71 -71
- data/build/ruby_extension.rb +29 -29
- data/build/ruby_tests.rb +6 -6
- data/build/test_basics.rb +37 -37
- data/debian.template/control.template +3 -5
- data/dev/copy_boost_headers +134 -134
- data/dev/install_scripts_bootstrap_code.rb +25 -25
- data/dev/list_tests +20 -20
- data/dev/ruby_server.rb +223 -223
- data/dev/runner +18 -18
- data/doc/ServerOptimizationGuide.txt.md +55 -2
- data/doc/Users guide Nginx.txt +0 -26
- data/doc/Users guide Standalone.txt +5 -1
- data/doc/users_guide_snippets/tips.txt +9 -0
- data/ext/common/ApplicationPool2/Group.h +23 -11
- data/ext/common/ApplicationPool2/Implementation.cpp +32 -7
- data/ext/common/ApplicationPool2/Pool.h +22 -17
- data/ext/common/ApplicationPool2/SmartSpawner.h +4 -1
- data/ext/common/ApplicationPool2/Spawner.h +1 -1
- data/ext/common/Constants.h +1 -1
- data/ext/common/agents/Base.cpp +35 -20
- data/ext/common/agents/HelperAgent/Main.cpp +8 -1
- data/ext/common/agents/HelperAgent/OptionParser.h +18 -4
- data/ext/common/agents/HelperAgent/RequestHandler.h +2 -83
- data/ext/common/agents/HelperAgent/RequestHandler/ForwardResponse.cpp +54 -1
- data/ext/common/agents/HelperAgent/RequestHandler/InitRequest.cpp +7 -4
- data/ext/common/agents/Main.cpp +1 -1
- data/ext/common/agents/Watchdog/Main.cpp +54 -19
- data/ext/nginx/Configuration.c +7 -0
- data/ext/nginx/ContentHandler.c +9 -1
- data/helper-scripts/backtrace-sanitizer.rb +106 -87
- data/helper-scripts/crash-watch.rb +32 -0
- data/helper-scripts/download_binaries/extconf.rb +38 -38
- data/helper-scripts/meteor-loader.rb +107 -107
- data/helper-scripts/prespawn +101 -101
- data/helper-scripts/rack-loader.rb +96 -96
- data/helper-scripts/rack-preloader.rb +137 -137
- data/lib/phusion_passenger.rb +292 -292
- data/lib/phusion_passenger/abstract_installer.rb +438 -438
- data/lib/phusion_passenger/active_support3_extensions/init.rb +168 -170
- data/lib/phusion_passenger/admin_tools.rb +20 -20
- data/lib/phusion_passenger/admin_tools/instance.rb +178 -178
- data/lib/phusion_passenger/admin_tools/instance_registry.rb +61 -61
- data/lib/phusion_passenger/admin_tools/memory_stats.rb +267 -267
- data/lib/phusion_passenger/apache2/config_options.rb +182 -182
- data/lib/phusion_passenger/common_library.rb +479 -485
- data/lib/phusion_passenger/config/about_command.rb +161 -161
- data/lib/phusion_passenger/config/admin_command_command.rb +129 -129
- data/lib/phusion_passenger/config/agent_compiler.rb +121 -121
- data/lib/phusion_passenger/config/build_native_support_command.rb +43 -43
- data/lib/phusion_passenger/config/command.rb +25 -25
- data/lib/phusion_passenger/config/compile_agent_command.rb +62 -62
- data/lib/phusion_passenger/config/compile_nginx_engine_command.rb +88 -73
- data/lib/phusion_passenger/config/detach_process_command.rb +72 -72
- data/lib/phusion_passenger/config/download_agent_command.rb +246 -227
- data/lib/phusion_passenger/config/download_nginx_engine_command.rb +245 -224
- data/lib/phusion_passenger/config/install_agent_command.rb +144 -132
- data/lib/phusion_passenger/config/install_standalone_runtime_command.rb +205 -185
- data/lib/phusion_passenger/config/installation_utils.rb +204 -204
- data/lib/phusion_passenger/config/list_instances_command.rb +64 -64
- data/lib/phusion_passenger/config/main.rb +152 -152
- data/lib/phusion_passenger/config/nginx_engine_compiler.rb +319 -300
- data/lib/phusion_passenger/config/reopen_logs_command.rb +67 -67
- data/lib/phusion_passenger/config/restart_app_command.rb +155 -155
- data/lib/phusion_passenger/config/system_metrics_command.rb +13 -13
- data/lib/phusion_passenger/config/utils.rb +95 -95
- data/lib/phusion_passenger/config/validate_install_command.rb +198 -198
- data/lib/phusion_passenger/console_text_template.rb +25 -25
- data/lib/phusion_passenger/constants.rb +90 -90
- data/lib/phusion_passenger/debug_logging.rb +106 -106
- data/lib/phusion_passenger/loader_shared_helpers.rb +447 -432
- data/lib/phusion_passenger/message_channel.rb +312 -312
- data/lib/phusion_passenger/message_client.rb +176 -176
- data/lib/phusion_passenger/native_support.rb +369 -369
- data/lib/phusion_passenger/nginx/config_options.rb +297 -297
- data/lib/phusion_passenger/packaging.rb +131 -131
- data/lib/phusion_passenger/platform_info.rb +360 -360
- data/lib/phusion_passenger/platform_info/apache.rb +767 -767
- data/lib/phusion_passenger/platform_info/apache_detector.rb +199 -199
- data/lib/phusion_passenger/platform_info/binary_compatibility.rb +107 -107
- data/lib/phusion_passenger/platform_info/compiler.rb +570 -570
- data/lib/phusion_passenger/platform_info/curl.rb +32 -32
- data/lib/phusion_passenger/platform_info/cxx_portability.rb +188 -188
- data/lib/phusion_passenger/platform_info/depcheck.rb +372 -372
- data/lib/phusion_passenger/platform_info/depcheck_specs/apache2.rb +109 -109
- data/lib/phusion_passenger/platform_info/depcheck_specs/compiler_toolchain.rb +4 -4
- data/lib/phusion_passenger/platform_info/depcheck_specs/gems.rb +10 -34
- data/lib/phusion_passenger/platform_info/depcheck_specs/libs.rb +101 -101
- data/lib/phusion_passenger/platform_info/depcheck_specs/ruby.rb +5 -5
- data/lib/phusion_passenger/platform_info/depcheck_specs/utilities.rb +13 -13
- data/lib/phusion_passenger/platform_info/linux.rb +55 -55
- data/lib/phusion_passenger/platform_info/operating_system.rb +149 -149
- data/lib/phusion_passenger/platform_info/ruby.rb +468 -448
- data/lib/phusion_passenger/platform_info/zlib.rb +9 -9
- data/lib/phusion_passenger/plugin.rb +66 -66
- data/lib/phusion_passenger/preloader_shared_helpers.rb +126 -126
- data/lib/phusion_passenger/public_api.rb +191 -191
- data/lib/phusion_passenger/rack/out_of_band_gc.rb +93 -94
- data/lib/phusion_passenger/rack/thread_handler_extension.rb +231 -227
- data/lib/phusion_passenger/request_handler.rb +567 -577
- data/lib/phusion_passenger/request_handler/thread_handler.rb +379 -381
- data/lib/phusion_passenger/ruby_core_enhancements.rb +86 -86
- data/lib/phusion_passenger/ruby_core_io_enhancements.rb +74 -74
- data/lib/phusion_passenger/simple_benchmarking.rb +25 -25
- data/lib/phusion_passenger/standalone/app_finder.rb +153 -150
- data/lib/phusion_passenger/standalone/command.rb +44 -40
- data/lib/phusion_passenger/standalone/config_utils.rb +53 -53
- data/lib/phusion_passenger/standalone/control_utils.rb +38 -59
- data/lib/phusion_passenger/standalone/main.rb +73 -73
- data/lib/phusion_passenger/standalone/start_command.rb +697 -685
- data/lib/phusion_passenger/standalone/start_command/builtin_engine.rb +193 -155
- data/lib/phusion_passenger/standalone/start_command/nginx_engine.rb +162 -133
- data/lib/phusion_passenger/standalone/status_command.rb +64 -64
- data/lib/phusion_passenger/standalone/stop_command.rb +72 -72
- data/lib/phusion_passenger/standalone/version_command.rb +9 -9
- data/lib/phusion_passenger/union_station/connection.rb +32 -32
- data/lib/phusion_passenger/union_station/core.rb +251 -251
- data/lib/phusion_passenger/union_station/transaction.rb +126 -126
- data/lib/phusion_passenger/utils.rb +199 -167
- data/lib/phusion_passenger/utils/ansi_colors.rb +128 -128
- data/lib/phusion_passenger/utils/download.rb +196 -196
- data/lib/phusion_passenger/utils/file_system_watcher.rb +158 -158
- data/lib/phusion_passenger/utils/hosts_file_parser.rb +101 -101
- data/lib/phusion_passenger/utils/lock.rb +31 -31
- data/lib/phusion_passenger/utils/native_support_utils.rb +31 -31
- data/lib/phusion_passenger/utils/progress_bar.rb +26 -26
- data/lib/phusion_passenger/utils/shellwords.rb +20 -20
- data/lib/phusion_passenger/utils/terminal_choice_menu.rb +206 -206
- data/lib/phusion_passenger/utils/unseekable_socket.rb +272 -272
- data/lib/phusion_passenger/vendor/crash_watch/app.rb +129 -0
- data/lib/phusion_passenger/vendor/crash_watch/gdb_controller.rb +341 -0
- data/lib/phusion_passenger/vendor/crash_watch/version.rb +24 -0
- data/lib/phusion_passenger/vendor/daemon_controller.rb +877 -0
- data/lib/phusion_passenger/vendor/daemon_controller/lock_file.rb +127 -0
- data/lib/phusion_passenger/vendor/daemon_controller/spawn.rb +26 -0
- data/lib/phusion_passenger/vendor/daemon_controller/version.rb +29 -0
- data/packaging/rpm/passenger_spec/passenger.spec.template +0 -1
- data/passenger.gemspec +0 -1
- data/resources/templates/config/nginx_engine_compiler/possible_solutions_for_download_and_extraction_problems.txt.erb +27 -0
- data/resources/templates/standalone/config.erb +19 -15
- data/test/integration_tests/apache2_tests.rb +566 -566
- data/test/integration_tests/downloaded_binaries_tests.rb +126 -125
- data/test/integration_tests/native_packaging_spec.rb +296 -296
- data/test/integration_tests/nginx_tests.rb +393 -393
- data/test/integration_tests/shared/example_webapp_tests.rb +282 -280
- data/test/integration_tests/source_packaging_test.rb +138 -138
- data/test/integration_tests/spec_helper.rb +5 -5
- data/test/integration_tests/standalone_tests.rb +367 -367
- data/test/ruby/debug_logging_spec.rb +133 -133
- data/test/ruby/message_channel_spec.rb +186 -186
- data/test/ruby/rack/loader_spec.rb +28 -28
- data/test/ruby/rack/preloader_spec.rb +34 -34
- data/test/ruby/rails3.0/loader_spec.rb +12 -12
- data/test/ruby/rails3.0/preloader_spec.rb +18 -18
- data/test/ruby/rails3.1/loader_spec.rb +12 -12
- data/test/ruby/rails3.1/preloader_spec.rb +18 -18
- data/test/ruby/rails3.2/loader_spec.rb +12 -12
- data/test/ruby/rails3.2/preloader_spec.rb +18 -18
- data/test/ruby/rails4.0/loader_spec.rb +12 -12
- data/test/ruby/rails4.0/preloader_spec.rb +18 -18
- data/test/ruby/rails4.1/loader_spec.rb +12 -12
- data/test/ruby/rails4.1/preloader_spec.rb +18 -18
- data/test/ruby/request_handler_spec.rb +730 -730
- data/test/ruby/shared/loader_sharedspec.rb +224 -224
- data/test/ruby/shared/rails/union_station_extensions_sharedspec.rb +327 -327
- data/test/ruby/shared/ruby_loader_sharedspec.rb +47 -47
- data/test/ruby/spec_helper.rb +65 -65
- data/test/ruby/standalone/runtime_installer_spec.rb +384 -384
- data/test/ruby/union_station_spec.rb +276 -276
- data/test/ruby/utils/file_system_watcher_spec.rb +220 -220
- data/test/ruby/utils/hosts_file_parser.rb +248 -248
- data/test/ruby/utils/tee_input_spec.rb +215 -215
- data/test/ruby/utils/unseekable_socket_spec.rb +57 -57
- data/test/ruby/utils_spec.rb +21 -21
- data/test/stub/rack/config.ru +87 -87
- data/test/stub/rack/library.rb +8 -8
- data/test/stub/rack/start.rb +30 -30
- data/test/support/apache2_controller.rb +191 -191
- data/test/support/nginx_controller.rb +90 -99
- data/test/support/placebo-preloader.rb +57 -57
- data/test/support/test_helper.rb +435 -435
- metadata +11 -21
- metadata.gz.asc +7 -7
- data/lib/phusion_passenger/standalone/command2.rb +0 -292
- data/lib/phusion_passenger/standalone/start2_command.rb +0 -799
- data/resources/templates/standalone/download_tool_missing.txt.erb +0 -18
- data/resources/templates/standalone/possible_solutions_for_download_and_extraction_problems.txt.erb +0 -17
- data/resources/templates/standalone/run_installer_as_root.txt.erb +0 -8
@@ -1,5 +1,5 @@
|
|
1
1
|
# Phusion Passenger - https://www.phusionpassenger.com/
|
2
|
-
# Copyright (c) 2010-
|
2
|
+
# Copyright (c) 2010-2015 Phusion
|
3
3
|
#
|
4
4
|
# "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
|
5
5
|
#
|
@@ -27,6 +27,7 @@ PhusionPassenger.require_passenger_lib 'constants'
|
|
27
27
|
PhusionPassenger.require_passenger_lib 'ruby_core_enhancements'
|
28
28
|
PhusionPassenger.require_passenger_lib 'standalone/command'
|
29
29
|
PhusionPassenger.require_passenger_lib 'standalone/config_utils'
|
30
|
+
PhusionPassenger.require_passenger_lib 'utils'
|
30
31
|
PhusionPassenger.require_passenger_lib 'utils/tmpio'
|
31
32
|
|
32
33
|
# We lazy load as many libraries as possible not only to improve startup performance,
|
@@ -34,688 +35,699 @@ PhusionPassenger.require_passenger_lib 'utils/tmpio'
|
|
34
35
|
# checking stage of the runtime installer.
|
35
36
|
|
36
37
|
module PhusionPassenger
|
37
|
-
module Standalone
|
38
|
-
|
39
|
-
class StartCommand < Command
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
private
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
end
|
719
|
-
|
720
|
-
end
|
38
|
+
module Standalone
|
39
|
+
|
40
|
+
class StartCommand < Command
|
41
|
+
DEFAULT_OPTIONS = {
|
42
|
+
:environment => ENV['RAILS_ENV'] || ENV['RACK_ENV'] || ENV['NODE_ENV'] ||
|
43
|
+
ENV['PASSENGER_APP_ENV'] || 'development',
|
44
|
+
:spawn_method => Kernel.respond_to?(:fork) ? DEFAULT_SPAWN_METHOD : 'direct',
|
45
|
+
:engine => "nginx",
|
46
|
+
:nginx_version => PREFERRED_NGINX_VERSION,
|
47
|
+
:log_level => DEFAULT_LOG_LEVEL,
|
48
|
+
:ctls => [],
|
49
|
+
:envvars => {}
|
50
|
+
}.freeze
|
51
|
+
|
52
|
+
def run
|
53
|
+
parse_options
|
54
|
+
load_local_config_file
|
55
|
+
remerge_all_options
|
56
|
+
sanity_check_options_and_set_defaults
|
57
|
+
|
58
|
+
lookup_runtime_and_ensure_installed
|
59
|
+
set_stdout_stderr_binmode
|
60
|
+
exit if @options[:runtime_check_only]
|
61
|
+
|
62
|
+
find_apps
|
63
|
+
find_pid_and_log_file(@app_finder, @options)
|
64
|
+
create_working_dir
|
65
|
+
begin
|
66
|
+
initialize_vars
|
67
|
+
start_engine
|
68
|
+
show_intro_message
|
69
|
+
maybe_daemonize
|
70
|
+
touch_temp_dir_in_background
|
71
|
+
########################
|
72
|
+
########################
|
73
|
+
watch_log_files_in_background if should_watch_logs?
|
74
|
+
wait_until_engine_has_exited if should_wait_until_engine_has_exited?
|
75
|
+
rescue Interrupt
|
76
|
+
shutdown_and_cleanup(true)
|
77
|
+
exit 2
|
78
|
+
rescue SignalException => signal
|
79
|
+
shutdown_and_cleanup(true)
|
80
|
+
if signal.message == 'SIGINT' || signal.message == 'SIGTERM'
|
81
|
+
exit 2
|
82
|
+
else
|
83
|
+
raise
|
84
|
+
end
|
85
|
+
rescue Exception
|
86
|
+
shutdown_and_cleanup(true)
|
87
|
+
raise
|
88
|
+
else
|
89
|
+
shutdown_and_cleanup(false)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
################# Configuration loading, option parsing and initialization ###################
|
95
|
+
|
96
|
+
def self.create_option_parser(options)
|
97
|
+
# If you add or change an option, make sure to update the following places too:
|
98
|
+
# lib/phusion_passenger/standalone/start_command/builtin_engine.rb, #build_daemon_controller_options
|
99
|
+
# resources/templates/config/standalone.erb
|
100
|
+
OptionParser.new do |opts|
|
101
|
+
nl = "\n" + ' ' * 37
|
102
|
+
opts.banner = "Usage: passenger start [DIRECTORY] [OPTIONS]\n"
|
103
|
+
opts.separator "Starts #{PROGRAM_NAME} Standalone and serve one or more web applications."
|
104
|
+
opts.separator ""
|
105
|
+
|
106
|
+
opts.separator "Server options:"
|
107
|
+
opts.on("-a", "--address HOST", String, "Bind to the given address.#{nl}" +
|
108
|
+
"Default: 0.0.0.0") do |value|
|
109
|
+
options[:address] = value
|
110
|
+
end
|
111
|
+
opts.on("-p", "--port NUMBER", Integer,
|
112
|
+
"Use the given port number. Default: 3000") do |value|
|
113
|
+
options[:port] = value
|
114
|
+
end
|
115
|
+
opts.on("-S", "--socket FILE", String,
|
116
|
+
"Bind to Unix domain socket instead of TCP#{nl}" +
|
117
|
+
"socket") do |value|
|
118
|
+
options[:socket_file] = value
|
119
|
+
end
|
120
|
+
opts.on("--ssl", "Enable SSL support (Nginx#{nl}" +
|
121
|
+
"engine only)") do
|
122
|
+
options[:ssl] = true
|
123
|
+
end
|
124
|
+
opts.on("--ssl-certificate PATH", String,
|
125
|
+
"Specify the SSL certificate path#{nl}" +
|
126
|
+
"(Nginx engine only)") do |value|
|
127
|
+
options[:ssl_certificate] = File.absolute_path_no_resolve(value)
|
128
|
+
end
|
129
|
+
opts.on("--ssl-certificate-key PATH", String,
|
130
|
+
"Specify the SSL key path") do |value|
|
131
|
+
options[:ssl_certificate_key] = File.absolute_path_no_resolve(value)
|
132
|
+
end
|
133
|
+
opts.on("--ssl-port PORT", Integer,
|
134
|
+
"Listen for SSL on this port, while#{nl}" +
|
135
|
+
"listening for HTTP on the normal port#{nl}" +
|
136
|
+
"(Nginx engine only)") do |value|
|
137
|
+
options[:ssl_port] = value
|
138
|
+
end
|
139
|
+
opts.on("-d", "--daemonize", "Daemonize into the background") do
|
140
|
+
options[:daemonize] = true
|
141
|
+
end
|
142
|
+
opts.on("--user USERNAME", String, "User to run as. Ignored unless#{nl}" +
|
143
|
+
"running as root") do |value|
|
144
|
+
options[:user] = value
|
145
|
+
end
|
146
|
+
opts.on("--log-file FILENAME", String,
|
147
|
+
"Where to write log messages. Default:#{nl}" +
|
148
|
+
"console, or /dev/null when daemonized") do |value|
|
149
|
+
options[:log_file] = value
|
150
|
+
end
|
151
|
+
opts.on("--pid-file FILENAME", String, "Where to store the PID file") do |value|
|
152
|
+
options[:pid_file] = value
|
153
|
+
end
|
154
|
+
opts.on("--instance-registry-dir PATH", String,
|
155
|
+
"Use the given instance registry directory") do |value|
|
156
|
+
options[:instance_registry_dir] = value
|
157
|
+
end
|
158
|
+
opts.on("--data-buffer-dir PATH", String,
|
159
|
+
"Use the given data buffer directory") do |value|
|
160
|
+
options[:data_buffer_dir] = value
|
161
|
+
end
|
162
|
+
|
163
|
+
opts.separator ""
|
164
|
+
opts.separator "Application loading options:"
|
165
|
+
opts.on("-e", "--environment ENV", String,
|
166
|
+
"Framework environment.#{nl}" +
|
167
|
+
"Default: #{DEFAULT_OPTIONS[:environment]}") do |value|
|
168
|
+
options[:environment] = value
|
169
|
+
end
|
170
|
+
opts.on("-R", "--rackup FILE", String,
|
171
|
+
"Consider application a Ruby app, and use#{nl}" +
|
172
|
+
"the given rackup file") do |value|
|
173
|
+
options[:app_type] = "rack"
|
174
|
+
options[:startup_file] = value
|
175
|
+
end
|
176
|
+
opts.on("--app-type NAME", String,
|
177
|
+
"Force app to be detected as the given type") do |value|
|
178
|
+
options[:app_type] = value
|
179
|
+
end
|
180
|
+
opts.on("--startup-file FILENAME", String,
|
181
|
+
"Force given startup file to be used") do |value|
|
182
|
+
options[:startup_file] = value
|
183
|
+
end
|
184
|
+
opts.on("--spawn-method NAME", String,
|
185
|
+
"The spawn method to use. Default: #{DEFAULT_OPTIONS[:spawn_method]}") do |value|
|
186
|
+
options[:spawn_method] = value
|
187
|
+
end
|
188
|
+
opts.on("--static-files-dir PATH", String,
|
189
|
+
"Specify the static files dir (Nginx engine#{nl}" +
|
190
|
+
"only)") do |val|
|
191
|
+
options[:static_files_dir] = File.absolute_path_no_resolve(val)
|
192
|
+
end
|
193
|
+
opts.on("--restart-dir PATH", String, "Specify the restart dir") do |val|
|
194
|
+
options[:restart_dir] = File.absolute_path_no_resolve(val)
|
195
|
+
end
|
196
|
+
opts.on("--friendly-error-pages", "Turn on friendly error pages") do
|
197
|
+
options[:friendly_error_pages] = true
|
198
|
+
end
|
199
|
+
opts.on("--no-friendly-error-pages", "Turn off friendly error pages") do
|
200
|
+
options[:friendly_error_pages] = false
|
201
|
+
end
|
202
|
+
opts.on("--load-shell-envvars",
|
203
|
+
"Load shell startup files before loading#{nl}" +
|
204
|
+
"application") do
|
205
|
+
options[:load_shell_envvars] = true
|
206
|
+
end
|
207
|
+
opts.on("--debugger", "Enable debugger support") do
|
208
|
+
options[:debugger] = true
|
209
|
+
end
|
210
|
+
|
211
|
+
opts.separator ""
|
212
|
+
opts.separator "Process management options:"
|
213
|
+
opts.on("--max-pool-size NUMBER", Integer,
|
214
|
+
"Maximum number of application processes.#{nl}" +
|
215
|
+
"Default: #{DEFAULT_MAX_POOL_SIZE}") do |value|
|
216
|
+
if value < 1
|
217
|
+
abort "*** ERROR: you may only specify for --max-pool-size a number greater than or equal to 1"
|
218
|
+
end
|
219
|
+
options[:max_pool_size] = value
|
220
|
+
end
|
221
|
+
opts.on("--min-instances NUMBER", Integer,
|
222
|
+
"Minimum number of processes per#{nl}" +
|
223
|
+
"application. Default: 1") do |value|
|
224
|
+
options[:min_instances] = value
|
225
|
+
end
|
226
|
+
opts.on("--concurrency-model NAME", String,
|
227
|
+
"The concurrency model to use, either#{nl}" +
|
228
|
+
"'process' or 'thread' (Enterprise only).#{nl}" +
|
229
|
+
"Default: #{DEFAULT_CONCURRENCY_MODEL}") do |value|
|
230
|
+
options[:concurrency_model] = value
|
231
|
+
end
|
232
|
+
opts.on("--thread-count NAME", Integer,
|
233
|
+
"The number of threads to use when using#{nl}" +
|
234
|
+
"the 'thread' concurrency model (Enterprise#{nl}" +
|
235
|
+
"only). Default: #{DEFAULT_APP_THREAD_COUNT}") do |value|
|
236
|
+
options[:thread_count] = value
|
237
|
+
end
|
238
|
+
opts.on("--rolling-restarts", "Enable rolling restarts (Enterprise only)") do
|
239
|
+
options[:rolling_restarts] = true
|
240
|
+
end
|
241
|
+
opts.on("--resist-deployment-errors", "Enable deployment error resistance#{nl}" +
|
242
|
+
"(Enterprise only)") do
|
243
|
+
options[:resist_deployment_errors] = true
|
244
|
+
end
|
245
|
+
|
246
|
+
opts.separator ""
|
247
|
+
opts.separator "Request handling options:"
|
248
|
+
opts.on("--sticky-sessions", "Enable sticky sessions") do
|
249
|
+
options[:sticky_sessions] = true
|
250
|
+
end
|
251
|
+
opts.on("--sticky-sessions-cookie-name NAME", String,
|
252
|
+
"Cookie name to use for sticky sessions.#{nl}" +
|
253
|
+
"Default: #{DEFAULT_STICKY_SESSIONS_COOKIE_NAME}") do |value|
|
254
|
+
options[:sticky_sessions_cookie_name] = value
|
255
|
+
end
|
256
|
+
opts.on("--vary-turbocache-by-cookie NAME", String,
|
257
|
+
"Vary the turbocache by the cookie of the given name") do |value|
|
258
|
+
options[:vary_turbocache_by_cookie] = value
|
259
|
+
end
|
260
|
+
opts.on("--disable-turbocaching", "Disable turbocaching") do
|
261
|
+
options[:turbocaching] = false
|
262
|
+
end
|
263
|
+
|
264
|
+
opts.separator ""
|
265
|
+
opts.separator "Union Station options:"
|
266
|
+
opts.on("--union-station-gateway HOST:PORT", String,
|
267
|
+
"Specify Union Station Gateway host and port") do |value|
|
268
|
+
host, port = value.split(":", 2)
|
269
|
+
port = port.to_i
|
270
|
+
port = 443 if port == 0
|
271
|
+
options[:union_station_gateway_address] = host
|
272
|
+
options[:union_station_gateway_port] = port.to_i
|
273
|
+
end
|
274
|
+
opts.on("--union-station-key KEY", String, "Specify Union Station key") do |value|
|
275
|
+
options[:union_station_key] = value
|
276
|
+
end
|
277
|
+
|
278
|
+
opts.separator ""
|
279
|
+
opts.separator "Nginx engine options:"
|
280
|
+
opts.on("--nginx-bin FILENAME", String, "Nginx binary to use as core") do |value|
|
281
|
+
options[:nginx_bin] = value
|
282
|
+
end
|
283
|
+
opts.on("--nginx-version VERSION", String,
|
284
|
+
"Nginx version to use as core.#{nl}" +
|
285
|
+
"Default: #{PREFERRED_NGINX_VERSION}") do |value|
|
286
|
+
options[:nginx_version] = value
|
287
|
+
end
|
288
|
+
opts.on("--nginx-tarball FILENAME", String,
|
289
|
+
"If Nginx needs to be installed, then the#{nl}" +
|
290
|
+
"given tarball will be used instead of#{nl}" +
|
291
|
+
"downloading from the Internet") do |value|
|
292
|
+
options[:nginx_tarball] = File.absolute_path_no_resolve(value)
|
293
|
+
end
|
294
|
+
opts.on("--nginx-config-template FILENAME", String,
|
295
|
+
"The template to use for generating the#{nl}" +
|
296
|
+
"Nginx config file") do |value|
|
297
|
+
options[:nginx_config_template] = File.absolute_path_no_resolve(value)
|
298
|
+
end
|
299
|
+
|
300
|
+
opts.separator ""
|
301
|
+
opts.separator "Advanced options:"
|
302
|
+
opts.on("--engine NAME", String,
|
303
|
+
"Underlying HTTP engine to use. Available#{nl}" +
|
304
|
+
"options: nginx (default), builtin") do |value|
|
305
|
+
options[:engine] = value
|
306
|
+
end
|
307
|
+
opts.on("--log-level NUMBER", Integer, "Log level to use. Default: #{DEFAULT_LOG_LEVEL}") do |value|
|
308
|
+
options[:log_level] = value
|
309
|
+
end
|
310
|
+
opts.on("--ctl NAME=VALUE", String) do |value|
|
311
|
+
if value !~ /=.+/
|
312
|
+
abort "*** ERROR: invalid --ctl format: #{value}"
|
313
|
+
end
|
314
|
+
options[:ctls] << value
|
315
|
+
end
|
316
|
+
opts.on("--binaries-url-root URL", String,
|
317
|
+
"If Nginx needs to be installed, then the#{nl}" +
|
318
|
+
"specified URL will be checked for binaries#{nl}" +
|
319
|
+
"prior to a local build") do |value|
|
320
|
+
options[:binaries_url_root] = value
|
321
|
+
end
|
322
|
+
opts.on("--no-download-binaries", "Never download binaries") do
|
323
|
+
options[:download_binaries] = false
|
324
|
+
end
|
325
|
+
opts.on("--runtime-check-only",
|
326
|
+
"Quit after checking whether the#{nl}" +
|
327
|
+
"#{PROGRAM_NAME} Standalone runtime files#{nl}" +
|
328
|
+
"are installed") do
|
329
|
+
options[:runtime_check_only] = true
|
330
|
+
end
|
331
|
+
opts.on("--no-install-runtime", "Abort if runtime must be installed") do
|
332
|
+
options[:dont_install_runtime] = true
|
333
|
+
end
|
334
|
+
opts.on("--no-compile-runtime", "Abort if runtime must be compiled") do
|
335
|
+
options[:dont_compile_runtime] = true
|
336
|
+
end
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
def load_local_config_file
|
341
|
+
if @argv.empty?
|
342
|
+
app_dir = File.absolute_path_no_resolve(".")
|
343
|
+
elsif @argv.size == 1
|
344
|
+
app_dir = @argv[0]
|
345
|
+
end
|
346
|
+
@local_options = {}
|
347
|
+
if app_dir
|
348
|
+
begin
|
349
|
+
ConfigUtils.load_local_config_file!(app_dir, @local_options)
|
350
|
+
rescue ConfigLoadError => e
|
351
|
+
abort "*** ERROR: #{e.message}"
|
352
|
+
end
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
356
|
+
# We want the command line options to override the options in the local config
|
357
|
+
# file, but the local config file could only be parsed when the command line
|
358
|
+
# options have been parsed. In this method we remerge all the config options
|
359
|
+
# from different sources so that options are overriden according to the following
|
360
|
+
# order:
|
361
|
+
#
|
362
|
+
# - DEFAULT_OPTIONS
|
363
|
+
# - global config file
|
364
|
+
# - local config file
|
365
|
+
# - command line options
|
366
|
+
def remerge_all_options
|
367
|
+
@options = DEFAULT_OPTIONS.
|
368
|
+
merge(@global_options).
|
369
|
+
merge(@local_options).
|
370
|
+
merge(@parsed_options)
|
371
|
+
end
|
372
|
+
|
373
|
+
def sanity_check_options_and_set_defaults
|
374
|
+
if (@options[:address] || @options[:port]) && @options[:socket_file]
|
375
|
+
abort "You cannot specify both --address/--port and --socket. Please choose either one."
|
376
|
+
end
|
377
|
+
if @options[:ssl] && !@options[:ssl_certificate]
|
378
|
+
abort "You specified --ssl. Please specify --ssl-certificate as well."
|
379
|
+
end
|
380
|
+
if @options[:ssl] && !@options[:ssl_certificate_key]
|
381
|
+
abort "You specified --ssl. Please specify --ssl-certificate-key as well."
|
382
|
+
end
|
383
|
+
if @options[:engine] != "builtin" && @options[:engine] != "nginx"
|
384
|
+
abort "You've specified an invalid value for --engine. The only values allowed are: builtin, nginx."
|
385
|
+
end
|
386
|
+
|
387
|
+
if !@options[:socket_file]
|
388
|
+
@options[:address] ||= "0.0.0.0"
|
389
|
+
@options[:port] ||= 3000
|
390
|
+
end
|
391
|
+
|
392
|
+
if @options[:engine] == "builtin"
|
393
|
+
# We explicitly check for some options are set and warn the user about this,
|
394
|
+
# in case they forget to pass --engine=nginx. We don't warn about options
|
395
|
+
# that begin with --nginx- because that should be obvious.
|
396
|
+
check_nginx_option_used_with_builtin_engine(:ssl, "--ssl")
|
397
|
+
check_nginx_option_used_with_builtin_engine(:ssl_certificate, "--ssl-certificate")
|
398
|
+
check_nginx_option_used_with_builtin_engine(:ssl_certificate_key, "--ssl-certificate-key")
|
399
|
+
check_nginx_option_used_with_builtin_engine(:ssl_port, "--ssl-port")
|
400
|
+
check_nginx_option_used_with_builtin_engine(:static_files_dir, "--static-files-dir")
|
401
|
+
end
|
402
|
+
|
403
|
+
#############
|
404
|
+
end
|
405
|
+
|
406
|
+
def check_nginx_option_used_with_builtin_engine(option, argument)
|
407
|
+
if @options.has_key?(option)
|
408
|
+
STDERR.puts "*** Warning: the #{argument} option is only allowed if you use " +
|
409
|
+
"the 'nginx' engine. You are currently using the 'builtin' engine, so " +
|
410
|
+
"this option has been ignored. To switch to the Nginx engine, please " +
|
411
|
+
"pass --engine=nginx."
|
412
|
+
end
|
413
|
+
end
|
414
|
+
|
415
|
+
def lookup_runtime_and_ensure_installed
|
416
|
+
@agent_exe = PhusionPassenger.find_support_binary(AGENT_EXE)
|
417
|
+
if @options[:nginx_bin]
|
418
|
+
@nginx_binary = @options[:nginx_bin]
|
419
|
+
if !@nginx_binary
|
420
|
+
abort "*** ERROR: Nginx binary #{@options[:nginx_bin]} does not exist"
|
421
|
+
end
|
422
|
+
if !@agent_exe
|
423
|
+
install_runtime
|
424
|
+
@agent_exe = PhusionPassenger.find_support_binary(AGENT_EXE)
|
425
|
+
end
|
426
|
+
else
|
427
|
+
nginx_name = "nginx-#{@options[:nginx_version]}"
|
428
|
+
@nginx_binary = PhusionPassenger.find_support_binary(nginx_name)
|
429
|
+
if !@agent_exe || !@nginx_binary
|
430
|
+
install_runtime
|
431
|
+
@agent_exe = PhusionPassenger.find_support_binary(AGENT_EXE)
|
432
|
+
@nginx_binary = PhusionPassenger.find_support_binary(nginx_name)
|
433
|
+
end
|
434
|
+
end
|
435
|
+
end
|
436
|
+
|
437
|
+
def install_runtime
|
438
|
+
if @options[:dont_install_runtime]
|
439
|
+
abort "*** ERROR: Refusing to install the #{PROGRAM_NAME} Standalone runtime " +
|
440
|
+
"because --no-install-runtime is given."
|
441
|
+
end
|
442
|
+
|
443
|
+
args = [
|
444
|
+
"--brief",
|
445
|
+
"--no-force-tip",
|
446
|
+
# Use default Utils::Download timeouts, which are short. We want short
|
447
|
+
# timeouts so that if the primary server is down and is not responding
|
448
|
+
# (as opposed to responding quickly with an error), then the system
|
449
|
+
# quickly switches to a mirror.
|
450
|
+
"--connect-timeout", "0",
|
451
|
+
"--idle-timeout", "0"
|
452
|
+
]
|
453
|
+
if @options[:binaries_url_root]
|
454
|
+
args << "--url-root"
|
455
|
+
args << @options[:binaries_url_root]
|
456
|
+
end
|
457
|
+
if @options[:nginx_version]
|
458
|
+
args << "--nginx-version"
|
459
|
+
args << @options[:nginx_version]
|
460
|
+
end
|
461
|
+
if @options[:nginx_tarball]
|
462
|
+
args << "--nginx-tarball"
|
463
|
+
args << @options[:nginx_tarball]
|
464
|
+
end
|
465
|
+
if @options[:dont_compile_runtime]
|
466
|
+
args << "--no-compile"
|
467
|
+
end
|
468
|
+
PhusionPassenger.require_passenger_lib 'config/install_standalone_runtime_command'
|
469
|
+
PhusionPassenger::Config::InstallStandaloneRuntimeCommand.new(args).run
|
470
|
+
puts
|
471
|
+
puts "--------------------------"
|
472
|
+
puts
|
473
|
+
end
|
474
|
+
|
475
|
+
def set_stdout_stderr_binmode
|
476
|
+
# We already set STDOUT and STDERR to binmode in bin/passenger, which
|
477
|
+
# fixes https://github.com/phusion/passenger-ruby-heroku-demo/issues/11.
|
478
|
+
# However RuntimeInstaller sets them to UTF-8, so here we set them back.
|
479
|
+
STDOUT.binmode
|
480
|
+
STDERR.binmode
|
481
|
+
end
|
482
|
+
|
483
|
+
|
484
|
+
################## Core logic ##################
|
485
|
+
|
486
|
+
def find_apps
|
487
|
+
PhusionPassenger.require_passenger_lib 'standalone/app_finder'
|
488
|
+
@app_finder = AppFinder.new(@argv, @options)
|
489
|
+
@apps = @app_finder.scan
|
490
|
+
if @app_finder.multi_mode? && @options[:engine] != 'nginx'
|
491
|
+
puts "Mass deployment enabled, so forcing engine to 'nginx'."
|
492
|
+
@options[:engine] = 'nginx'
|
493
|
+
end
|
494
|
+
end
|
495
|
+
|
496
|
+
def find_pid_and_log_file(app_finder, options)
|
497
|
+
exec_root = app_finder.execution_root
|
498
|
+
if options[:socket_file]
|
499
|
+
pid_basename = "passenger.pid"
|
500
|
+
log_basename = "passenger.log"
|
501
|
+
else
|
502
|
+
pid_basename = "passenger.#{options[:port]}.pid"
|
503
|
+
log_basename = "passenger.#{options[:port]}.log"
|
504
|
+
end
|
505
|
+
if File.directory?("#{exec_root}/tmp/pids")
|
506
|
+
options[:pid_file] ||= "#{exec_root}/tmp/pids/#{pid_basename}"
|
507
|
+
else
|
508
|
+
options[:pid_file] ||= "#{exec_root}/#{pid_basename}"
|
509
|
+
end
|
510
|
+
if File.directory?("log")
|
511
|
+
options[:log_file] ||= "#{exec_root}/log/#{log_basename}"
|
512
|
+
else
|
513
|
+
options[:log_file] ||= "#{exec_root}/#{log_basename}"
|
514
|
+
end
|
515
|
+
end
|
516
|
+
|
517
|
+
def create_working_dir
|
518
|
+
# We don't remove the working dir in 'passenger start'. In daemon
|
519
|
+
# mode 'passenger start' just quits and lets background processes
|
520
|
+
# running. A specific background process, temp-dir-toucher, is
|
521
|
+
# responsible for cleaning up the working dir.
|
522
|
+
@working_dir = PhusionPassenger::Utils.mktmpdir("passenger-standalone.")
|
523
|
+
File.chmod(0755, @working_dir)
|
524
|
+
Dir.mkdir("#{@working_dir}/logs")
|
525
|
+
@can_remove_working_dir = true
|
526
|
+
end
|
527
|
+
|
528
|
+
def initialize_vars
|
529
|
+
@console_mutex = Mutex.new
|
530
|
+
@termination_pipe = IO.pipe
|
531
|
+
@threads = []
|
532
|
+
@interruptable_threads = []
|
533
|
+
end
|
534
|
+
|
535
|
+
def start_engine
|
536
|
+
metaclass = class << self; self; end
|
537
|
+
if @options[:engine] == 'nginx'
|
538
|
+
PhusionPassenger.require_passenger_lib 'standalone/start_command/nginx_engine'
|
539
|
+
metaclass.send(:include, PhusionPassenger::Standalone::StartCommand::NginxEngine)
|
540
|
+
else
|
541
|
+
PhusionPassenger.require_passenger_lib 'standalone/start_command/builtin_engine'
|
542
|
+
metaclass.send(:include, PhusionPassenger::Standalone::StartCommand::BuiltinEngine)
|
543
|
+
end
|
544
|
+
start_engine_real
|
545
|
+
end
|
546
|
+
|
547
|
+
# Returns the URL that the server will be listening on.
|
548
|
+
def listen_url
|
549
|
+
if @options[:socket_file]
|
550
|
+
return @options[:socket_file]
|
551
|
+
else
|
552
|
+
if @options[:ssl] && !@options[:ssl_port]
|
553
|
+
scheme = "https"
|
554
|
+
else
|
555
|
+
scheme = "http"
|
556
|
+
end
|
557
|
+
result = "#{scheme}://"
|
558
|
+
if @options[:port] == 80
|
559
|
+
result << @options[:address]
|
560
|
+
else
|
561
|
+
result << compose_ip_and_port(@options[:address], @options[:port])
|
562
|
+
end
|
563
|
+
result << "/"
|
564
|
+
return result
|
565
|
+
end
|
566
|
+
end
|
567
|
+
|
568
|
+
def compose_ip_and_port(ip, port)
|
569
|
+
if ip =~ /:/
|
570
|
+
# IPv6
|
571
|
+
return "[#{ip}]:#{port}"
|
572
|
+
else
|
573
|
+
return "#{ip}:#{port}"
|
574
|
+
end
|
575
|
+
end
|
576
|
+
|
577
|
+
def show_intro_message
|
578
|
+
puts "=============== Phusion Passenger Standalone web server started ==============="
|
579
|
+
puts "PID file: #{@options[:pid_file]}"
|
580
|
+
puts "Log file: #{@options[:log_file]}"
|
581
|
+
puts "Environment: #{@options[:environment]}"
|
582
|
+
puts "Accessible via: #{listen_url}"
|
583
|
+
|
584
|
+
puts
|
585
|
+
if @options[:daemonize]
|
586
|
+
puts "Serving in the background as a daemon."
|
587
|
+
else
|
588
|
+
puts "You can stop #{PROGRAM_NAME} Standalone by pressing Ctrl-C."
|
589
|
+
end
|
590
|
+
puts "Problems? Check #{STANDALONE_DOC_URL}#troubleshooting"
|
591
|
+
puts "==============================================================================="
|
592
|
+
end
|
593
|
+
|
594
|
+
def maybe_daemonize
|
595
|
+
if @options[:daemonize]
|
596
|
+
PhusionPassenger.require_passenger_lib 'platform_info/ruby'
|
597
|
+
if PlatformInfo.ruby_supports_fork?
|
598
|
+
daemonize
|
599
|
+
else
|
600
|
+
abort "Unable to daemonize using the current Ruby interpreter " +
|
601
|
+
"(#{PlatformInfo.ruby_command}) because it does not support forking."
|
602
|
+
end
|
603
|
+
end
|
604
|
+
end
|
605
|
+
|
606
|
+
def daemonize
|
607
|
+
pid = fork
|
608
|
+
if pid
|
609
|
+
# Parent
|
610
|
+
exit!(0)
|
611
|
+
else
|
612
|
+
# Child
|
613
|
+
trap "HUP", "IGNORE"
|
614
|
+
STDIN.reopen("/dev/null", "r")
|
615
|
+
STDOUT.reopen(@options[:log_file], "a")
|
616
|
+
STDERR.reopen(@options[:log_file], "a")
|
617
|
+
STDOUT.sync = true
|
618
|
+
STDERR.sync = true
|
619
|
+
Process.setsid
|
620
|
+
@threads.clear
|
621
|
+
end
|
622
|
+
end
|
623
|
+
|
624
|
+
def touch_temp_dir_in_background
|
625
|
+
result = system(@agent_exe,
|
626
|
+
"temp-dir-toucher",
|
627
|
+
@working_dir,
|
628
|
+
"--cleanup",
|
629
|
+
"--daemonize",
|
630
|
+
"--pid-file", "#{@working_dir}/temp_dir_toucher.pid",
|
631
|
+
"--log-file", @options[:log_file])
|
632
|
+
if !result
|
633
|
+
abort "Cannot start #{@agent_exe} temp-dir-toucher"
|
634
|
+
end
|
635
|
+
@can_remove_working_dir = false
|
636
|
+
end
|
637
|
+
|
638
|
+
def watch_log_file(log_file)
|
639
|
+
if File.exist?(log_file)
|
640
|
+
backward = 0
|
641
|
+
else
|
642
|
+
# tail bails out if the file doesn't exist, so wait until it exists.
|
643
|
+
while !File.exist?(log_file)
|
644
|
+
sleep 1
|
645
|
+
end
|
646
|
+
backward = 10
|
647
|
+
end
|
648
|
+
|
649
|
+
IO.popen("tail -f -n #{backward} \"#{log_file}\"", "rb") do |f|
|
650
|
+
begin
|
651
|
+
while true
|
652
|
+
begin
|
653
|
+
line = f.readline
|
654
|
+
@console_mutex.synchronize do
|
655
|
+
STDOUT.write(line)
|
656
|
+
STDOUT.flush
|
657
|
+
end
|
658
|
+
rescue EOFError
|
659
|
+
break
|
660
|
+
end
|
661
|
+
end
|
662
|
+
ensure
|
663
|
+
Process.kill('TERM', f.pid) rescue nil
|
664
|
+
end
|
665
|
+
end
|
666
|
+
end
|
667
|
+
|
668
|
+
def watch_log_files_in_background
|
669
|
+
@apps.each do |app|
|
670
|
+
thread = Utils.create_thread_and_abort_on_exception do
|
671
|
+
watch_log_file("#{app[:root]}/log/#{@options[:environment]}.log")
|
672
|
+
end
|
673
|
+
@threads << thread
|
674
|
+
@interruptable_threads << thread
|
675
|
+
end
|
676
|
+
thread = Utils.create_thread_and_abort_on_exception do
|
677
|
+
watch_log_file(@options[:log_file])
|
678
|
+
end
|
679
|
+
@threads << thread
|
680
|
+
@interruptable_threads << thread
|
681
|
+
end
|
682
|
+
|
683
|
+
def should_watch_logs?
|
684
|
+
return !@options[:daemonize] && @options[:log_file] != "/dev/null"
|
685
|
+
end
|
686
|
+
|
687
|
+
def should_wait_until_engine_has_exited?
|
688
|
+
return !@options[:daemonize] || @app_finder.multi_mode?
|
689
|
+
end
|
690
|
+
|
691
|
+
|
692
|
+
################## Shut down and cleanup ##################
|
693
|
+
|
694
|
+
def shutdown_and_cleanup(error_occurred)
|
695
|
+
# Stop engine
|
696
|
+
if @engine && (error_occurred || should_wait_until_engine_has_exited?)
|
697
|
+
@console_mutex.synchronize do
|
698
|
+
STDOUT.write("Stopping web server...")
|
699
|
+
STDOUT.flush
|
700
|
+
@engine.stop
|
701
|
+
STDOUT.puts " done"
|
702
|
+
STDOUT.flush
|
703
|
+
end
|
704
|
+
@engine = nil
|
705
|
+
end
|
706
|
+
|
707
|
+
# Stop threads
|
708
|
+
if @threads
|
709
|
+
if !@termination_pipe[1].closed?
|
710
|
+
@termination_pipe[1].write("x")
|
711
|
+
@termination_pipe[1].close
|
712
|
+
end
|
713
|
+
@interruptable_threads.each do |thread|
|
714
|
+
thread.terminate
|
715
|
+
end
|
716
|
+
@interruptable_threads = []
|
717
|
+
@threads.each do |thread|
|
718
|
+
thread.join
|
719
|
+
end
|
720
|
+
@threads = nil
|
721
|
+
end
|
722
|
+
|
723
|
+
if @can_remove_working_dir
|
724
|
+
FileUtils.remove_entry_secure(@working_dir)
|
725
|
+
@can_remove_working_dir = false
|
726
|
+
end
|
727
|
+
end
|
728
|
+
|
729
|
+
#################
|
730
|
+
end
|
731
|
+
|
732
|
+
end # module Standalone
|
721
733
|
end # module PhusionPassenger
|