aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/commands/process/spawner.rb
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib/commands/process/spawner.rb')
-rw-r--r--railties/lib/commands/process/spawner.rb25
1 files changed, 22 insertions, 3 deletions
diff --git a/railties/lib/commands/process/spawner.rb b/railties/lib/commands/process/spawner.rb
index 465017d8a4..031beb4c15 100644
--- a/railties/lib/commands/process/spawner.rb
+++ b/railties/lib/commands/process/spawner.rb
@@ -1,16 +1,21 @@
require 'optparse'
def spawn(port)
- print "Starting FCGI on port: #{port}\n "
+ puts "Starting FCGI on port: #{port}"
system("#{OPTIONS[:spawner]} -f #{OPTIONS[:dispatcher]} -p #{port}")
end
+def spawn_all
+ OPTIONS[:instances].times { |i| spawn(OPTIONS[:port] + i) }
+end
+
OPTIONS = {
:environment => "production",
:spawner => '/usr/bin/env spawn-fcgi',
:dispatcher => File.expand_path(RAILS_ROOT + '/public/dispatch.fcgi'),
:port => 8000,
- :instances => 3
+ :instances => 3,
+ :repeat => nil
}
ARGV.options do |opts|
@@ -28,15 +33,20 @@ ARGV.options do |opts|
You decide a starting port (default is 8000) and the number of FCGI process instances you'd
like to run. So if you pick 9100 and 3 instances, you'll start processes on 9100, 9101, and 9102.
+ By setting the repeat option, you get a protection loop, which will attempt to restart any FCGI processes
+ that might have been exited or outright crashed.
+
Examples:
spawner # starts instances on 8000, 8001, and 8002
spawner -p 9100 -i 10 # starts 10 instances counting from 9100 to 9109
+ spawner -p 9100 -r 5 # starts 3 instances counting from 9100 to 9102 and attempts start them every 5 seconds
EOF
opts.on(" Options:")
opts.on("-p", "--port=number", Integer, "Starting port number (default: #{OPTIONS[:port]})") { |OPTIONS[:port]| }
opts.on("-i", "--instances=number", Integer, "Number of instances (default: #{OPTIONS[:instances]})") { |OPTIONS[:instances]| }
+ opts.on("-r", "--repeat=seconds", Integer, "Repeat spawn attempts every n seconds (default: off)") { |OPTIONS[:repeat]| }
opts.on("-e", "--environment=name", String, "test|development|production (default: #{OPTIONS[:environment]})") { |OPTIONS[:environment]| }
opts.on("-s", "--spawner=path", String, "default: #{OPTIONS[:spawner]}") { |OPTIONS[:spawner]| }
opts.on("-d", "--dispatcher=path", String, "default: #{OPTIONS[:dispatcher]}") { |dispatcher| OPTIONS[:dispatcher] = File.expand_path(dispatcher) }
@@ -49,4 +59,13 @@ ARGV.options do |opts|
end
ENV["RAILS_ENV"] = OPTIONS[:environment]
-OPTIONS[:instances].times { |i| spawn(OPTIONS[:port] + i) } \ No newline at end of file
+
+if OPTIONS[:repeat]
+ loop do
+ spawn_all
+ puts "Sleeping for #{OPTIONS[:repeat]} seconds"
+ sleep OPTIONS[:repeat]
+ end
+else
+ spawn_all
+end