Detects all possible Apache installations on the system, and presents the autodetection information to the user in a friendly way. It turns out too many people have multiple Apache installations on their system, but they don't know about that, or they don't know how to compile against the correct Apache installation. This tool helps them.
If you use this class to log things to the terminal, then be sure to set the terminal color to Utils::AnsiColors::DEFAULT_TERMINAL_COLOR.
# File lib/phusion_passenger/platform_info/apache_detector.rb, line 87 def initialize(output) @output = output @results = [] PlatformInfo.verbose = true PlatformInfo.log_implementation = lambda do |message| if message =~ /: found$/ log("<green> --> #{message}</green>") else log(" --> #{message}") end end end
# File lib/phusion_passenger/platform_info/apache_detector.rb, line 105 def detect_all log "<banner>Looking for possible Apache installations...</banner>" apxses = PlatformInfo.find_all_commands("apxs2") + PlatformInfo.find_all_commands("apxs") apxses = remove_symlink_duplications(apxses) log "" apxses.each do |apxs2| detect_one(apxs2) end end
# File lib/phusion_passenger/platform_info/apache_detector.rb, line 116 def detect_one(apxs2) log "<banner>Analyzing #{apxs2}...</banner>" add_result do |result| result.apxs2 = apxs2 log "Detecting main Apache executable..." result.httpd = PlatformInfo.httpd(:apxs2 => apxs2) if result.httpd log "Detecting version..." if result.version = PlatformInfo.httpd_version(:httpd => result.httpd) log " --> #{result.version}" else log "<red> --> Cannot detect version!</red>" result.httpd = nil end end if result.httpd log "Detecting control command..." result.ctl = PlatformInfo.apache2ctl(:apxs2 => apxs2) result.httpd = nil if !result.ctl end if result.httpd log "Detecting configuration file location..." result.config_file = PlatformInfo.httpd_default_config_file(:httpd => result.httpd) if result.config_file log " --> #{result.config_file}" else log "<red> --> Cannot detect default config file location!</red>" result.httpd = nil end end if result.httpd log "Detecting error log file..." result.error_log = PlatformInfo.httpd_actual_error_log(:httpd => result.httpd) if result.error_log log " --> #{result.error_log}" else log "<red> --> Cannot detect error log file!</red>" end end if result.httpd log "Detecting a2enmod and a2dismod..." result.a2enmod = PlatformInfo.a2enmod(:apxs2 => apxs2) result.a2dismod = PlatformInfo.a2dismod(:apxs2 => apxs2) end if result.httpd log "<green>Found a usable Apache installation using #{apxs2}.</green>" true else log "<yellow>Cannot find a usable Apache installation using #{apxs2}.</yellow>" false end end log "" end
# File lib/phusion_passenger/platform_info/apache_detector.rb, line 100 def finish PlatformInfo.verbose = false PlatformInfo.log_implementation = nil end
# File lib/phusion_passenger/platform_info/apache_detector.rb, line 171 def report log "<banner>Final autodetection results</banner>" @results.each do |result| result.report end if @results.empty? log "<red>Sorry, this program cannot find an Apache installation.</red>" log "" log "To install Apache, please run the following. It will tell you how to install Apache." log "" log " <b>#{PhusionPassenger.bin_dir}/passenger-install-apache2-module</b>" log "" log "If you are sure that you have Apache installed, please read the documentation:" log "<b>#{APACHE2_DOC_URL}#forcing_location_of_command_line_tools_and_dependencies</b>" elsif @results.size > 1 log "<yellow>WARNING: You have multiple Apache installations on your system!</yellow>" log "You are strongly recommended to read this section of the documentation:" log "<b>#{APACHE2_DOC_URL}#multiple_apache_installs</b>" end end
# File lib/phusion_passenger/platform_info/apache_detector.rb, line 192 def result_for(apxs2) # All the results use realpaths, so the input must too. apxs2 = Pathname.new(apxs2).realpath return @results.find { |r| r.apxs2 == apxs2 } end
# File lib/phusion_passenger/platform_info/apache_detector.rb, line 224 def add_result result = Result.new(self) @results << result if yield(result) end
# File lib/phusion_passenger/platform_info/apache_detector.rb, line 199 def log(message) if @output.tty? @output.puts(Utils::AnsiColors.ansi_colorize(message)) else @output.puts(Utils::AnsiColors.strip_color_tags(message)) end end
On Ubuntu, /usr/bin/apxs2 is a symlink to /usr/bin/apxs. On recent Arch Linux releases, /bin, /sbin etc are symlinks to /usr/bin and /usr/sbin. We're only supposed to detect one Apache in that case so we need to resolve symlinks.
# File lib/phusion_passenger/platform_info/apache_detector.rb, line 212 def remove_symlink_duplications(filenames) old_size = filenames.size filenames = filenames.map do |filename| Pathname.new(filename).realpath end filenames.uniq! if old_size != filenames.size log "#{old_size - filenames.size} symlink duplicate(s) detected; ignoring them." end return filenames end