# File lib/phusion_passenger/standalone/command.rb, line 49 def self.description return nil end
# File lib/phusion_passenger/standalone/command.rb, line 53 def initialize(args) @args = args.dup @original_args = args.dup @options = DEFAULT_OPTIONS.dup end
# File lib/phusion_passenger/standalone/command.rb, line 45 def self.show_in_command_list return true end
# File lib/phusion_passenger/standalone/command.rb, line 255 def boolean_config_value(val) return val ? "on" : "off" end
# File lib/phusion_passenger/standalone/command.rb, line 287 def create_nginx_controller(extra_options = {}) require_daemon_controller require 'socket' unless defined?(UNIXSocket) require 'thread' unless defined?(Mutex) if @options[:socket_file] ping_spec = [:unix, @options[:socket_file]] else ping_spec = [:tcp, @options[:address], nginx_ping_port] end opts = { :identifier => 'Nginx', :before_start => method(:write_nginx_config_file), :start_command => method(:determine_nginx_start_command), :ping_command => ping_spec, :pid_file => @options[:pid_file], :log_file => @options[:log_file], :timeout => 25 } @nginx = DaemonController.new(opts.merge(extra_options)) @nginx_mutex = Mutex.new end
# File lib/phusion_passenger/standalone/command.rb, line 103 def debugging? return ENV['PASSENGER_DEBUG'] && !ENV['PASSENGER_DEBUG'].empty? end
# File lib/phusion_passenger/standalone/command.rb, line 269 def determine_nginx_start_command if @options[:nginx_bin] nginx_bin = @options[:nginx_bin] else nginx_bin = @runtime_locator.find_nginx_binary end return "#{nginx_bin} -c '#{@config_filename}' -p '#{@temp_dir}/'" end
# File lib/phusion_passenger/standalone/command.rb, line 171 def determine_various_resource_locations(create_subdirs = true) require_app_finder if @options[:socket_file] pid_basename = "passenger.pid" log_basename = "passenger.log" else pid_basename = "passenger.#{@options[:port]}.pid" log_basename = "passenger.#{@options[:port]}.log" end if @args.empty? if AppFinder.looks_like_app_directory?(".") @options[:pid_file] ||= File.expand_path("tmp/pids/#{pid_basename}") @options[:log_file] ||= File.expand_path("log/#{log_basename}") if create_subdirs ensure_directory_exists(File.dirname(@options[:pid_file])) ensure_directory_exists(File.dirname(@options[:log_file])) end else @options[:pid_file] ||= File.expand_path(pid_basename) @options[:log_file] ||= File.expand_path(log_basename) end else @options[:pid_file] ||= File.expand_path(File.join(@args[0], pid_basename)) @options[:log_file] ||= File.expand_path(File.join(@args[0], log_basename)) end end
# File lib/phusion_passenger/standalone/command.rb, line 164 def ensure_directory_exists(dir) if !File.exist?(dir) require_file_utils FileUtils.mkdir_p(dir) end end
# File lib/phusion_passenger/standalone/command.rb, line 135 def error(message, options = {}) wrap = options.fetch(:wrap, true) if message =~ /\n/ if wrap processed_message = wrap_desc(message, 80, 0) else processed_message = message end STDERR.puts("*** ERROR ***\n" << processed_message) else if wrap processed_message = wrap_desc("*** ERROR: #{message}", 80, 0) else processed_message = "*** ERROR: #{message}" end STDERR.puts(processed_message) end @plugin.call_hook(:error, message) if @plugin end
# File lib/phusion_passenger/standalone/command.rb, line 246 def nginx_config_template_filename if @options[:nginx_config_template] return @options[:nginx_config_template] else return File.join(PhusionPassenger.resources_dir, "templates", "standalone", "config.erb") end end
Returns the port on which to ping Nginx.
# File lib/phusion_passenger/standalone/command.rb, line 279 def nginx_ping_port if @options[:ping_port] return @options[:ping_port] else return @options[:port] end end
# File lib/phusion_passenger/standalone/command.rb, line 107 def parse_options!(command_name, description = nil) help = false global_config_file = File.join(ENV['HOME'], USER_NAMESPACE_DIRNAME, "standalone", "config") if File.exist?(global_config_file) PhusionPassenger.require_passenger_lib 'standalone/config_file' unless defined?(ConfigFile) global_options = ConfigFile.new(:global_config, global_config_file).options @options.merge!(global_options) end require_optparse parser = OptionParser.new do |opts| opts.banner = "Usage: passenger #{command_name} [options]" opts.separator description if description opts.separator " " opts.separator "Options:" yield opts opts.on("-h", "--help", "Show this help message") do help = true end end parser.parse!(@args) if help puts parser exit 0 end end
# File lib/phusion_passenger/standalone/command.rb, line 99 def require_app_finder PhusionPassenger.require_passenger_lib 'standalone/app_finder' unless defined?(AppFinder) end
# File lib/phusion_passenger/standalone/command.rb, line 60 def require_daemon_controller if !defined?(DaemonController) begin require 'daemon_controller' begin require 'daemon_controller/version' too_old = DaemonController::VERSION_STRING < '1.1.0' rescue LoadError too_old = true end if too_old PhusionPassenger.require_passenger_lib 'platform_info/ruby' gem_command = PlatformInfo.gem_command(:sudo => true) error "Your version of daemon_controller is too old. " << "You must install 1.1.0 or later. Please upgrade:\n\n" << " #{gem_command} uninstall FooBarWidget-daemon_controller\n" << " #{gem_command} install daemon_controller", :wrap => false exit 1 end rescue LoadError PhusionPassenger.require_passenger_lib 'platform_info/ruby' gem_command = PlatformInfo.gem_command(:sudo => true) error "Please install daemon_controller first:\n\n" << " #{gem_command} install daemon_controller" exit 1 end end end
# File lib/phusion_passenger/standalone/command.rb, line 91 def require_erb require 'erb' unless defined?(ERB) end
# File lib/phusion_passenger/standalone/command.rb, line 95 def require_optparse require 'optparse' unless defined?(OptionParser) end
# File lib/phusion_passenger/standalone/command.rb, line 259 def serialize_strset(*items) if "".respond_to?(:force_encoding) items = items.map { |x| x.force_encoding('binary') } null = "\00"".force_encoding('binary') else null = "\00"" end return [items.join(null)].pack('m*').gsub("\n", "").strip end
Word wrap the given option description text so that it is formatted nicely in the –help output.
# File lib/phusion_passenger/standalone/command.rb, line 157 def wrap_desc(description_text, max_width = 43, newline_prefix_size = 37) line_prefix = "\n" << (' ' * newline_prefix_size) result = description_text.gsub(/(.{1,#{max_width}})( +|$\n?)|(.{1,#{max_width}})/, "\\1\\3#{line_prefix}") result.strip! return result end
# File lib/phusion_passenger/standalone/command.rb, line 198 def write_nginx_config_file PhusionPassenger.require_passenger_lib 'platform_info/ruby' PhusionPassenger.require_passenger_lib 'utils/tmpio' # @temp_dir may already be set because we're redeploying # using Mass Deployment. @temp_dir ||= PhusionPassenger::Utils.mktmpdir( "passenger-standalone.") @config_filename = "#{@temp_dir}/config" location_config_filename = "#{@temp_dir}/locations.ini" File.chmod(0755, @temp_dir) begin Dir.mkdir("#{@temp_dir}/logs") rescue Errno::EEXIST end locations_ini_fields = PhusionPassenger::REQUIRED_LOCATIONS_INI_FIELDS + PhusionPassenger::OPTIONAL_LOCATIONS_INI_FIELDS - [:agents_dir, :lib_dir] File.open(location_config_filename, 'w') do |f| f.puts '[locations]' f.puts "natively_packaged=#{PhusionPassenger.natively_packaged?}" if PhusionPassenger.natively_packaged? f.puts "native_packaging_method=#{PhusionPassenger.native_packaging_method}" end f.puts "lib_dir=#{@runtime_locator.find_lib_dir}" f.puts "agents_dir=#{@runtime_locator.find_agents_dir}" locations_ini_fields.each do |field| value = PhusionPassenger.send(field) f.puts "#{field}=#{value}" if value end end puts File.read(location_config_filename) if debugging? File.open(@config_filename, 'w') do |f| f.chmod(0644) require_erb erb = ERB.new(File.read(nginx_config_template_filename), nil, "-") current_user = Etc.getpwuid(Process.uid).name # The template requires some helper methods which are defined in start_command.rb. output = erb.result(binding) f.write(output) puts output if debugging? end end