$OpenBSD: patch-lib_phusion_passenger_standalone_start_command_rb,v 1.2 2014/06/24 21:45:06 jeremy Exp $

The if false removes a method that tries to download and compile nginx and
install it into the user's home directory (even if you change HOME!)

We compile the standalone version of nginx in advance and place it in the
gem standalone directory so there isn't a need to compile at runtime.

Add a rescue clause so that attempting to kill a process that may or may not
exist doesn't raise an error.

--- lib/phusion_passenger/standalone/start_command.rb.orig	Thu May 29 05:13:26 2014
+++ lib/phusion_passenger/standalone/start_command.rb	Thu Jun  5 14:16:51 2014
@@ -389,13 +389,13 @@ private
 				sockaddr = Socket.pack_sockaddr_in(port, address)
 				begin
 					socket.connect_nonblock(sockaddr)
-				rescue Errno::ENOENT, Errno::EINPROGRESS, Errno::EAGAIN, Errno::EWOULDBLOCK
+				rescue Errno::ENOENT, Errno::EINPROGRESS, Errno::EAGAIN, Errno::EWOULDBLOCK, Errno::EINVAL
 					if select(nil, [socket], nil, 0.1)
 						begin
 							socket.connect_nonblock(sockaddr)
 						rescue Errno::EISCONN
 						rescue Errno::EINVAL
-							if PlatformInfo.os_name =~ /freebsd/i
+							if PlatformInfo.os_name =~ /bsd/i
 								raise Errno::ECONNREFUSED
 							else
 								raise
@@ -477,24 +477,12 @@ private
 			:dont_compile_runtime => @options[:dont_compile_runtime],
 			:plugin      => @plugin)
 		return installer.run
-	end
+	end if false
 
 	def ensure_runtime_installed
-		if @runtime_locator.everything_installed?
-			if !File.exist?(@runtime_locator.find_nginx_binary)
-				error "The web helper binary '#{@runtime_locator.find_nginx_binary}' does not exist."
-				exit 1
-			end
-		else
-			if !@runtime_locator.find_support_dir && PhusionPassenger.natively_packaged?
-				error "Your Phusion Passenger Standalone installation is broken: the support " +
-					"files could not be found. Please reinstall Phusion Passenger Standalone. " +
-					"If this problem persists, please contact your packager."
-				exit 1
-			end
-			install_runtime(@runtime_locator) || exit(1)
-			@runtime_locator.reload
-		end
+		gem_root_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__))))
+		@options[:runtime_dir] = File.join(gem_root_dir, 'standalone')
+		@runtime_locator.reload
 	end
 
 	def set_stdout_stderr_binmode
@@ -675,7 +663,7 @@ private
 			if @options[:socket_file]
 				socket = UNIXSocket.new(@options[:socket_file])
 			else
-				socket = TCPSocket.new(@options[:address], nginx_ping_port)
+				socket = TCPSocket.new(@options[:address] == '0.0.0.0' ? '127.0.0.1' : @options[:address], nginx_ping_port)
 			end
 			begin
 				socket.read rescue nil
