module PhusionPassenger::Standalone::StartCommand::NginxEngine
Private Instance Methods
boolean_config_value(val)
click to toggle source
# File src/ruby_supportlib/phusion_passenger/standalone/start_command/nginx_engine.rb, line 183 def boolean_config_value(val) return val ? "on" : "off" end
build_daemon_controller_options()
click to toggle source
# File src/ruby_supportlib/phusion_passenger/standalone/start_command/nginx_engine.rb, line 90 def build_daemon_controller_options if @options[:socket_file] ping_spec = [:unix, @options[:socket_file]] else ping_spec = [:tcp, @options[:address], @options[:port]] end return { :identifier => 'Nginx', :start_command => "#{@nginx_binary} " + "-c #{Shellwords.escape nginx_config_path} " + "-p #{Shellwords.escape @working_dir}", :ping_command => ping_spec, :pid_file => @options[:pid_file], :log_file => @options[:log_file], :timeout => 25 } end
debugging?()
click to toggle source
# File src/ruby_supportlib/phusion_passenger/standalone/start_command/nginx_engine.rb, line 135 def debugging? return ENV['PASSENGER_DEBUG'] && !ENV['PASSENGER_DEBUG'].empty? end
default_group_for(username)
click to toggle source
# File src/ruby_supportlib/phusion_passenger/standalone/start_command/nginx_engine.rb, line 157 def default_group_for(username) user = Etc.getpwnam(username) group = Etc.getgrgid(user.gid) return group.name end
nginx_config_path()
click to toggle source
# File src/ruby_supportlib/phusion_passenger/standalone/start_command/nginx_engine.rb, line 108 def nginx_config_path return "#{@working_dir}/nginx.conf" end
nginx_config_template_filename()
click to toggle source
# File src/ruby_supportlib/phusion_passenger/standalone/start_command/nginx_engine.rb, line 126 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
nginx_listen_address(options = @options)
click to toggle source
Config file template helpers ####
# File src/ruby_supportlib/phusion_passenger/standalone/start_command/nginx_engine.rb, line 141 def nginx_listen_address(options = @options) if options[:socket_file] "unix:#{options[:socket_file]}" else compose_ip_and_port(options[:address], options[:port]) end end
nginx_listen_address_with_ssl_port(options = @options)
click to toggle source
# File src/ruby_supportlib/phusion_passenger/standalone/start_command/nginx_engine.rb, line 149 def nginx_listen_address_with_ssl_port(options = @options) if options[:socket_file] "unix:#{options[:socket_file]}" else compose_ip_and_port(options[:address], options[:ssl_port]) end end
nginx_option(nginx_config_name, option_name)
click to toggle source
# File src/ruby_supportlib/phusion_passenger/standalone/start_command/nginx_engine.rb, line 163 def nginx_option(nginx_config_name, option_name) if @options.has_key?(option_name) value = @options[option_name] if value.is_a?(String) value = "'#{value}'" elsif value == true value = "on" elsif value == false value = "off" end "#{nginx_config_name} #{value};" end end
serialize_strset(*items)
click to toggle source
# File src/ruby_supportlib/phusion_passenger/standalone/start_command/nginx_engine.rb, line 187 def serialize_strset(*items) if "".respond_to?(:force_encoding) items = items.map { |x| x.force_encoding('binary') } null = "\0".force_encoding('binary') else null = "\0" end return [items.join(null)].pack('m*').gsub("\n", "").strip end
start_engine_real()
click to toggle source
# File src/ruby_supportlib/phusion_passenger/standalone/start_command/nginx_engine.rb, line 38 def start_engine_real Standalone::ControlUtils.require_daemon_controller @engine = DaemonController.new(build_daemon_controller_options) write_nginx_config_file(nginx_config_path) begin @engine.start rescue DaemonController::AlreadyStarted begin pid = @engine.pid rescue SystemCallError, IOError pid = nil end if pid abort "#{PROGRAM_NAME} Standalone is already running on PID #{pid}." else abort "#{PROGRAM_NAME} Standalone is already running." end rescue DaemonController::StartError => e abort "Could not start the Nginx engine:\n#{e}" end end
wait_until_engine_has_exited()
click to toggle source
# File src/ruby_supportlib/phusion_passenger/standalone/start_command/nginx_engine.rb, line 61 def wait_until_engine_has_exited # Since the engine is not our child process (it daemonizes) # we cannot use Process.waitpid to wait for it. A busy-sleep-loop with # Process.kill(0, pid) isn't very efficient. Instead we do this: # # Connect to the engine's server and wait until it disconnects the socket # because of timeout. Keep doing this until we can no longer connect. while true if @options[:socket_file] socket = UNIXSocket.new(@options[:socket_file]) else socket = TCPSocket.new(@options[:address], @options[:port]) end begin begin socket.read rescue SystemCallError, IOError, SocketError end ensure begin socket.close rescue SystemCallError, IOError, SocketError end end end rescue Errno::ECONNREFUSED, Errno::ECONNRESET end
write_nginx_config_file(path)
click to toggle source
# File src/ruby_supportlib/phusion_passenger/standalone/start_command/nginx_engine.rb, line 112 def write_nginx_config_file(path) File.open(path, 'w') do |f| f.chmod(0644) erb = ERB.new(File.read(nginx_config_template_filename), nil, "-") erb.filename = nginx_config_template_filename 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