module PhusionPassenger::Config::InstallationUtils
Public Class Methods
included(klass)
click to toggle source
# File src/ruby_supportlib/phusion_passenger/config/installation_utils.rb, line 42 def self.included(klass) # When included into another class, make sure that Utils # methods are made private. public_instance_methods(false).each do |method_name| klass.send(:private, method_name) end end
Public Instance Methods
check_for_download_tool!()
click to toggle source
# File src/ruby_supportlib/phusion_passenger/config/installation_utils.rb, line 82 def check_for_download_tool! PlatformInfo::Depcheck.load('depcheck_specs/utilities') result = PlatformInfo::Depcheck.find('download-tool').check # Don't output anything if there is a download tool. # We want to be as quiet as possible. return if result && result[:found] colors = @colors || Utils::AnsiColors.new puts colors.ansi_colorize("<banner>Checking for basic prerequities...</banner>") puts runner = PlatformInfo::Depcheck::ConsoleRunner.new runner.add('download-tool') result = runner.check_all puts if !result puts "---------------------------------------" puts render_template 'installation_utils/download_tool_missing', :runner => runner abort end end
find_or_create_writable_support_binaries_dir!()
click to toggle source
# File src/ruby_supportlib/phusion_passenger/config/installation_utils.rb, line 50 def find_or_create_writable_support_binaries_dir! if File.exist?(PhusionPassenger.support_binaries_dir) result = directory_writable?(PhusionPassenger.support_binaries_dir) if result == true # return value can be a SystemCallError return PhusionPassenger.support_binaries_dir end if Process.euid == 0 if result == false print_installation_error_header render_template 'installation_utils/support_binaries_dir_not_writable_despite_running_as_root', :dir => PhusionPassenger.support_binaries_dir, :myself => myself else render_template 'installation_utils/unexpected_filesystem_problem', :dir => PhusionPassenger.support_binaries_dir, :exception => result end abort else return find_or_create_writable_user_support_binaries_dir! end else if Process.euid == 0 mkdir_p_preserve_parent_owner(PhusionPassenger.support_binaries_dir) return PhusionPassenger.support_binaries_dir else return find_or_create_writable_user_support_binaries_dir! end end end
print_installation_error_header()
click to toggle source
Override this method to print a different header
# File src/ruby_supportlib/phusion_passenger/config/installation_utils.rb, line 108 def print_installation_error_header if @colors red = @colors.red reset = @colors.reset else red = nil reset = nil end @logger.warn "------------------------------------------" if @logger puts "#{red}Cannot proceed with installation#{reset}" puts end
rake()
click to toggle source
# File src/ruby_supportlib/phusion_passenger/config/installation_utils.rb, line 121 def rake return "env NOEXEC_DISABLE=1 #{PlatformInfo.rake_command}" end
run_rake_task!(target) { |progress, total_lines| ... }
click to toggle source
# File src/ruby_supportlib/phusion_passenger/config/installation_utils.rb, line 125 def run_rake_task!(target) total_lines = %x#{rake} #{target} --dry-run STDERR_TO_STDOUT=1 2>&1`.split("\n").size - 1 partial_backlog = "" logfile = PhusionPassenger::Utils::TmpIO.new("passenger-install-log", :mode => File::WRONLY, :unlink_immediately => false) begin command = "#{rake} #{target} --trace STDERR_TO_STDOUT=1 2>&1" IO.popen(command, "rb") do |io| progress = 1 while !io.eof? line = io.readline logfile.write(line) yield(progress, total_lines) if line =~ /^\*\* / partial_backlog.replace("") progress += 1 else partial_backlog << line end end end if $?.exitstatus != 0 colors = @colors || PhusionPassenger::Utils::AnsiColors.new stderr = @stderr || STDERR stderr.puts stderr.puts "#{colors.red}*** ERROR: a Rake command failed. You can find the full " + "log in #{logfile.path}. Below, you can find the last few lines of the command's output.#{colors.reset}" stderr.puts "#{colors.red}------------- Begin command output snippet -------------#{colors.reset}" stderr.puts(partial_backlog) stderr.puts "#{colors.red}------------- End command output snippet -------------#{colors.reset}" stderr.puts "#{colors.red}The full log can be found in #{logfile.path}#{colors.reset}" exit 1 end ensure logfile.close end end
Private Instance Methods
create_user_support_binaries_dir!()
click to toggle source
# File src/ruby_supportlib/phusion_passenger/config/installation_utils.rb, line 207 def create_user_support_binaries_dir! dir = PhusionPassenger.user_support_binaries_dir begin mkdir_p_preserve_parent_owner(dir) rescue Errno::EACCES print_installation_error_header render_template 'installation_utils/cannot_create_user_support_binaries_dir', :dir => dir, :myself => myself abort rescue SystemCallError print_installation_error_header render_template 'installation_utils/unexpected_filesystem_problem', :dir => dir, :exception => result abort end end
directory_writable?(path)
click to toggle source
We can't use File.writable() and friends here because they don't always work right with ACLs. Instead of we use 'real' checks.
# File src/ruby_supportlib/phusion_passenger/config/installation_utils.rb, line 168 def directory_writable?(path) filename = "#{path}/.__test_#{object_id}__.txt" @logger.debug "Checking whether we can write to #{path}..." if @logger begin File.new(filename, "w").close @logger.debug "Yes" if @logger return true rescue Errno::EACCES @logger.debug "No" if @logger return false rescue SystemCallError => e @logger.warn "Unable to check whether we can write to #{path}: #{e}" if @logger return e ensure File.unlink(filename) rescue nil end end
find_or_create_writable_user_support_binaries_dir!()
click to toggle source
# File src/ruby_supportlib/phusion_passenger/config/installation_utils.rb, line 186 def find_or_create_writable_user_support_binaries_dir! if !File.exist?(PhusionPassenger.user_support_binaries_dir) create_user_support_binaries_dir! end result = directory_writable?(PhusionPassenger.user_support_binaries_dir) case result when true return PhusionPassenger.user_support_binaries_dir when false print_installation_error_header render_template 'installation_utils/user_support_binaries_dir_not_writable' abort else print_installation_error_header render_template 'installation_utils/unexpected_filesystem_problem', :dir => PhusionPassenger.support_binaries_dir, :exception => result abort end end
mkdir_p_preserve_parent_owner(path)
click to toggle source
When creating PhusionPassenger.support_binaries_dir, preserve the parent directory's UID and GID. This way, running `passenger-config compile-agent` with sudo privileged, even though Phusion Passenger isn't installed as root, won't mess up permissions.
# File src/ruby_supportlib/phusion_passenger/config/installation_utils.rb, line 230 def mkdir_p_preserve_parent_owner(path) Pathname.new(path).descend do |subpath| if !subpath.exist? stat = subpath.parent.stat Dir.mkdir(subpath.to_s) if Process.euid == 0 File.chown(stat.uid, stat.gid, subpath.to_s) end end end end
myself()
click to toggle source
# File src/ruby_supportlib/phusion_passenger/config/installation_utils.rb, line 242 def myself return %xwhoami`.strip end
render_template(name, options = {})
click to toggle source
# File src/ruby_supportlib/phusion_passenger/config/installation_utils.rb, line 246 def render_template(name, options = {}) options.merge!(:colors => @colors || PhusionPassenger::Utils::AnsiColors.new) # This check here is necessary for NginxEngineCompiler. NginxEngineCompiler # derives from AbstractInstaller but also includes InstallationUtils. We want # the AbstractInstaller methods to work when they call render_template. if !File.exist?("#{PhusionPassenger.resources_dir}/templates/#{name}.txt.erb") name = "config/#{name}" end puts ConsoleTextTemplate.new({ :file => name }, options).result end