From 8bf987140a40a523a34bb6a52dd23afb99f92331 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 18 Mar 2006 19:21:54 +0000 Subject: Added 'port open?' check to the spawner when running in repeat mode so we don't needlessly boot the dispatcher if the port is already in use anyway #4089 [guy.naor@famundo.com] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3938 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- railties/lib/commands/process/spawner.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'railties/lib/commands') diff --git a/railties/lib/commands/process/spawner.rb b/railties/lib/commands/process/spawner.rb index 031beb4c15..47259979d6 100644 --- a/railties/lib/commands/process/spawner.rb +++ b/railties/lib/commands/process/spawner.rb @@ -1,10 +1,20 @@ require 'optparse' +require 'socket' def spawn(port) - puts "Starting FCGI on port: #{port}" - system("#{OPTIONS[:spawner]} -f #{OPTIONS[:dispatcher]} -p #{port}") + print "Checking if something is already running on port #{port}..." + begin + srv = TCPServer.new('0.0.0.0', port) + srv.close + srv = nil + print "NO\n " + print "Starting FCGI on port: #{port}\n " + system("#{OPTIONS[:spawner]} -f #{OPTIONS[:dispatcher]} -p #{port}") + rescue + print "YES\n" + end end - + def spawn_all OPTIONS[:instances].times { |i| spawn(OPTIONS[:port] + i) } end -- cgit v1.2.3