karsthammer-passenger 2.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,45 @@
1
+ == Introduction
2
+
3
+ Phusion Passenger probably requires no introduction. We kindly refer the reader
4
+ to http://www.modrails.com/ for general information.
5
+
6
+ == Installation
7
+
8
+ === Regular installation
9
+
10
+ You can install either Phusion Passenger for Apache or for Nginx. Run either of
11
+ the following programs as root:
12
+
13
+ ./bin/passenger-install-apache2-module
14
+
15
+ -OR-
16
+
17
+ ./bin/passenger-install-nginx-module
18
+
19
+ That's it. :)
20
+
21
+ For troubleshooting, configuration and tips, please read the corresponding
22
+ Users Guide:
23
+
24
+ doc/Users guide Apache.html
25
+ doc/Users guide Nginx.html
26
+
27
+ These files are included in the source tarball, and may also be viewed online on
28
+ our website.
29
+
30
+ === Installing via a gem
31
+
32
+ You may also first generate a .gem file, and then install that.
33
+ First, make sure that you have the following software installed:
34
+ - Doxygen: http://www.stack.nl/~dimitri/doxygen/
35
+ - Asciidoc: http://www.methods.co.nz/asciidoc/
36
+
37
+ Next, run:
38
+
39
+ rake package
40
+
41
+ The gem will be available under the 'pkg' folder.
42
+
43
+ == Legal
44
+
45
+ Phusion Passenger is a trademark of Hongli Lai & Ninh Bui.
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+ # Phusion Passenger - http://www.modrails.com/
3
+ # Copyright (c) 2008, 2009 Phusion
4
+ #
5
+ # "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in
15
+ # all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ # THE SOFTWARE.
24
+
25
+ PASSENGER_ROOT = File.expand_path(File.dirname(__FILE__) << "/..")
26
+ $LOAD_PATH.unshift("#{PASSENGER_ROOT}/lib")
27
+ require 'phusion_passenger/constants'
28
+
29
+ def help
30
+ puts "Tool for showing Passenger configuration information."
31
+ puts "Usage: passenger-config <OPTIONS>"
32
+ puts
33
+ puts "Options:"
34
+ puts " --root Show Passenger's root directory."
35
+ puts " --version Show Passenger's version number."
36
+ end
37
+
38
+ case ARGV[0]
39
+ when "--root"
40
+ puts PASSENGER_ROOT
41
+ when "--version"
42
+ puts PhusionPassenger::VERSION_STRING
43
+ else
44
+ help
45
+ exit 1
46
+ end
@@ -0,0 +1,217 @@
1
+ #!/usr/bin/env ruby
2
+ # Phusion Passenger - http://www.modrails.com/
3
+ # Copyright (c) 2008, 2009 Phusion
4
+ #
5
+ # "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in
15
+ # all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ # THE SOFTWARE.
24
+
25
+ PASSENGER_ROOT = File.expand_path(File.dirname(__FILE__) << "/..")
26
+ $LOAD_PATH.unshift("#{PASSENGER_ROOT}/lib")
27
+ $LOAD_PATH.unshift("#{PASSENGER_ROOT}/ext")
28
+
29
+ # The Apache executable may be located in an 'sbin' folder. We add
30
+ # the 'sbin' folders to $PATH just in case. On some systems
31
+ # 'sbin' isn't in $PATH unless the user is logged in as root from
32
+ # the start (i.e. not via 'su' or 'sudo').
33
+ ENV["PATH"] += ":/usr/sbin:/sbin:/usr/local/sbin"
34
+
35
+ require 'optparse'
36
+ require 'phusion_passenger/platform_info'
37
+ require 'phusion_passenger/dependencies'
38
+ require 'phusion_passenger/abstract_installer'
39
+ include PlatformInfo
40
+
41
+ class Installer < PhusionPassenger::AbstractInstaller
42
+ include PhusionPassenger
43
+
44
+ def dependencies
45
+ result = [
46
+ Dependencies::GCC,
47
+ Dependencies::Ruby_DevHeaders,
48
+ Dependencies::Ruby_OpenSSL,
49
+ Dependencies::RubyGems,
50
+ Dependencies::Rake,
51
+ Dependencies::Apache2,
52
+ Dependencies::Apache2_DevHeaders
53
+ ]
54
+ if Dependencies.fastthread_required?
55
+ result << Dependencies::FastThread
56
+ end
57
+ # Some broken servers don't have apr-config or apu-config installed.
58
+ # Nevertheless, it is possible to compile Apache modules if Apache
59
+ # was configured with --included-apr. So here we check whether
60
+ # apr-config and apu-config are available. If they're not available,
61
+ # then we only register them as required dependency if no Apache
62
+ # module can be compiled without their presence.
63
+ if (PlatformInfo.apr_config && PlatformInfo.apu_config) ||
64
+ PlatformInfo.apr_config_needed_for_building_apache_modules?
65
+ result << Dependencies::APR_DevHeaders
66
+ result << Dependencies::APU_DevHeaders
67
+ end
68
+ return result
69
+ end
70
+
71
+ def users_guide
72
+ return "#{DOCDIR}/Users guide Apache.html"
73
+ end
74
+
75
+ def install!
76
+ if PhusionPassenger.natively_packaged?
77
+ check_dependencies || exit(1)
78
+ show_apache2_config_snippets
79
+ show_deployment_example
80
+ exit
81
+ end
82
+
83
+ Dir.chdir(PASSENGER_ROOT)
84
+ show_welcome_screen
85
+ check_dependencies || exit(1)
86
+ check_whether_apache_uses_compatible_mpm
87
+ check_write_permission_to_passenger_root || exit(1)
88
+ if install_apache2_module
89
+ show_apache2_config_snippets
90
+ show_deployment_example
91
+ else
92
+ show_possible_solutions_for_compilation_and_installation_problems
93
+ exit(1)
94
+ end
95
+ end
96
+
97
+ private
98
+ def show_welcome_screen
99
+ render_template 'apache2/welcome', :version => VERSION_STRING
100
+ wait
101
+ end
102
+
103
+ def check_whether_apache_uses_compatible_mpm
104
+ # 'httpd -V' output is in the form of:
105
+ #
106
+ # Server MPM: Prefork # <--- this line is not always available!
107
+ # ...
108
+ # Server compiled with....
109
+ # -D APACHE_MPM_DIR="server/mpm/prefork"
110
+ output = `#{PlatformInfo.httpd} -V`
111
+ output =~ /^Server MPM: +(.*)$/
112
+ if $1
113
+ mpm = $1.downcase
114
+ else
115
+ output =~ /APACHE_MPM_DIR="server\/mpm\/(.*)"/
116
+ if $1
117
+ mpm = $1.downcase
118
+ else
119
+ mpm = nil
120
+ end
121
+ end
122
+ if mpm != "prefork" && mpm != "worker"
123
+ new_screen
124
+ render_template 'apache2/apache_must_be_compiled_with_compatible_mpm',
125
+ :current_mpm => mpm
126
+ wait
127
+ end
128
+ end
129
+
130
+ def check_write_permission_to_passenger_root
131
+ File.new("__test__.txt", "w").close
132
+ return true
133
+ rescue SystemCallError
134
+ puts
135
+ line
136
+ if Process.uid == 0
137
+ render_template 'apache2/no_write_permission_to_passenger_root'
138
+ else
139
+ render_template 'apache2/run_installer_as_root'
140
+ end
141
+ return false
142
+ ensure
143
+ File.unlink("__test__.txt") rescue nil
144
+ end
145
+
146
+ def install_apache2_module
147
+ puts
148
+ line
149
+ color_puts '<banner>Compiling and installing Apache 2 module...</banner>'
150
+ puts "cd #{PASSENGER_ROOT}"
151
+ if ENV['TRACE']
152
+ puts "#{RUBY} -S #{PlatformInfo.rake} --trace clean apache2"
153
+ return sh(RUBY, "-S", PlatformInfo.rake, "--trace", "clean", "apache2")
154
+ else
155
+ puts "#{RUBY} -S #{PlatformInfo.rake} clean apache2"
156
+ return sh(RUBY, "-S", PlatformInfo.rake, "clean", "apache2")
157
+ end
158
+ end
159
+
160
+ def show_apache2_config_snippets
161
+ puts
162
+ line
163
+ if PhusionPassenger.natively_packaged?
164
+ module_location = "#{PASSENGER_ROOT}/lib/phusion_passenger/mod_passenger.so"
165
+ else
166
+ module_location = "#{PASSENGER_ROOT}/ext/apache2/mod_passenger.so"
167
+ end
168
+ render_template 'apache2/config_snippets',
169
+ :module_location => module_location,
170
+ :passenger_root => PASSENGER_ROOT,
171
+ :ruby => RUBY
172
+ if PhusionPassenger.natively_packaged?
173
+ wait(10)
174
+ else
175
+ wait
176
+ end
177
+ end
178
+
179
+ def show_deployment_example
180
+ puts
181
+ line
182
+ render_template 'apache2/deployment_example',
183
+ :users_guide => users_guide,
184
+ :phusion_website => PHUSION_WEBSITE,
185
+ :passenger_website => PASSENGER_WEBSITE
186
+ end
187
+
188
+ def show_possible_solutions_for_compilation_and_installation_problems
189
+ new_screen
190
+ render_template 'apache2/possible_solutions_for_compilation_and_installation_problems',
191
+ :users_guide => users_guide,
192
+ :passenger_website => PASSENGER_WEBSITE
193
+ end
194
+ end
195
+
196
+ options = {}
197
+ parser = OptionParser.new do |opts|
198
+ opts.banner = "Usage: passenger-install-apache2-module [options]"
199
+ opts.separator ""
200
+
201
+ opts.separator "Options:"
202
+ opts.on("-a", "--auto", String, "Automatically build the Apache module,\n" <<
203
+ "#{' ' * 37}without interactively asking for user\n" <<
204
+ "#{' ' * 37}input.") do
205
+ options[:auto] = true
206
+ end
207
+ end
208
+ begin
209
+ parser.parse!
210
+ rescue OptionParser::ParseError => e
211
+ puts e
212
+ puts
213
+ puts "Please see '--help' for valid options."
214
+ exit 1
215
+ end
216
+
217
+ Installer.new(options).start
@@ -0,0 +1,465 @@
1
+ #!/usr/bin/env ruby
2
+ # Phusion Passenger - http://www.modrails.com/
3
+ # Copyright (c) 2009 Phusion
4
+ #
5
+ # "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in
15
+ # all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ # THE SOFTWARE.
24
+
25
+ PASSENGER_ROOT = File.expand_path(File.dirname(__FILE__) << "/..")
26
+ $LOAD_PATH.unshift("#{PASSENGER_ROOT}/lib")
27
+ $LOAD_PATH.unshift("#{PASSENGER_ROOT}/ext")
28
+
29
+ require 'optparse'
30
+ require 'fileutils'
31
+ require 'phusion_passenger/platform_info'
32
+ require 'phusion_passenger/dependencies'
33
+ require 'phusion_passenger/abstract_installer'
34
+ include PlatformInfo
35
+
36
+ class Installer < PhusionPassenger::AbstractInstaller
37
+ include PhusionPassenger
38
+
39
+ NGINX_VERSION = "0.6.37"
40
+
41
+ def dependencies
42
+ result = [
43
+ Dependencies::GCC,
44
+ Dependencies::Ruby_DevHeaders,
45
+ Dependencies::Ruby_OpenSSL,
46
+ Dependencies::RubyGems,
47
+ Dependencies::Rake,
48
+ Dependencies::Zlib_Dev
49
+ ]
50
+ if Dependencies.fastthread_required?
51
+ result << Dependencies::FastThread
52
+ end
53
+ return result
54
+ end
55
+
56
+ def users_guide
57
+ return "#{DOCDIR}/Users guide Nginx.html"
58
+ end
59
+
60
+ def install!
61
+ Dir.chdir(PASSENGER_ROOT)
62
+ show_welcome_screen
63
+ check_dependencies || exit(1)
64
+
65
+ check_whether_we_can_write_to(PASSENGER_ROOT) || exit(1)
66
+
67
+ download_and_install = should_we_download_and_install_nginx_automatically?
68
+ if pcre_is_installed?
69
+ @pcre_source_dir = nil
70
+ else
71
+ @pcre_source_dir = download_and_extract_pcre
72
+ end
73
+ if download_and_install
74
+ nginx_source_dir = download_and_extract_nginx
75
+ if nginx_source_dir.nil?
76
+ show_possible_solutions_for_download_and_extraction_problems
77
+ exit(1)
78
+ end
79
+ nginx_prefix = ask_for_nginx_install_prefix
80
+ extra_nginx_configure_flags = nil
81
+ else
82
+ nginx_source_dir = ask_for_nginx_source_dir
83
+ nginx_prefix = ask_for_nginx_install_prefix
84
+ extra_nginx_configure_flags = ask_for_extra_nginx_configure_flags(nginx_prefix)
85
+ end
86
+ check_whether_we_can_write_to(nginx_prefix) || exit(1)
87
+ nginx_config_already_exists_before_installing = nginx_config_exists?(nginx_prefix)
88
+ compile_passenger_support_files || exit(1)
89
+ if install_nginx(nginx_source_dir, nginx_prefix, extra_nginx_configure_flags)
90
+ if nginx_config_already_exists_before_installing || !locate_nginx_config_file(nginx_prefix)
91
+ show_passenger_config_snippets(nginx_prefix)
92
+ else
93
+ insert_passenger_config_snippets(nginx_prefix)
94
+ end
95
+ show_deployment_example
96
+ else
97
+ show_possible_solutions_for_compilation_and_installation_problems
98
+ exit(1)
99
+ end
100
+ end
101
+
102
+ private
103
+ def show_welcome_screen
104
+ render_template 'nginx/welcome', :version => VERSION_STRING
105
+ wait
106
+ end
107
+
108
+ def compile_passenger_support_files
109
+ new_screen
110
+ color_puts "<banner>Compiling Passenger support files...</banner>"
111
+ return sh(RUBY, "-S", PlatformInfo.rake, "clean", "nginx")
112
+ end
113
+
114
+ def should_we_download_and_install_nginx_automatically?
115
+ new_screen
116
+ render_template 'nginx/query_download_and_install',
117
+ :nginx_version => NGINX_VERSION
118
+ puts
119
+
120
+ if @auto_download
121
+ color_puts "<b>=> Proceeding with choice 1.</b>"
122
+ return true
123
+ elsif @nginx_source_dir
124
+ color_puts "<b>=> Proceeding with choice 2.</b>"
125
+ return false
126
+ else
127
+ choice = prompt("Enter your choice (1 or 2) or press Ctrl-C to abort") do |input|
128
+ if input == "1" || input == "2"
129
+ true
130
+ elsif input.empty?
131
+ color_puts "<red>No choice has been given.</red>"
132
+ false
133
+ else
134
+ color_puts "<red>'#{input}' is not a valid choice.</red>"
135
+ false
136
+ end
137
+ end
138
+ return choice == "1"
139
+ end
140
+ end
141
+
142
+ def download_and_extract_pcre
143
+ new_screen
144
+ color_puts "<banner>PCRE (required by Nginx) not installed, downloading it...</banner>"
145
+
146
+ basename = "pcre-7.8.tar.gz"
147
+ dirname = "pcre-7.8"
148
+ url = "ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/#{basename}"
149
+ File.unlink("/tmp/#{basename}") rescue nil
150
+ FileUtils.rm_rf("/tmp/#{dirname}")
151
+
152
+ if download(url, "/tmp/#{basename}")
153
+ Dir.chdir("/tmp") do
154
+ color_puts "<banner>Extracting PCRE source tarball...</banner>"
155
+ if sh("tar", "xzvf", basename)
156
+ return "/tmp/#{dirname}"
157
+ else
158
+ new_screen
159
+ render_template "nginx/pcre_could_not_be_extracted"
160
+ wait
161
+ return nil
162
+ end
163
+ end
164
+ else
165
+ new_screen
166
+ render_template "nginx/pcre_could_not_be_downloaded"
167
+ wait
168
+ return nil
169
+ end
170
+ rescue Interrupt
171
+ exit 2
172
+ end
173
+
174
+ def download_and_extract_nginx
175
+ new_screen
176
+ color_puts "<banner>Downloading Nginx...</banner>"
177
+
178
+ basename = "nginx-#{NGINX_VERSION}.tar.gz"
179
+ url = "http://sysoev.ru/nginx/#{basename}"
180
+ File.unlink("/tmp/#{basename}") rescue nil
181
+ FileUtils.rm_rf("/tmp/nginx-#{NGINX_VERSION}")
182
+
183
+ if download(url, "/tmp/#{basename}")
184
+ Dir.chdir("/tmp") do
185
+ color_puts "<banner>Extracting Nginx source tarball...</banner>"
186
+ if sh("tar", "xzvf", basename)
187
+ return "/tmp/nginx-#{NGINX_VERSION}"
188
+ else
189
+ return nil
190
+ end
191
+ end
192
+ else
193
+ return nil
194
+ end
195
+ rescue Interrupt
196
+ exit 2
197
+ end
198
+
199
+ def show_possible_solutions_for_download_and_extraction_problems
200
+ new_screen
201
+ render_template "nginx/possible_solutions_for_download_and_extraction_problems"
202
+ puts
203
+ end
204
+
205
+ def ask_for_nginx_install_prefix
206
+ new_screen
207
+ color_puts "<banner>Where do you want to install Nginx to?</banner>"
208
+ puts
209
+ if @prefix
210
+ color_puts "<b>=> #{@prefix}</b>"
211
+ return @prefix
212
+ else
213
+ prefix = prompt("Please specify a prefix directory [/opt/nginx]") do |input|
214
+ if input.empty? || input =~ %r(/)
215
+ true
216
+ else
217
+ color_puts "<red>Please specify an absolute path.</red>"
218
+ false
219
+ end
220
+ end
221
+ if prefix.empty?
222
+ prefix = "/opt/nginx"
223
+ end
224
+ return prefix
225
+ end
226
+ end
227
+
228
+ def ask_for_nginx_source_dir
229
+ new_screen
230
+ color_puts "<banner>Where is your Nginx source code located?</banner>"
231
+ puts
232
+ if @nginx_source_dir
233
+ color_puts "<b>=> #{@nginx_source_dir}</b>"
234
+ return @nginx_source_dir
235
+ else
236
+ return prompt("Please specify the directory") do |input|
237
+ if input =~ %r(/)
238
+ if File.exist?("#{input}/src/core/nginx.c")
239
+ true
240
+ else
241
+ color_puts "<red>'#{input}' does not look like an Nginx source directory.</red>"
242
+ false
243
+ end
244
+ else
245
+ color_puts "<red>Please specify an absolute path.</red>"
246
+ false
247
+ end
248
+ end
249
+ end
250
+ end
251
+
252
+ def ask_for_extra_nginx_configure_flags(prefix)
253
+ done = false
254
+ while !done
255
+ new_screen
256
+ render_template 'nginx/ask_for_extra_configure_flags',
257
+ :command => build_nginx_configure_command(prefix)
258
+ puts
259
+ if @extra_configure_flags
260
+ if @extra_configure_flags == "none"
261
+ extra_args = ""
262
+ color_puts "<b>=> No extra configure flags.</b>"
263
+ else
264
+ extra_args = @extra_configure_flags
265
+ color_puts "<b>=> #{extra_args}</b>"
266
+ end
267
+ return extra_args
268
+ else
269
+ extra_args = prompt "Extra arguments to pass to configure script"
270
+
271
+ new_screen
272
+ render_template 'nginx/confirm_extra_configure_flags',
273
+ :command => build_nginx_configure_command(prefix, extra_args)
274
+ puts
275
+ answer = prompt("Is this what you want? (yes/no) [default=yes]") do |input|
276
+ if input.empty? || input == "yes" || input == "no"
277
+ true
278
+ else
279
+ color_puts "<red>Please enter 'yes' or 'no'.</red>"
280
+ false
281
+ end
282
+ end
283
+ done = answer.empty? || answer == "yes"
284
+ end
285
+ end
286
+ return extra_args
287
+ end
288
+
289
+ def check_whether_we_can_write_to(dir)
290
+ FileUtils.mkdir_p(dir)
291
+ File.new("#{dir}/__test__.txt", "w").close
292
+ return true
293
+ rescue
294
+ new_screen
295
+ if Process.uid == 0
296
+ render_template 'nginx/cannot_write_to_dir', :dir => dir
297
+ else
298
+ render_template 'nginx/run_installer_as_root', :dir => dir
299
+ end
300
+ return false
301
+ ensure
302
+ File.unlink("#{dir}/__test__.txt") rescue nil
303
+ end
304
+
305
+ def nginx_config_exists?(prefix)
306
+ return !!locate_nginx_config_file(prefix)
307
+ end
308
+
309
+ def install_nginx(source_dir, prefix, extra_configure_flags)
310
+ Dir.chdir(source_dir) do
311
+ new_screen
312
+ color_puts "<banner>Compiling and installing Nginx...</banner>"
313
+ if !sh(build_nginx_configure_command(prefix, extra_configure_flags)) ||
314
+ !sh("make") ||
315
+ !sh("make install")
316
+ return false
317
+ end
318
+ end
319
+ return true
320
+ end
321
+
322
+ def show_passenger_config_snippets(prefix)
323
+ new_screen
324
+ render_template 'nginx/config_snippets',
325
+ :config_file => locate_nginx_config_file(prefix),
326
+ :passenger_root => PASSENGER_ROOT,
327
+ :ruby => RUBY
328
+ wait
329
+ end
330
+
331
+ def show_deployment_example
332
+ line
333
+ puts
334
+ render_template 'nginx/deployment_example',
335
+ :users_guide => users_guide,
336
+ :phusion_website => PHUSION_WEBSITE,
337
+ :passenger_website => PASSENGER_WEBSITE
338
+ end
339
+
340
+ def show_possible_solutions_for_compilation_and_installation_problems
341
+ line
342
+ puts
343
+ render_template 'nginx/possible_solutions_for_compilation_and_installation_problems',
344
+ :users_guide => users_guide,
345
+ :passenger_website => PASSENGER_WEBSITE
346
+ end
347
+
348
+ def locate_nginx_config_file(prefix)
349
+ ["#{prefix}/conf/nginx.conf", "#{prefix}/etc/nginx.conf"].each do |filename|
350
+ if File.exist?(filename)
351
+ return filename
352
+ end
353
+ end
354
+ return nil
355
+ end
356
+
357
+ def insert_passenger_config_snippets(prefix)
358
+ config_file = locate_nginx_config_file(prefix)
359
+ contents = File.read(config_file)
360
+ contents.sub!(/^http \{/,
361
+ "http {\n" <<
362
+ " passenger_root #{PASSENGER_ROOT};\n" <<
363
+ " passenger_ruby #{RUBY};\n")
364
+ File.open(config_file, 'w') do |f|
365
+ f.write(contents)
366
+ end
367
+
368
+ new_screen
369
+ render_template 'nginx/config_snippets_inserted',
370
+ :config_file => config_file,
371
+ :passenger_root => PASSENGER_ROOT,
372
+ :ruby => RUBY
373
+ wait
374
+ end
375
+
376
+ def build_nginx_configure_command(prefix, extra_configure_flags = nil)
377
+ command = "./configure --prefix='#{prefix}' "
378
+ if @pcre_source_dir
379
+ command << "--with-pcre='#{@pcre_source_dir}' "
380
+ elsif !pcre_is_installed?
381
+ command << "--without-http_rewrite_module "
382
+ end
383
+ command << "--add-module='#{PASSENGER_ROOT}/ext/nginx' #{extra_configure_flags}"
384
+ command.strip!
385
+ return command
386
+ end
387
+
388
+ def pcre_is_installed?
389
+ if @pcre_is_installed.nil?
390
+ @pcre_is_installed = begin
391
+ File.open('/tmp/passenger-check.c', 'w') do |f|
392
+ f.puts("#include <pcre.h>")
393
+ end
394
+ Dir.chdir('/tmp') do
395
+ system("(gcc -c passenger-check.c) >/dev/null 2>/dev/null")
396
+ end
397
+ ensure
398
+ File.unlink('/tmp/passenger-check.c') rescue nil
399
+ File.unlink('/tmp/passenger-check.o') rescue nil
400
+ end
401
+ end
402
+ return @pcre_is_installed
403
+ end
404
+
405
+ def download(url, output)
406
+ if PlatformInfo.find_command("wget")
407
+ return sh("wget", "-O", output, url)
408
+ else
409
+ return sh("curl", url, "-o", output)
410
+ end
411
+ end
412
+ end
413
+
414
+ options = {}
415
+ parser = OptionParser.new do |opts|
416
+ opts.banner = "Usage: passenger-install-nginx-module [options]"
417
+ opts.separator ""
418
+
419
+ opts.separator "Options:"
420
+ opts.on("--auto", "Automatically confirm 'Press ENTER to\n" <<
421
+ "#{' ' * 37}continue' prompts.") do
422
+ options[:auto] = true
423
+ end
424
+ opts.on("--prefix=DIR", String, "Use the given Nginx install prefix instead\n" <<
425
+ "#{' ' * 37}of asking for it interactively.") do |dir|
426
+ options[:prefix] = dir
427
+ end
428
+ opts.on("--auto-download", "Download and install Nginx automatically,\n" <<
429
+ "#{' ' * 37}instead of asking interactively whether to\n" <<
430
+ "#{' ' * 37}download+install or to use an existing\n" <<
431
+ "#{' ' * 37}Nginx source directory.") do
432
+ options[:auto_download] = true
433
+ end
434
+ opts.on("--nginx-source-dir=DIR", String, "Compile and install Nginx using the given\n" <<
435
+ "#{' ' * 37}Nginx source directory, instead of\n" <<
436
+ "#{' ' * 37}interactively asking to download+install\n" <<
437
+ "#{' ' * 37}or to use an existing Nginx source\n" <<
438
+ "#{' ' * 37}directory. Conflicts with --auto-download.") do |dir|
439
+ options[:nginx_source_dir] = dir
440
+ end
441
+ opts.on("--extra-configure-flags=STRING", String, "Pass these extra flags to Nginx's\n" <<
442
+ "#{' ' * 37}'configure' script, instead of asking for\n" <<
443
+ "#{' ' * 37}it interactively. Only applicable if\n" <<
444
+ "#{' ' * 37}--nginx-source-dir is given. Specify\n" <<
445
+ "#{' ' * 37}'none' if you do not want to pass\n" <<
446
+ "#{' ' * 37}additional flags but do not want this\n" <<
447
+ "#{' ' * 37}installer to ask interactively either.") do |flags|
448
+ options[:extra_configure_flags] = flags
449
+ end
450
+ end
451
+ begin
452
+ parser.parse!
453
+ rescue OptionParser::ParseError => e
454
+ puts e
455
+ puts
456
+ puts "Please see '--help' for valid options."
457
+ exit 1
458
+ end
459
+
460
+ if options[:auto_download] && options[:nginx_source_dir]
461
+ STDERR.puts "You cannot specify both --auto-download and --nginx-source-dir."
462
+ exit 1
463
+ end
464
+
465
+ Installer.new(options).start