forked from phusion/passenger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
passenger-install-apache2-module
executable file
·218 lines (200 loc) · 6.4 KB
/
passenger-install-apache2-module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
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
#!/usr/bin/env ruby
# Phusion Passenger - http://www.modrails.com/
# Copyright (c) 2008, 2009 Phusion
#
# "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
PASSENGER_ROOT = File.expand_path(File.dirname(__FILE__) << "/..")
$LOAD_PATH.unshift("#{PASSENGER_ROOT}/lib")
$LOAD_PATH.unshift("#{PASSENGER_ROOT}/ext")
# The Apache executable may be located in an 'sbin' folder. We add
# the 'sbin' folders to $PATH just in case. On some systems
# 'sbin' isn't in $PATH unless the user is logged in as root from
# the start (i.e. not via 'su' or 'sudo').
ENV["PATH"] += ":/usr/sbin:/sbin:/usr/local/sbin"
require 'optparse'
require 'phusion_passenger/platform_info'
require 'phusion_passenger/dependencies'
require 'phusion_passenger/abstract_installer'
include PlatformInfo
class Installer < PhusionPassenger::AbstractInstaller
include PhusionPassenger
def dependencies
result = [
Dependencies::GCC,
Dependencies::Ruby_DevHeaders,
Dependencies::Ruby_OpenSSL,
Dependencies::RubyGems,
Dependencies::Rake,
Dependencies::Apache2,
Dependencies::Apache2_DevHeaders,
Dependencies::FastThread
]
if Dependencies.fastthread_required?
result << Dependencies::FastThread
end
# Some broken servers don't have apr-config or apu-config installed.
# Nevertheless, it is possible to compile Apache modules if Apache
# was configured with --included-apr. So here we check whether
# apr-config and apu-config are available. If they're not available,
# then we only register them as required dependency if no Apache
# module can be compiled without their presence.
if (PlatformInfo.apr_config && PlatformInfo.apu_config) ||
PlatformInfo.apr_config_needed_for_building_apache_modules?
result << Dependencies::APR_DevHeaders
result << Dependencies::APU_DevHeaders
end
return result
end
def users_guide
return "#{DOCDIR}/Users guide Apache.html"
end
def install!
if PhusionPassenger.natively_packaged?
check_dependencies || exit(1)
show_apache2_config_snippets
show_deployment_example
exit
end
Dir.chdir(PASSENGER_ROOT)
show_welcome_screen
check_dependencies || exit(1)
check_whether_apache_uses_compatible_mpm
check_write_permission_to_passenger_root || exit(1)
if install_apache2_module
show_apache2_config_snippets
show_deployment_example
else
show_possible_solutions_for_compilation_and_installation_problems
exit(1)
end
end
private
def show_welcome_screen
render_template 'apache2/welcome', :version => VERSION_STRING
wait
end
def check_whether_apache_uses_compatible_mpm
# 'httpd -V' output is in the form of:
#
# Server MPM: Prefork # <--- this line is not always available!
# ...
# Server compiled with....
# -D APACHE_MPM_DIR="server/mpm/prefork"
output = `#{PlatformInfo.httpd} -V`
output =~ /^Server MPM: +(.*)$/
if $1
mpm = $1.downcase
else
output =~ /APACHE_MPM_DIR="server\/mpm\/(.*)"/
if $1
mpm = $1.downcase
else
mpm = nil
end
end
if mpm != "prefork" && mpm != "worker"
new_screen
render_template 'apache2/apache_must_be_compiled_with_compatible_mpm',
:current_mpm => mpm
wait
end
end
def check_write_permission_to_passenger_root
File.new("__test__.txt", "w").close
return true
rescue SystemCallError
puts
line
if Process.uid == 0
render_template 'apache2/no_write_permission_to_passenger_root'
else
render_template 'apache2/run_installer_as_root'
end
return false
ensure
File.unlink("__test__.txt") rescue nil
end
def install_apache2_module
puts
line
color_puts '<banner>Compiling and installing Apache 2 module...</banner>'
puts "cd #{PASSENGER_ROOT}"
if ENV['TRACE']
puts "#{RUBY} -S #{PlatformInfo.rake} --trace clean apache2"
return sh(RUBY, "-S", PlatformInfo.rake, "--trace", "clean", "apache2")
else
puts "#{RUBY} -S #{PlatformInfo.rake} clean apache2"
return sh(RUBY, "-S", PlatformInfo.rake, "clean", "apache2")
end
end
def show_apache2_config_snippets
puts
line
if PhusionPassenger.natively_packaged?
module_location = "#{PASSENGER_ROOT}/lib/phusion_passenger/mod_passenger.so"
else
module_location = "#{PASSENGER_ROOT}/ext/apache2/mod_passenger.so"
end
render_template 'apache2/config_snippets',
:module_location => module_location,
:passenger_root => PASSENGER_ROOT,
:ruby => RUBY
if PhusionPassenger.natively_packaged?
wait(10)
else
wait
end
end
def show_deployment_example
puts
line
render_template 'apache2/deployment_example',
:users_guide => users_guide,
:phusion_website => PHUSION_WEBSITE,
:passenger_website => PASSENGER_WEBSITE
end
def show_possible_solutions_for_compilation_and_installation_problems
new_screen
render_template 'apache2/possible_solutions_for_compilation_and_installation_problems',
:users_guide => users_guide,
:passenger_website => PASSENGER_WEBSITE
end
end
options = {}
parser = OptionParser.new do |opts|
opts.banner = "Usage: passenger-install-apache2-module [options]"
opts.separator ""
opts.separator "Options:"
opts.on("-a", "--auto", String, "Automatically build the Apache module,\n" <<
"#{' ' * 37}without interactively asking for user\n" <<
"#{' ' * 37}input.") do
options[:auto] = true
end
end
begin
parser.parse!
rescue OptionParser::ParseError => e
puts e
puts
puts "Please see '--help' for valid options."
exit 1
end
Installer.new(options).start