diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2006-02-26 20:25:24 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2006-02-26 20:25:24 +0000 |
commit | 09f89c4abf7a3cbff79426f2446bfc05fd1b18a6 (patch) | |
tree | 09d1c337121b1440a46ec897390524e20d666edf /railties/lib/commands | |
parent | 1215d54c2f31c4d19b2432ab05751fe2eaec0319 (diff) | |
download | rails-09f89c4abf7a3cbff79426f2446bfc05fd1b18a6.tar.gz rails-09f89c4abf7a3cbff79426f2446bfc05fd1b18a6.tar.bz2 rails-09f89c4abf7a3cbff79426f2446bfc05fd1b18a6.zip |
Added -r/--repeat option to script/process/spawner that offers the same loop protection as the spinner did. This deprecates the script/process/spinner, so it's no longer included in the default Rails skeleton, but still available for backwards compatibility (closes #3461) [ror@andreas-s.net]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3672 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/lib/commands')
-rw-r--r-- | railties/lib/commands/process/spawner.rb | 25 |
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 |