aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--railties/CHANGELOG2
-rw-r--r--railties/lib/commands/process/spawner.rb16
2 files changed, 15 insertions, 3 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG
index 112d91d355..355ed3167b 100644
--- a/railties/CHANGELOG
+++ b/railties/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* 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]
+
* Add verification to generated scaffolds, don't allow get for unsafe actions [Michael Koziarski]
* Don't replace application.js in public/javascripts if it already exists [Cody Fauser]
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