passenger 5.0.0.beta3 → 5.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of passenger might be problematic. Click here for more details.

Files changed (218) hide show
  1. checksums.yaml +8 -8
  2. checksums.yaml.gz.asc +7 -7
  3. data.tar.gz.asc +7 -7
  4. data/.editorconfig +11 -5
  5. data/CHANGELOG +38 -0
  6. data/CONTRIBUTING.md +1 -4
  7. data/Gemfile +0 -1
  8. data/Gemfile.lock +0 -2
  9. data/Rakefile +33 -33
  10. data/bin/passenger +1 -1
  11. data/bin/passenger-config +1 -1
  12. data/bin/passenger-install-apache2-module +800 -800
  13. data/bin/passenger-install-nginx-module +592 -592
  14. data/bin/passenger-memory-stats +127 -127
  15. data/bin/passenger-status +216 -216
  16. data/build/agents.rb +127 -127
  17. data/build/apache2.rb +87 -87
  18. data/build/basics.rb +60 -60
  19. data/build/common_library.rb +165 -165
  20. data/build/cplusplus_support.rb +51 -51
  21. data/build/cxx_tests.rb +268 -268
  22. data/build/debian.rb +143 -143
  23. data/build/documentation.rb +58 -58
  24. data/build/integration_tests.rb +81 -81
  25. data/build/misc.rb +132 -132
  26. data/build/nginx.rb +20 -20
  27. data/build/node_tests.rb +7 -7
  28. data/build/oxt_tests.rb +14 -14
  29. data/build/packaging.rb +570 -570
  30. data/build/preprocessor.rb +260 -260
  31. data/build/rake_extensions.rb +71 -71
  32. data/build/ruby_extension.rb +29 -29
  33. data/build/ruby_tests.rb +6 -6
  34. data/build/test_basics.rb +37 -37
  35. data/debian.template/control.template +3 -5
  36. data/dev/copy_boost_headers +134 -134
  37. data/dev/install_scripts_bootstrap_code.rb +25 -25
  38. data/dev/list_tests +20 -20
  39. data/dev/ruby_server.rb +223 -223
  40. data/dev/runner +18 -18
  41. data/doc/ServerOptimizationGuide.txt.md +55 -2
  42. data/doc/Users guide Nginx.txt +0 -26
  43. data/doc/Users guide Standalone.txt +5 -1
  44. data/doc/users_guide_snippets/tips.txt +9 -0
  45. data/ext/common/ApplicationPool2/Group.h +23 -11
  46. data/ext/common/ApplicationPool2/Implementation.cpp +32 -7
  47. data/ext/common/ApplicationPool2/Pool.h +22 -17
  48. data/ext/common/ApplicationPool2/SmartSpawner.h +4 -1
  49. data/ext/common/ApplicationPool2/Spawner.h +1 -1
  50. data/ext/common/Constants.h +1 -1
  51. data/ext/common/agents/Base.cpp +35 -20
  52. data/ext/common/agents/HelperAgent/Main.cpp +8 -1
  53. data/ext/common/agents/HelperAgent/OptionParser.h +18 -4
  54. data/ext/common/agents/HelperAgent/RequestHandler.h +2 -83
  55. data/ext/common/agents/HelperAgent/RequestHandler/ForwardResponse.cpp +54 -1
  56. data/ext/common/agents/HelperAgent/RequestHandler/InitRequest.cpp +7 -4
  57. data/ext/common/agents/Main.cpp +1 -1
  58. data/ext/common/agents/Watchdog/Main.cpp +54 -19
  59. data/ext/nginx/Configuration.c +7 -0
  60. data/ext/nginx/ContentHandler.c +9 -1
  61. data/helper-scripts/backtrace-sanitizer.rb +106 -87
  62. data/helper-scripts/crash-watch.rb +32 -0
  63. data/helper-scripts/download_binaries/extconf.rb +38 -38
  64. data/helper-scripts/meteor-loader.rb +107 -107
  65. data/helper-scripts/prespawn +101 -101
  66. data/helper-scripts/rack-loader.rb +96 -96
  67. data/helper-scripts/rack-preloader.rb +137 -137
  68. data/lib/phusion_passenger.rb +292 -292
  69. data/lib/phusion_passenger/abstract_installer.rb +438 -438
  70. data/lib/phusion_passenger/active_support3_extensions/init.rb +168 -170
  71. data/lib/phusion_passenger/admin_tools.rb +20 -20
  72. data/lib/phusion_passenger/admin_tools/instance.rb +178 -178
  73. data/lib/phusion_passenger/admin_tools/instance_registry.rb +61 -61
  74. data/lib/phusion_passenger/admin_tools/memory_stats.rb +267 -267
  75. data/lib/phusion_passenger/apache2/config_options.rb +182 -182
  76. data/lib/phusion_passenger/common_library.rb +479 -485
  77. data/lib/phusion_passenger/config/about_command.rb +161 -161
  78. data/lib/phusion_passenger/config/admin_command_command.rb +129 -129
  79. data/lib/phusion_passenger/config/agent_compiler.rb +121 -121
  80. data/lib/phusion_passenger/config/build_native_support_command.rb +43 -43
  81. data/lib/phusion_passenger/config/command.rb +25 -25
  82. data/lib/phusion_passenger/config/compile_agent_command.rb +62 -62
  83. data/lib/phusion_passenger/config/compile_nginx_engine_command.rb +88 -73
  84. data/lib/phusion_passenger/config/detach_process_command.rb +72 -72
  85. data/lib/phusion_passenger/config/download_agent_command.rb +246 -227
  86. data/lib/phusion_passenger/config/download_nginx_engine_command.rb +245 -224
  87. data/lib/phusion_passenger/config/install_agent_command.rb +144 -132
  88. data/lib/phusion_passenger/config/install_standalone_runtime_command.rb +205 -185
  89. data/lib/phusion_passenger/config/installation_utils.rb +204 -204
  90. data/lib/phusion_passenger/config/list_instances_command.rb +64 -64
  91. data/lib/phusion_passenger/config/main.rb +152 -152
  92. data/lib/phusion_passenger/config/nginx_engine_compiler.rb +319 -300
  93. data/lib/phusion_passenger/config/reopen_logs_command.rb +67 -67
  94. data/lib/phusion_passenger/config/restart_app_command.rb +155 -155
  95. data/lib/phusion_passenger/config/system_metrics_command.rb +13 -13
  96. data/lib/phusion_passenger/config/utils.rb +95 -95
  97. data/lib/phusion_passenger/config/validate_install_command.rb +198 -198
  98. data/lib/phusion_passenger/console_text_template.rb +25 -25
  99. data/lib/phusion_passenger/constants.rb +90 -90
  100. data/lib/phusion_passenger/debug_logging.rb +106 -106
  101. data/lib/phusion_passenger/loader_shared_helpers.rb +447 -432
  102. data/lib/phusion_passenger/message_channel.rb +312 -312
  103. data/lib/phusion_passenger/message_client.rb +176 -176
  104. data/lib/phusion_passenger/native_support.rb +369 -369
  105. data/lib/phusion_passenger/nginx/config_options.rb +297 -297
  106. data/lib/phusion_passenger/packaging.rb +131 -131
  107. data/lib/phusion_passenger/platform_info.rb +360 -360
  108. data/lib/phusion_passenger/platform_info/apache.rb +767 -767
  109. data/lib/phusion_passenger/platform_info/apache_detector.rb +199 -199
  110. data/lib/phusion_passenger/platform_info/binary_compatibility.rb +107 -107
  111. data/lib/phusion_passenger/platform_info/compiler.rb +570 -570
  112. data/lib/phusion_passenger/platform_info/curl.rb +32 -32
  113. data/lib/phusion_passenger/platform_info/cxx_portability.rb +188 -188
  114. data/lib/phusion_passenger/platform_info/depcheck.rb +372 -372
  115. data/lib/phusion_passenger/platform_info/depcheck_specs/apache2.rb +109 -109
  116. data/lib/phusion_passenger/platform_info/depcheck_specs/compiler_toolchain.rb +4 -4
  117. data/lib/phusion_passenger/platform_info/depcheck_specs/gems.rb +10 -34
  118. data/lib/phusion_passenger/platform_info/depcheck_specs/libs.rb +101 -101
  119. data/lib/phusion_passenger/platform_info/depcheck_specs/ruby.rb +5 -5
  120. data/lib/phusion_passenger/platform_info/depcheck_specs/utilities.rb +13 -13
  121. data/lib/phusion_passenger/platform_info/linux.rb +55 -55
  122. data/lib/phusion_passenger/platform_info/operating_system.rb +149 -149
  123. data/lib/phusion_passenger/platform_info/ruby.rb +468 -448
  124. data/lib/phusion_passenger/platform_info/zlib.rb +9 -9
  125. data/lib/phusion_passenger/plugin.rb +66 -66
  126. data/lib/phusion_passenger/preloader_shared_helpers.rb +126 -126
  127. data/lib/phusion_passenger/public_api.rb +191 -191
  128. data/lib/phusion_passenger/rack/out_of_band_gc.rb +93 -94
  129. data/lib/phusion_passenger/rack/thread_handler_extension.rb +231 -227
  130. data/lib/phusion_passenger/request_handler.rb +567 -577
  131. data/lib/phusion_passenger/request_handler/thread_handler.rb +379 -381
  132. data/lib/phusion_passenger/ruby_core_enhancements.rb +86 -86
  133. data/lib/phusion_passenger/ruby_core_io_enhancements.rb +74 -74
  134. data/lib/phusion_passenger/simple_benchmarking.rb +25 -25
  135. data/lib/phusion_passenger/standalone/app_finder.rb +153 -150
  136. data/lib/phusion_passenger/standalone/command.rb +44 -40
  137. data/lib/phusion_passenger/standalone/config_utils.rb +53 -53
  138. data/lib/phusion_passenger/standalone/control_utils.rb +38 -59
  139. data/lib/phusion_passenger/standalone/main.rb +73 -73
  140. data/lib/phusion_passenger/standalone/start_command.rb +697 -685
  141. data/lib/phusion_passenger/standalone/start_command/builtin_engine.rb +193 -155
  142. data/lib/phusion_passenger/standalone/start_command/nginx_engine.rb +162 -133
  143. data/lib/phusion_passenger/standalone/status_command.rb +64 -64
  144. data/lib/phusion_passenger/standalone/stop_command.rb +72 -72
  145. data/lib/phusion_passenger/standalone/version_command.rb +9 -9
  146. data/lib/phusion_passenger/union_station/connection.rb +32 -32
  147. data/lib/phusion_passenger/union_station/core.rb +251 -251
  148. data/lib/phusion_passenger/union_station/transaction.rb +126 -126
  149. data/lib/phusion_passenger/utils.rb +199 -167
  150. data/lib/phusion_passenger/utils/ansi_colors.rb +128 -128
  151. data/lib/phusion_passenger/utils/download.rb +196 -196
  152. data/lib/phusion_passenger/utils/file_system_watcher.rb +158 -158
  153. data/lib/phusion_passenger/utils/hosts_file_parser.rb +101 -101
  154. data/lib/phusion_passenger/utils/lock.rb +31 -31
  155. data/lib/phusion_passenger/utils/native_support_utils.rb +31 -31
  156. data/lib/phusion_passenger/utils/progress_bar.rb +26 -26
  157. data/lib/phusion_passenger/utils/shellwords.rb +20 -20
  158. data/lib/phusion_passenger/utils/terminal_choice_menu.rb +206 -206
  159. data/lib/phusion_passenger/utils/unseekable_socket.rb +272 -272
  160. data/lib/phusion_passenger/vendor/crash_watch/app.rb +129 -0
  161. data/lib/phusion_passenger/vendor/crash_watch/gdb_controller.rb +341 -0
  162. data/lib/phusion_passenger/vendor/crash_watch/version.rb +24 -0
  163. data/lib/phusion_passenger/vendor/daemon_controller.rb +877 -0
  164. data/lib/phusion_passenger/vendor/daemon_controller/lock_file.rb +127 -0
  165. data/lib/phusion_passenger/vendor/daemon_controller/spawn.rb +26 -0
  166. data/lib/phusion_passenger/vendor/daemon_controller/version.rb +29 -0
  167. data/packaging/rpm/passenger_spec/passenger.spec.template +0 -1
  168. data/passenger.gemspec +0 -1
  169. data/resources/templates/config/nginx_engine_compiler/possible_solutions_for_download_and_extraction_problems.txt.erb +27 -0
  170. data/resources/templates/standalone/config.erb +19 -15
  171. data/test/integration_tests/apache2_tests.rb +566 -566
  172. data/test/integration_tests/downloaded_binaries_tests.rb +126 -125
  173. data/test/integration_tests/native_packaging_spec.rb +296 -296
  174. data/test/integration_tests/nginx_tests.rb +393 -393
  175. data/test/integration_tests/shared/example_webapp_tests.rb +282 -280
  176. data/test/integration_tests/source_packaging_test.rb +138 -138
  177. data/test/integration_tests/spec_helper.rb +5 -5
  178. data/test/integration_tests/standalone_tests.rb +367 -367
  179. data/test/ruby/debug_logging_spec.rb +133 -133
  180. data/test/ruby/message_channel_spec.rb +186 -186
  181. data/test/ruby/rack/loader_spec.rb +28 -28
  182. data/test/ruby/rack/preloader_spec.rb +34 -34
  183. data/test/ruby/rails3.0/loader_spec.rb +12 -12
  184. data/test/ruby/rails3.0/preloader_spec.rb +18 -18
  185. data/test/ruby/rails3.1/loader_spec.rb +12 -12
  186. data/test/ruby/rails3.1/preloader_spec.rb +18 -18
  187. data/test/ruby/rails3.2/loader_spec.rb +12 -12
  188. data/test/ruby/rails3.2/preloader_spec.rb +18 -18
  189. data/test/ruby/rails4.0/loader_spec.rb +12 -12
  190. data/test/ruby/rails4.0/preloader_spec.rb +18 -18
  191. data/test/ruby/rails4.1/loader_spec.rb +12 -12
  192. data/test/ruby/rails4.1/preloader_spec.rb +18 -18
  193. data/test/ruby/request_handler_spec.rb +730 -730
  194. data/test/ruby/shared/loader_sharedspec.rb +224 -224
  195. data/test/ruby/shared/rails/union_station_extensions_sharedspec.rb +327 -327
  196. data/test/ruby/shared/ruby_loader_sharedspec.rb +47 -47
  197. data/test/ruby/spec_helper.rb +65 -65
  198. data/test/ruby/standalone/runtime_installer_spec.rb +384 -384
  199. data/test/ruby/union_station_spec.rb +276 -276
  200. data/test/ruby/utils/file_system_watcher_spec.rb +220 -220
  201. data/test/ruby/utils/hosts_file_parser.rb +248 -248
  202. data/test/ruby/utils/tee_input_spec.rb +215 -215
  203. data/test/ruby/utils/unseekable_socket_spec.rb +57 -57
  204. data/test/ruby/utils_spec.rb +21 -21
  205. data/test/stub/rack/config.ru +87 -87
  206. data/test/stub/rack/library.rb +8 -8
  207. data/test/stub/rack/start.rb +30 -30
  208. data/test/support/apache2_controller.rb +191 -191
  209. data/test/support/nginx_controller.rb +90 -99
  210. data/test/support/placebo-preloader.rb +57 -57
  211. data/test/support/test_helper.rb +435 -435
  212. metadata +11 -21
  213. metadata.gz.asc +7 -7
  214. data/lib/phusion_passenger/standalone/command2.rb +0 -292
  215. data/lib/phusion_passenger/standalone/start2_command.rb +0 -799
  216. data/resources/templates/standalone/download_tool_missing.txt.erb +0 -18
  217. data/resources/templates/standalone/possible_solutions_for_download_and_extraction_problems.txt.erb +0 -17
  218. data/resources/templates/standalone/run_installer_as_root.txt.erb +0 -8
@@ -26,7 +26,7 @@
26
26
  source_root = File.expand_path("..", File.dirname(__FILE__))
27
27
  $LOAD_PATH.unshift("#{source_root}/lib")
28
28
  begin
29
- require 'rubygems'
29
+ require 'rubygems'
30
30
  rescue LoadError
31
31
  end
32
32
  require 'phusion_passenger'
@@ -43,613 +43,613 @@ PhusionPassenger.require_passenger_lib 'utils/terminal_choice_menu'
43
43
  PhusionPassenger.require_passenger_lib 'utils/tmpio'
44
44
 
45
45
  DOWNLOAD_OPTION = {
46
- :connect_timeout => 30,
47
- :idle_timeout => 30
46
+ :connect_timeout => 30,
47
+ :idle_timeout => 30
48
48
  }
49
49
 
50
50
  class Installer < PhusionPassenger::AbstractInstaller
51
- include PhusionPassenger
52
- TerminalChoiceMenu = PhusionPassenger::Utils::TerminalChoiceMenu
53
-
54
- def dependencies
55
- specs = [
56
- 'depcheck_specs/compiler_toolchain',
57
- 'depcheck_specs/ruby',
58
- 'depcheck_specs/gems',
59
- 'depcheck_specs/libs',
60
- 'depcheck_specs/utilities'
61
- ]
62
- ids = [
63
- 'cc',
64
- 'c++',
65
- 'download-tool',
66
- 'libcurl-dev',
67
- 'openssl-dev',
68
- 'zlib-dev',
69
- 'rake',
70
- 'ruby-openssl',
71
- 'rubygems'
72
- ]
73
- if @languages.include?("ruby")
74
- if PlatformInfo.passenger_needs_ruby_dev_header?
75
- ids << 'ruby-dev'
76
- end
77
- ids << 'rack'
78
- end
79
- return [specs, ids]
80
- end
81
-
82
- def users_guide_path
83
- return PhusionPassenger.nginx_doc_path
84
- end
85
-
86
- def users_guide_url
87
- return NGINX_DOC_URL
88
- end
89
-
90
- def run_steps
91
- # Make sure the configure script finds the correct
92
- # passenger-config command.
93
- ENV['PATH'] = PhusionPassenger.bin_dir + ":" + ENV['PATH']
94
-
95
- show_welcome_screen
96
- query_interested_languages
97
- check_gem_install_permission_problems || exit(1)
98
- check_directory_accessible_by_web_server
99
- check_nginx_module_sources_available || exit(1)
100
- check_dependencies || exit(1)
101
- if needs_compiling_support_files?
102
- check_whether_we_can_write_to(PhusionPassenger.build_system_dir) || exit(1)
103
- end
104
- check_whether_os_is_broken
105
- check_whether_system_has_enough_ram
106
-
107
- download_and_install = should_we_download_and_install_nginx_automatically?
108
- if pcre_is_installed?
109
- @pcre_source_dir = nil
110
- else
111
- @pcre_source_dir = download_and_extract_pcre
112
- end
113
- if download_and_install
114
- nginx_source_dir = download_and_extract_nginx
115
- if nginx_source_dir.nil?
116
- show_possible_solutions_for_download_and_extraction_problems
117
- exit(1)
118
- end
119
- nginx_prefix = ask_for_nginx_install_prefix
120
- check_whether_other_nginx_installations_exist(nginx_prefix)
121
- if @extra_configure_flags == "none"
122
- extra_nginx_configure_flags = nil
123
- else
124
- extra_nginx_configure_flags = @extra_configure_flags
125
- end
126
- else
127
- nginx_source_dir = ask_for_nginx_source_dir
128
- nginx_prefix = ask_for_nginx_install_prefix
129
- check_whether_other_nginx_installations_exist(nginx_prefix)
130
- extra_nginx_configure_flags = ask_for_extra_nginx_configure_flags(nginx_prefix)
131
- end
132
- check_whether_we_can_write_to(nginx_prefix) || exit(1)
133
- nginx_config_already_exists_before_installing = nginx_config_exists?(nginx_prefix)
134
- if needs_compiling_support_files?
135
- if !compile_passenger_support_files
136
- show_possible_solutions_for_compilation_and_installation_problems
137
- exit(1)
138
- end
139
- end
140
- if install_nginx(nginx_source_dir, nginx_prefix, extra_nginx_configure_flags)
141
- if nginx_config_already_exists_before_installing || !locate_nginx_config_file(nginx_prefix)
142
- show_passenger_config_snippets(nginx_prefix)
143
- else
144
- insert_passenger_config_snippets(nginx_prefix)
145
- end
146
- show_deployment_example
147
- else
148
- show_possible_solutions_for_compilation_and_installation_problems
149
- exit(1)
150
- end
151
- end
152
-
153
- def before_install
154
- super
155
- myself = `whoami`.strip
156
- @working_dir = PhusionPassenger::Utils.mktmpdir("passenger.", PlatformInfo.tmpexedir)
157
- end
158
-
159
- def after_install
160
- super
161
- FileUtils.remove_entry_secure(@working_dir) if @working_dir
162
- end
51
+ include PhusionPassenger
52
+ TerminalChoiceMenu = PhusionPassenger::Utils::TerminalChoiceMenu
53
+
54
+ def dependencies
55
+ specs = [
56
+ 'depcheck_specs/compiler_toolchain',
57
+ 'depcheck_specs/ruby',
58
+ 'depcheck_specs/gems',
59
+ 'depcheck_specs/libs',
60
+ 'depcheck_specs/utilities'
61
+ ]
62
+ ids = [
63
+ 'cc',
64
+ 'c++',
65
+ 'download-tool',
66
+ 'libcurl-dev',
67
+ 'openssl-dev',
68
+ 'zlib-dev',
69
+ 'rake',
70
+ 'ruby-openssl',
71
+ 'rubygems'
72
+ ]
73
+ if @languages.include?("ruby")
74
+ if PlatformInfo.passenger_needs_ruby_dev_header?
75
+ ids << 'ruby-dev'
76
+ end
77
+ ids << 'rack'
78
+ end
79
+ return [specs, ids]
80
+ end
81
+
82
+ def users_guide_path
83
+ return PhusionPassenger.nginx_doc_path
84
+ end
85
+
86
+ def users_guide_url
87
+ return NGINX_DOC_URL
88
+ end
89
+
90
+ def run_steps
91
+ # Make sure the configure script finds the correct
92
+ # passenger-config command.
93
+ ENV['PATH'] = PhusionPassenger.bin_dir + ":" + ENV['PATH']
94
+
95
+ show_welcome_screen
96
+ query_interested_languages
97
+ check_gem_install_permission_problems || exit(1)
98
+ check_directory_accessible_by_web_server
99
+ check_nginx_module_sources_available || exit(1)
100
+ check_dependencies || exit(1)
101
+ if needs_compiling_support_files?
102
+ check_whether_we_can_write_to(PhusionPassenger.build_system_dir) || exit(1)
103
+ end
104
+ check_whether_os_is_broken
105
+ check_whether_system_has_enough_ram
106
+
107
+ download_and_install = should_we_download_and_install_nginx_automatically?
108
+ if pcre_is_installed?
109
+ @pcre_source_dir = nil
110
+ else
111
+ @pcre_source_dir = download_and_extract_pcre
112
+ end
113
+ if download_and_install
114
+ nginx_source_dir = download_and_extract_nginx
115
+ if nginx_source_dir.nil?
116
+ show_possible_solutions_for_download_and_extraction_problems
117
+ exit(1)
118
+ end
119
+ nginx_prefix = ask_for_nginx_install_prefix
120
+ check_whether_other_nginx_installations_exist(nginx_prefix)
121
+ if @extra_configure_flags == "none"
122
+ extra_nginx_configure_flags = nil
123
+ else
124
+ extra_nginx_configure_flags = @extra_configure_flags
125
+ end
126
+ else
127
+ nginx_source_dir = ask_for_nginx_source_dir
128
+ nginx_prefix = ask_for_nginx_install_prefix
129
+ check_whether_other_nginx_installations_exist(nginx_prefix)
130
+ extra_nginx_configure_flags = ask_for_extra_nginx_configure_flags(nginx_prefix)
131
+ end
132
+ check_whether_we_can_write_to(nginx_prefix) || exit(1)
133
+ nginx_config_already_exists_before_installing = nginx_config_exists?(nginx_prefix)
134
+ if needs_compiling_support_files?
135
+ if !compile_passenger_support_files
136
+ show_possible_solutions_for_compilation_and_installation_problems
137
+ exit(1)
138
+ end
139
+ end
140
+ if install_nginx(nginx_source_dir, nginx_prefix, extra_nginx_configure_flags)
141
+ if nginx_config_already_exists_before_installing || !locate_nginx_config_file(nginx_prefix)
142
+ show_passenger_config_snippets(nginx_prefix)
143
+ else
144
+ insert_passenger_config_snippets(nginx_prefix)
145
+ end
146
+ show_deployment_example
147
+ else
148
+ show_possible_solutions_for_compilation_and_installation_problems
149
+ exit(1)
150
+ end
151
+ end
152
+
153
+ def before_install
154
+ super
155
+ myself = `whoami`.strip
156
+ @working_dir = PhusionPassenger::Utils.mktmpdir("passenger.", PlatformInfo.tmpexedir)
157
+ end
158
+
159
+ def after_install
160
+ super
161
+ FileUtils.remove_entry_secure(@working_dir) if @working_dir
162
+ end
163
163
 
164
164
  private
165
- def show_welcome_screen
166
- render_template 'nginx/welcome', :version => VERSION_STRING
167
- wait
168
- end
169
-
170
- def query_interested_languages
171
- menu = TerminalChoiceMenu.new(["Ruby", "Python", "Node.js", "Meteor"])
172
- menu["Ruby"].checked = interesting_language?('ruby')
173
- menu["Python"].checked = interesting_language?('python')
174
- menu["Node.js"].checked = interesting_language?('nodejs', 'node')
175
- menu["Meteor"].checked = interesting_language?('meteor')
176
-
177
- new_screen
178
- puts "<banner>Which languages are you interested in?</banner>"
179
- puts
180
- if interactive?
181
- puts "Use <space> to select."
182
- puts "<dgray>If the menu doesn't display correctly, press '!'</dgray>"
183
- else
184
- puts "Override selection with --languages."
185
- end
186
- puts
187
-
188
- if interactive?
189
- begin
190
- menu.query
191
- rescue Interrupt
192
- raise Abort
193
- end
194
- else
195
- menu.display_choices
196
- puts
197
- end
198
-
199
- @languages = menu.selected_choices.map{ |x| x.downcase.gsub(/\./, '') }
200
- end
201
-
202
- def interesting_language?(name, command = nil)
203
- if @languages
204
- return @languages.include?(name)
205
- else
206
- return !!PlatformInfo.find_command(command || name)
207
- end
208
- end
209
-
210
- def check_nginx_module_sources_available
211
- if PhusionPassenger.custom_packaged? &&
212
- (!PhusionPassenger.nginx_module_source_dir || !File.exist?(PhusionPassenger.nginx_module_source_dir))
213
- new_screen
214
- render_template 'nginx/nginx_module_sources_not_available'
215
- return false
216
- else
217
- return true
218
- end
219
- end
220
-
221
- def needs_compiling_support_files?
222
- return !PhusionPassenger.build_system_dir.nil?
223
- end
224
-
225
- def compile_passenger_support_files
226
- new_screen
227
- puts "<banner>Compiling Passenger support files...</banner>"
228
- Dir.chdir(PhusionPassenger.build_system_dir) do
229
- return sh("env NOEXEC_DISABLE=1 #{PlatformInfo.rake_command} nginx:clean nginx RELEASE=yes")
230
- end
231
- end
232
-
233
- def should_we_download_and_install_nginx_automatically?
234
- new_screen
235
- render_template 'nginx/query_download_and_install',
236
- :nginx_version => PREFERRED_NGINX_VERSION
237
- puts
238
-
239
- if @auto_download
240
- puts "<b>=> Proceeding with choice 1.</b>"
241
- return true
242
- elsif @nginx_source_dir
243
- puts "<b>=> Proceeding with choice 2.</b>"
244
- return false
245
- elsif @auto
246
- puts "<b>=> Proceeding with choice 1.</b>"
247
- return true
248
- else
249
- choice = prompt("Enter your choice (1 or 2) or press Ctrl-C to abort") do |input|
250
- if input == "1" || input == "2"
251
- true
252
- elsif input.empty?
253
- puts "<red>No choice has been given.</red>"
254
- false
255
- else
256
- puts "<red>'#{input}' is not a valid choice.</red>"
257
- false
258
- end
259
- end
260
- return choice == "1"
261
- end
262
- end
263
-
264
- def download_and_extract_pcre
265
- new_screen
266
- puts "<banner>PCRE (required by Nginx) not installed, downloading it...</banner>"
267
-
268
- url = "http://downloads.sourceforge.net/project/pcre/pcre/#{PREFERRED_PCRE_VERSION}/pcre-#{PREFERRED_PCRE_VERSION}.tar.gz"
269
- dirname = "pcre-#{PREFERRED_PCRE_VERSION}"
270
- tarball = "#{@working_dir}/pcre.tar.gz"
271
-
272
- if download(url, tarball, DOWNLOAD_OPTION)
273
- Dir.chdir(@working_dir) do
274
- puts "<banner>Verifying PCRE checksum...</banner>"
275
- if sha256_file(tarball) != PCRE_SHA256_CHECKSUM
276
- new_screen
277
- render_template "nginx/pcre_checksum_could_not_be_verified"
278
- wait
279
- return nil
280
- end
281
-
282
- puts "<banner>Extracting PCRE source tarball...</banner>"
283
- if sh("tar", "xzvf", tarball)
284
- return "#{@working_dir}/#{dirname}"
285
- else
286
- new_screen
287
- render_template "nginx/pcre_could_not_be_extracted"
288
- wait
289
- return nil
290
- end
291
- end
292
- else
293
- new_screen
294
- render_template "nginx/pcre_could_not_be_downloaded"
295
- wait
296
- return nil
297
- end
298
- rescue Interrupt
299
- exit 2
300
- end
301
-
302
- def download_and_extract_nginx
303
- new_screen
304
- puts "<banner>Downloading Nginx...</banner>"
305
-
306
- url = "http://www.nginx.org/download/nginx-#{PREFERRED_NGINX_VERSION}.tar.gz"
307
- dirname = "nginx-#{PREFERRED_NGINX_VERSION}"
308
- tarball = "#{@working_dir}/nginx.tar.gz"
309
-
310
- if download(url, tarball, DOWNLOAD_OPTION)
311
- Dir.chdir(@working_dir) do
312
- puts "<banner>Verifying Nginx checksum...</banner>"
313
- if sha256_file(tarball) != NGINX_SHA256_CHECKSUM
314
- return nil
315
- end
316
-
317
- puts "<banner>Extracting Nginx source tarball...</banner>"
318
- if sh("tar", "xzvf", tarball)
319
- return "#{@working_dir}/#{dirname}"
320
- else
321
- return nil
322
- end
323
- end
324
- else
325
- return nil
326
- end
327
- rescue Interrupt
328
- exit 2
329
- end
330
-
331
- def show_possible_solutions_for_download_and_extraction_problems
332
- new_screen
333
- render_template "nginx/possible_solutions_for_download_and_extraction_problems"
334
- puts
335
- end
336
-
337
- def ask_for_nginx_install_prefix
338
- new_screen
339
- puts "<banner>Where do you want to install Nginx to?</banner>"
340
- puts
341
- if @prefix
342
- puts "<b>=> #{@prefix}</b>"
343
- return @prefix
344
- elsif @auto
345
- puts "<b>=> /opt/nginx</b>"
346
- return "/opt/nginx"
347
- else
348
- prefix = prompt("Please specify a prefix directory [/opt/nginx]") do |input|
349
- if input.empty? || input =~ %r(/)
350
- true
351
- else
352
- puts "<red>Please specify an absolute path.</red>"
353
- false
354
- end
355
- end
356
- if prefix.empty?
357
- prefix = "/opt/nginx"
358
- end
359
- return prefix
360
- end
361
- end
362
-
363
- def check_whether_other_nginx_installations_exist(nginx_prefix)
364
- check_for = [
365
- "/usr/bin/nginx",
366
- "/usr/sbin/nginx"
367
- ]
368
- existing_binary = nil
369
- check_for.each do |filename|
370
- if File.exist?(filename)
371
- existing_binary = filename
372
- break
373
- end
374
- end
375
- if existing_binary
376
- new_screen
377
- render_template 'nginx/other_nginx_installations_exist',
378
- :existing_binary => existing_binary,
379
- :prefix => nginx_prefix
380
- wait
381
- end
382
- end
383
-
384
- def ask_for_nginx_source_dir
385
- new_screen
386
- puts "<banner>Where is your Nginx source code located?</banner>"
387
- puts
388
- if @nginx_source_dir
389
- puts "<b>=> #{@nginx_source_dir}</b>"
390
- return @nginx_source_dir
391
- else
392
- return prompt("Please specify the directory") do |input|
393
- if input =~ %r(/)
394
- if File.exist?("#{input}/src/core/nginx.c")
395
- true
396
- else
397
- puts "<red>'#{input}' does not look like an Nginx source directory.</red>"
398
- false
399
- end
400
- else
401
- puts "<red>Please specify an absolute path.</red>"
402
- false
403
- end
404
- end
405
- end
406
- end
407
-
408
- def ask_for_extra_nginx_configure_flags(prefix)
409
- done = false
410
- while !done
411
- new_screen
412
- render_template 'nginx/ask_for_extra_configure_flags',
413
- :command => build_nginx_configure_command(prefix)
414
- puts
415
- if @extra_configure_flags
416
- if @extra_configure_flags == "none"
417
- extra_args = ""
418
- puts "<b>=> No extra configure flags.</b>"
419
- else
420
- extra_args = @extra_configure_flags
421
- puts "<b>=> #{extra_args}</b>"
422
- end
423
- return extra_args
424
- elsif @auto
425
- puts "<b>=> No extra configure flags.</b>"
426
- return ""
427
- else
428
- extra_args = prompt "Extra arguments to pass to configure script"
429
-
430
- new_screen
431
- render_template 'nginx/confirm_extra_configure_flags',
432
- :command => build_nginx_configure_command(prefix, extra_args)
433
- puts
434
- answer = prompt("Is this what you want? (yes/no) [default=yes]") do |input|
435
- if input.empty? || input == "yes" || input == "no"
436
- true
437
- else
438
- puts "<red>Please enter 'yes' or 'no'.</red>"
439
- false
440
- end
441
- end
442
- done = answer.empty? || answer == "yes"
443
- end
444
- end
445
- return extra_args
446
- end
447
-
448
- def check_whether_we_can_write_to(dir)
449
- FileUtils.mkdir_p(dir)
450
- File.new("#{dir}/__test__.txt", "w").close
451
- return true
452
- rescue
453
- new_screen
454
- if Process.uid == 0
455
- render_template 'nginx/cannot_write_to_dir', :dir => dir
456
- else
457
- render_template 'installer_common/run_installer_as_root',
458
- :dir => dir,
459
- :sudo => PhusionPassenger::PlatformInfo.ruby_sudo_command,
460
- :sudo_s_e => PhusionPassenger::PlatformInfo.ruby_sudo_shell_command("-E"),
461
- :ruby => PhusionPassenger::PlatformInfo.ruby_command,
462
- :installer => "#{PhusionPassenger.bin_dir}/passenger-install-nginx-module #{ORIG_ARGV.join(' ')}"
463
- end
464
- return false
465
- ensure
466
- File.unlink("#{dir}/__test__.txt") rescue nil
467
- end
468
-
469
- def nginx_config_exists?(prefix)
470
- return !!locate_nginx_config_file(prefix)
471
- end
472
-
473
- def install_nginx(source_dir, prefix, extra_configure_flags)
474
- Dir.chdir(source_dir) do
475
- new_screen
476
- puts "<banner>Compiling and installing Nginx...</banner>"
477
- if !sh(build_nginx_configure_command(prefix, extra_configure_flags)) ||
478
- !sh("make") ||
479
- !sh("make install")
480
- return false
481
- end
482
- end
483
- return true
484
- rescue Interrupt
485
- raise Aborted
486
- end
487
-
488
- def show_passenger_config_snippets(prefix)
489
- new_screen
490
- render_template 'nginx/config_snippets',
491
- :config_file => locate_nginx_config_file(prefix),
492
- :passenger_root => PhusionPassenger.install_spec,
493
- :ruby => PlatformInfo.ruby_command
494
- wait
495
- end
496
-
497
- def show_deployment_example
498
- line
499
- puts
500
- render_template 'nginx/deployment_example',
501
- :users_guide_path => users_guide_path,
502
- :users_guide_url => users_guide_url,
503
- :phusion_website => PHUSION_WEBSITE,
504
- :passenger_website => PASSENGER_WEBSITE
505
- end
506
-
507
- def show_possible_solutions_for_compilation_and_installation_problems
508
- line
509
- puts
510
- render_template 'nginx/possible_solutions_for_compilation_and_installation_problems',
511
- :users_guide_path => users_guide_path,
512
- :users_guide_url => users_guide_url,
513
- :support_url => SUPPORT_URL
514
- end
515
-
516
- def locate_nginx_config_file(prefix)
517
- ["#{prefix}/conf/nginx.conf", "#{prefix}/etc/nginx.conf"].each do |filename|
518
- if File.exist?(filename)
519
- return filename
520
- end
521
- end
522
- return nil
523
- end
524
-
525
- def insert_passenger_config_snippets(prefix)
526
- config_file = locate_nginx_config_file(prefix)
527
- contents = File.read(config_file)
528
- contents.sub!(/^http \{/,
529
- "http {\n" <<
530
- " passenger_root #{PhusionPassenger.install_spec};\n" <<
531
- " passenger_ruby #{PlatformInfo.ruby_command};\n")
532
- File.open(config_file, 'w') do |f|
533
- f.write(contents)
534
- end
535
-
536
- new_screen
537
- render_template 'nginx/config_snippets_inserted',
538
- :config_file => config_file,
539
- :passenger_root => PhusionPassenger.install_spec,
540
- :ruby => PlatformInfo.ruby_command
541
- wait
542
- end
543
-
544
- def build_nginx_configure_command(prefix, extra_configure_flags = nil)
545
- command = "sh ./configure --prefix='#{prefix}' "
546
- command << "--with-http_ssl_module "
547
- command << "--with-http_gzip_static_module "
548
- command << "--with-http_stub_status_module "
549
- command << "--with-cc-opt='-Wno-error' "
550
- if @pcre_source_dir
551
- command << "--with-pcre='#{@pcre_source_dir}' "
552
- elsif !pcre_is_installed?
553
- command << "--without-http_rewrite_module "
554
- end
555
- command << "--add-module='#{PhusionPassenger.nginx_module_source_dir}' #{extra_configure_flags}"
556
- command.strip!
557
- return command
558
- end
559
-
560
- def pcre_is_installed?
561
- if @pcre_is_installed.nil?
562
- @pcre_is_installed = begin
563
- File.open('/tmp/passenger-check.c', 'w') do |f|
564
- f.puts("#include <pcre.h>")
565
- end
566
- Dir.chdir('/tmp') do
567
- # Nginx checks for PCRE in multiple places...
568
- system("(gcc -I/usr/local/include -I/usr/include/pcre " <<
569
- "-I/usr/pkg/include -I/opt/local/include " <<
570
- "-c passenger-check.c) >/dev/null 2>/dev/null")
571
- end
572
- ensure
573
- File.unlink('/tmp/passenger-check.c') rescue nil
574
- File.unlink('/tmp/passenger-check.o') rescue nil
575
- end
576
- end
577
- return @pcre_is_installed
578
- end
579
-
580
- def sha256_file(path)
581
- # We do this instead of using #file, for Ruby 1.8.5 support.
582
- digest = Digest::SHA256.new
583
- File.open(path, "rb") do |f|
584
- buf = ''
585
- buf.force_encoding('binary') if buf.respond_to?(:force_encoding)
586
- while !f.eof?
587
- f.read(1024 * 16, buf)
588
- digest.update(buf)
589
- end
590
- end
591
- return digest.hexdigest
592
- end
165
+ def show_welcome_screen
166
+ render_template 'nginx/welcome', :version => VERSION_STRING
167
+ wait
168
+ end
169
+
170
+ def query_interested_languages
171
+ menu = TerminalChoiceMenu.new(["Ruby", "Python", "Node.js", "Meteor"])
172
+ menu["Ruby"].checked = interesting_language?('ruby')
173
+ menu["Python"].checked = interesting_language?('python')
174
+ menu["Node.js"].checked = interesting_language?('nodejs', 'node')
175
+ menu["Meteor"].checked = interesting_language?('meteor')
176
+
177
+ new_screen
178
+ puts "<banner>Which languages are you interested in?</banner>"
179
+ puts
180
+ if interactive?
181
+ puts "Use <space> to select."
182
+ puts "<dgray>If the menu doesn't display correctly, press '!'</dgray>"
183
+ else
184
+ puts "Override selection with --languages."
185
+ end
186
+ puts
187
+
188
+ if interactive?
189
+ begin
190
+ menu.query
191
+ rescue Interrupt
192
+ raise Abort
193
+ end
194
+ else
195
+ menu.display_choices
196
+ puts
197
+ end
198
+
199
+ @languages = menu.selected_choices.map{ |x| x.downcase.gsub(/\./, '') }
200
+ end
201
+
202
+ def interesting_language?(name, command = nil)
203
+ if @languages
204
+ return @languages.include?(name)
205
+ else
206
+ return !!PlatformInfo.find_command(command || name)
207
+ end
208
+ end
209
+
210
+ def check_nginx_module_sources_available
211
+ if PhusionPassenger.custom_packaged? &&
212
+ (!PhusionPassenger.nginx_module_source_dir || !File.exist?(PhusionPassenger.nginx_module_source_dir))
213
+ new_screen
214
+ render_template 'nginx/nginx_module_sources_not_available'
215
+ return false
216
+ else
217
+ return true
218
+ end
219
+ end
220
+
221
+ def needs_compiling_support_files?
222
+ return !PhusionPassenger.build_system_dir.nil?
223
+ end
224
+
225
+ def compile_passenger_support_files
226
+ new_screen
227
+ puts "<banner>Compiling Passenger support files...</banner>"
228
+ Dir.chdir(PhusionPassenger.build_system_dir) do
229
+ return sh("env NOEXEC_DISABLE=1 #{PlatformInfo.rake_command} nginx:clean nginx RELEASE=yes")
230
+ end
231
+ end
232
+
233
+ def should_we_download_and_install_nginx_automatically?
234
+ new_screen
235
+ render_template 'nginx/query_download_and_install',
236
+ :nginx_version => PREFERRED_NGINX_VERSION
237
+ puts
238
+
239
+ if @auto_download
240
+ puts "<b>=> Proceeding with choice 1.</b>"
241
+ return true
242
+ elsif @nginx_source_dir
243
+ puts "<b>=> Proceeding with choice 2.</b>"
244
+ return false
245
+ elsif @auto
246
+ puts "<b>=> Proceeding with choice 1.</b>"
247
+ return true
248
+ else
249
+ choice = prompt("Enter your choice (1 or 2) or press Ctrl-C to abort") do |input|
250
+ if input == "1" || input == "2"
251
+ true
252
+ elsif input.empty?
253
+ puts "<red>No choice has been given.</red>"
254
+ false
255
+ else
256
+ puts "<red>'#{input}' is not a valid choice.</red>"
257
+ false
258
+ end
259
+ end
260
+ return choice == "1"
261
+ end
262
+ end
263
+
264
+ def download_and_extract_pcre
265
+ new_screen
266
+ puts "<banner>PCRE (required by Nginx) not installed, downloading it...</banner>"
267
+
268
+ url = "http://downloads.sourceforge.net/project/pcre/pcre/#{PREFERRED_PCRE_VERSION}/pcre-#{PREFERRED_PCRE_VERSION}.tar.gz"
269
+ dirname = "pcre-#{PREFERRED_PCRE_VERSION}"
270
+ tarball = "#{@working_dir}/pcre.tar.gz"
271
+
272
+ if download(url, tarball, DOWNLOAD_OPTION)
273
+ Dir.chdir(@working_dir) do
274
+ puts "<banner>Verifying PCRE checksum...</banner>"
275
+ if sha256_file(tarball) != PCRE_SHA256_CHECKSUM
276
+ new_screen
277
+ render_template "nginx/pcre_checksum_could_not_be_verified"
278
+ wait
279
+ return nil
280
+ end
281
+
282
+ puts "<banner>Extracting PCRE source tarball...</banner>"
283
+ if sh("tar", "xzvf", tarball)
284
+ return "#{@working_dir}/#{dirname}"
285
+ else
286
+ new_screen
287
+ render_template "nginx/pcre_could_not_be_extracted"
288
+ wait
289
+ return nil
290
+ end
291
+ end
292
+ else
293
+ new_screen
294
+ render_template "nginx/pcre_could_not_be_downloaded"
295
+ wait
296
+ return nil
297
+ end
298
+ rescue Interrupt
299
+ exit 2
300
+ end
301
+
302
+ def download_and_extract_nginx
303
+ new_screen
304
+ puts "<banner>Downloading Nginx...</banner>"
305
+
306
+ url = "http://www.nginx.org/download/nginx-#{PREFERRED_NGINX_VERSION}.tar.gz"
307
+ dirname = "nginx-#{PREFERRED_NGINX_VERSION}"
308
+ tarball = "#{@working_dir}/nginx.tar.gz"
309
+
310
+ if download(url, tarball, DOWNLOAD_OPTION)
311
+ Dir.chdir(@working_dir) do
312
+ puts "<banner>Verifying Nginx checksum...</banner>"
313
+ if sha256_file(tarball) != NGINX_SHA256_CHECKSUM
314
+ return nil
315
+ end
316
+
317
+ puts "<banner>Extracting Nginx source tarball...</banner>"
318
+ if sh("tar", "xzvf", tarball)
319
+ return "#{@working_dir}/#{dirname}"
320
+ else
321
+ return nil
322
+ end
323
+ end
324
+ else
325
+ return nil
326
+ end
327
+ rescue Interrupt
328
+ exit 2
329
+ end
330
+
331
+ def show_possible_solutions_for_download_and_extraction_problems
332
+ new_screen
333
+ render_template "nginx/possible_solutions_for_download_and_extraction_problems"
334
+ puts
335
+ end
336
+
337
+ def ask_for_nginx_install_prefix
338
+ new_screen
339
+ puts "<banner>Where do you want to install Nginx to?</banner>"
340
+ puts
341
+ if @prefix
342
+ puts "<b>=> #{@prefix}</b>"
343
+ return @prefix
344
+ elsif @auto
345
+ puts "<b>=> /opt/nginx</b>"
346
+ return "/opt/nginx"
347
+ else
348
+ prefix = prompt("Please specify a prefix directory [/opt/nginx]") do |input|
349
+ if input.empty? || input =~ %r(/)
350
+ true
351
+ else
352
+ puts "<red>Please specify an absolute path.</red>"
353
+ false
354
+ end
355
+ end
356
+ if prefix.empty?
357
+ prefix = "/opt/nginx"
358
+ end
359
+ return prefix
360
+ end
361
+ end
362
+
363
+ def check_whether_other_nginx_installations_exist(nginx_prefix)
364
+ check_for = [
365
+ "/usr/bin/nginx",
366
+ "/usr/sbin/nginx"
367
+ ]
368
+ existing_binary = nil
369
+ check_for.each do |filename|
370
+ if File.exist?(filename)
371
+ existing_binary = filename
372
+ break
373
+ end
374
+ end
375
+ if existing_binary
376
+ new_screen
377
+ render_template 'nginx/other_nginx_installations_exist',
378
+ :existing_binary => existing_binary,
379
+ :prefix => nginx_prefix
380
+ wait
381
+ end
382
+ end
383
+
384
+ def ask_for_nginx_source_dir
385
+ new_screen
386
+ puts "<banner>Where is your Nginx source code located?</banner>"
387
+ puts
388
+ if @nginx_source_dir
389
+ puts "<b>=> #{@nginx_source_dir}</b>"
390
+ return @nginx_source_dir
391
+ else
392
+ return prompt("Please specify the directory") do |input|
393
+ if input =~ %r(/)
394
+ if File.exist?("#{input}/src/core/nginx.c")
395
+ true
396
+ else
397
+ puts "<red>'#{input}' does not look like an Nginx source directory.</red>"
398
+ false
399
+ end
400
+ else
401
+ puts "<red>Please specify an absolute path.</red>"
402
+ false
403
+ end
404
+ end
405
+ end
406
+ end
407
+
408
+ def ask_for_extra_nginx_configure_flags(prefix)
409
+ done = false
410
+ while !done
411
+ new_screen
412
+ render_template 'nginx/ask_for_extra_configure_flags',
413
+ :command => build_nginx_configure_command(prefix)
414
+ puts
415
+ if @extra_configure_flags
416
+ if @extra_configure_flags == "none"
417
+ extra_args = ""
418
+ puts "<b>=> No extra configure flags.</b>"
419
+ else
420
+ extra_args = @extra_configure_flags
421
+ puts "<b>=> #{extra_args}</b>"
422
+ end
423
+ return extra_args
424
+ elsif @auto
425
+ puts "<b>=> No extra configure flags.</b>"
426
+ return ""
427
+ else
428
+ extra_args = prompt "Extra arguments to pass to configure script"
429
+
430
+ new_screen
431
+ render_template 'nginx/confirm_extra_configure_flags',
432
+ :command => build_nginx_configure_command(prefix, extra_args)
433
+ puts
434
+ answer = prompt("Is this what you want? (yes/no) [default=yes]") do |input|
435
+ if input.empty? || input == "yes" || input == "no"
436
+ true
437
+ else
438
+ puts "<red>Please enter 'yes' or 'no'.</red>"
439
+ false
440
+ end
441
+ end
442
+ done = answer.empty? || answer == "yes"
443
+ end
444
+ end
445
+ return extra_args
446
+ end
447
+
448
+ def check_whether_we_can_write_to(dir)
449
+ FileUtils.mkdir_p(dir)
450
+ File.new("#{dir}/__test__.txt", "w").close
451
+ return true
452
+ rescue
453
+ new_screen
454
+ if Process.uid == 0
455
+ render_template 'nginx/cannot_write_to_dir', :dir => dir
456
+ else
457
+ render_template 'installer_common/run_installer_as_root',
458
+ :dir => dir,
459
+ :sudo => PhusionPassenger::PlatformInfo.ruby_sudo_command,
460
+ :sudo_s_e => PhusionPassenger::PlatformInfo.ruby_sudo_shell_command("-E"),
461
+ :ruby => PhusionPassenger::PlatformInfo.ruby_command,
462
+ :installer => "#{PhusionPassenger.bin_dir}/passenger-install-nginx-module #{ORIG_ARGV.join(' ')}"
463
+ end
464
+ return false
465
+ ensure
466
+ File.unlink("#{dir}/__test__.txt") rescue nil
467
+ end
468
+
469
+ def nginx_config_exists?(prefix)
470
+ return !!locate_nginx_config_file(prefix)
471
+ end
472
+
473
+ def install_nginx(source_dir, prefix, extra_configure_flags)
474
+ Dir.chdir(source_dir) do
475
+ new_screen
476
+ puts "<banner>Compiling and installing Nginx...</banner>"
477
+ if !sh(build_nginx_configure_command(prefix, extra_configure_flags)) ||
478
+ !sh("make") ||
479
+ !sh("make install")
480
+ return false
481
+ end
482
+ end
483
+ return true
484
+ rescue Interrupt
485
+ raise Aborted
486
+ end
487
+
488
+ def show_passenger_config_snippets(prefix)
489
+ new_screen
490
+ render_template 'nginx/config_snippets',
491
+ :config_file => locate_nginx_config_file(prefix),
492
+ :passenger_root => PhusionPassenger.install_spec,
493
+ :ruby => PlatformInfo.ruby_command
494
+ wait
495
+ end
496
+
497
+ def show_deployment_example
498
+ line
499
+ puts
500
+ render_template 'nginx/deployment_example',
501
+ :users_guide_path => users_guide_path,
502
+ :users_guide_url => users_guide_url,
503
+ :phusion_website => PHUSION_WEBSITE,
504
+ :passenger_website => PASSENGER_WEBSITE
505
+ end
506
+
507
+ def show_possible_solutions_for_compilation_and_installation_problems
508
+ line
509
+ puts
510
+ render_template 'nginx/possible_solutions_for_compilation_and_installation_problems',
511
+ :users_guide_path => users_guide_path,
512
+ :users_guide_url => users_guide_url,
513
+ :support_url => SUPPORT_URL
514
+ end
515
+
516
+ def locate_nginx_config_file(prefix)
517
+ ["#{prefix}/conf/nginx.conf", "#{prefix}/etc/nginx.conf"].each do |filename|
518
+ if File.exist?(filename)
519
+ return filename
520
+ end
521
+ end
522
+ return nil
523
+ end
524
+
525
+ def insert_passenger_config_snippets(prefix)
526
+ config_file = locate_nginx_config_file(prefix)
527
+ contents = File.read(config_file)
528
+ contents.sub!(/^http \{/,
529
+ "http {\n" <<
530
+ " passenger_root #{PhusionPassenger.install_spec};\n" <<
531
+ " passenger_ruby #{PlatformInfo.ruby_command};\n")
532
+ File.open(config_file, 'w') do |f|
533
+ f.write(contents)
534
+ end
535
+
536
+ new_screen
537
+ render_template 'nginx/config_snippets_inserted',
538
+ :config_file => config_file,
539
+ :passenger_root => PhusionPassenger.install_spec,
540
+ :ruby => PlatformInfo.ruby_command
541
+ wait
542
+ end
543
+
544
+ def build_nginx_configure_command(prefix, extra_configure_flags = nil)
545
+ command = "sh ./configure --prefix='#{prefix}' "
546
+ command << "--with-http_ssl_module "
547
+ command << "--with-http_gzip_static_module "
548
+ command << "--with-http_stub_status_module "
549
+ command << "--with-cc-opt='-Wno-error' "
550
+ if @pcre_source_dir
551
+ command << "--with-pcre='#{@pcre_source_dir}' "
552
+ elsif !pcre_is_installed?
553
+ command << "--without-http_rewrite_module "
554
+ end
555
+ command << "--add-module='#{PhusionPassenger.nginx_module_source_dir}' #{extra_configure_flags}"
556
+ command.strip!
557
+ return command
558
+ end
559
+
560
+ def pcre_is_installed?
561
+ if @pcre_is_installed.nil?
562
+ @pcre_is_installed = begin
563
+ File.open('/tmp/passenger-check.c', 'w') do |f|
564
+ f.puts("#include <pcre.h>")
565
+ end
566
+ Dir.chdir('/tmp') do
567
+ # Nginx checks for PCRE in multiple places...
568
+ system("(gcc -I/usr/local/include -I/usr/include/pcre " <<
569
+ "-I/usr/pkg/include -I/opt/local/include " <<
570
+ "-c passenger-check.c) >/dev/null 2>/dev/null")
571
+ end
572
+ ensure
573
+ File.unlink('/tmp/passenger-check.c') rescue nil
574
+ File.unlink('/tmp/passenger-check.o') rescue nil
575
+ end
576
+ end
577
+ return @pcre_is_installed
578
+ end
579
+
580
+ def sha256_file(path)
581
+ # We do this instead of using #file, for Ruby 1.8.5 support.
582
+ digest = Digest::SHA256.new
583
+ File.open(path, "rb") do |f|
584
+ buf = ''
585
+ buf.force_encoding('binary') if buf.respond_to?(:force_encoding)
586
+ while !f.eof?
587
+ f.read(1024 * 16, buf)
588
+ digest.update(buf)
589
+ end
590
+ end
591
+ return digest.hexdigest
592
+ end
593
593
  end
594
594
 
595
595
  ORIG_ARGV = ARGV.dup
596
596
  options = {}
597
597
  parser = OptionParser.new do |opts|
598
- opts.banner = "Usage: passenger-install-nginx-module [options]"
599
- opts.separator ""
600
-
601
- indent = ' ' * 37
602
- opts.separator "Options:"
603
- opts.on("--auto", "Automatically confirm 'Press ENTER to\n" <<
604
- "#{indent}continue' prompts.") do
605
- options[:auto] = true
606
- end
607
- opts.on("--prefix=DIR", String, "Use the given Nginx install prefix instead\n" <<
608
- "#{indent}of asking for it interactively.") do |dir|
609
- options[:prefix] = dir
610
- end
611
- opts.on("--auto-download", "Download and install Nginx automatically,\n" <<
612
- "#{indent}instead of asking interactively whether to\n" <<
613
- "#{indent}download+install or to use an existing\n" <<
614
- "#{indent}Nginx source directory.") do
615
- options[:auto_download] = true
616
- end
617
- opts.on("--nginx-source-dir=DIR", String, "Compile and install Nginx using the given\n" <<
618
- "#{indent}Nginx source directory, instead of\n" <<
619
- "#{indent}interactively asking to download+install\n" <<
620
- "#{indent}or to use an existing Nginx source\n" <<
621
- "#{indent}directory. Conflicts with --auto-download.") do |dir|
622
- options[:nginx_source_dir] = dir
623
- end
624
- opts.on("--extra-configure-flags=STRING", String, "Pass these extra flags to Nginx's\n" <<
625
- "#{indent}'configure' script, instead of asking for\n" <<
626
- "#{indent}it interactively. Specify 'none' if you\n" <<
627
- "#{indent}do not want to pass additional flags but do\n" <<
628
- "#{indent}not want this installer to ask\n" <<
629
- "#{indent}interactively either.") do |flags|
630
- options[:extra_configure_flags] = flags
631
- end
632
- opts.on("--languages NAMES", "Comma-separated list of interested\n" <<
633
- "#{indent}languages (e.g.\n" <<
634
- "#{indent}'ruby,python,nodejs,meteor')") do |value|
635
- options[:languages] = value.split(",")
636
- end
637
- opts.on("--force-colors", "Display colors even if stdout is not a TTY") do
638
- options[:colorize] = true
639
- end
598
+ opts.banner = "Usage: passenger-install-nginx-module [options]"
599
+ opts.separator ""
600
+
601
+ indent = ' ' * 37
602
+ opts.separator "Options:"
603
+ opts.on("--auto", "Automatically confirm 'Press ENTER to\n" <<
604
+ "#{indent}continue' prompts.") do
605
+ options[:auto] = true
606
+ end
607
+ opts.on("--prefix=DIR", String, "Use the given Nginx install prefix instead\n" <<
608
+ "#{indent}of asking for it interactively.") do |dir|
609
+ options[:prefix] = dir
610
+ end
611
+ opts.on("--auto-download", "Download and install Nginx automatically,\n" <<
612
+ "#{indent}instead of asking interactively whether to\n" <<
613
+ "#{indent}download+install or to use an existing\n" <<
614
+ "#{indent}Nginx source directory.") do
615
+ options[:auto_download] = true
616
+ end
617
+ opts.on("--nginx-source-dir=DIR", String, "Compile and install Nginx using the given\n" <<
618
+ "#{indent}Nginx source directory, instead of\n" <<
619
+ "#{indent}interactively asking to download+install\n" <<
620
+ "#{indent}or to use an existing Nginx source\n" <<
621
+ "#{indent}directory. Conflicts with --auto-download.") do |dir|
622
+ options[:nginx_source_dir] = dir
623
+ end
624
+ opts.on("--extra-configure-flags=STRING", String, "Pass these extra flags to Nginx's\n" <<
625
+ "#{indent}'configure' script, instead of asking for\n" <<
626
+ "#{indent}it interactively. Specify 'none' if you\n" <<
627
+ "#{indent}do not want to pass additional flags but do\n" <<
628
+ "#{indent}not want this installer to ask\n" <<
629
+ "#{indent}interactively either.") do |flags|
630
+ options[:extra_configure_flags] = flags
631
+ end
632
+ opts.on("--languages NAMES", "Comma-separated list of interested\n" <<
633
+ "#{indent}languages (e.g.\n" <<
634
+ "#{indent}'ruby,python,nodejs,meteor')") do |value|
635
+ options[:languages] = value.split(",")
636
+ end
637
+ opts.on("--force-colors", "Display colors even if stdout is not a TTY") do
638
+ options[:colorize] = true
639
+ end
640
640
  end
641
641
  begin
642
- parser.parse!
642
+ parser.parse!
643
643
  rescue OptionParser::ParseError => e
644
- puts e
645
- puts
646
- puts "Please see '--help' for valid options."
647
- exit 1
644
+ puts e
645
+ puts
646
+ puts "Please see '--help' for valid options."
647
+ exit 1
648
648
  end
649
649
 
650
650
  if options[:auto_download] && options[:nginx_source_dir]
651
- STDERR.puts "You cannot specify both --auto-download and --nginx-source-dir."
652
- exit 1
651
+ STDERR.puts "You cannot specify both --auto-download and --nginx-source-dir."
652
+ exit 1
653
653
  end
654
654
 
655
655
  Installer.new(options).run