Skip to content
Browse files

Added -r/--repeat option to script/process/spawner that offers the sa…

…me 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
  • Loading branch information...
1 parent 1215d54 commit 09f89c4abf7a3cbff79426f2446bfc05fd1b18a6 @dhh dhh committed Feb 26, 2006
View
2 railties/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* 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 #3461 [ror@andreas-s.net]
+
* Added collision option to template generation in generators #3329 [anna@wota.jp]. Examples:
m.template "stuff.config" , "config/stuff.config" , :collision => :skip
View
2 railties/Rakefile
@@ -41,7 +41,7 @@ LOG_FILES = %w( server.log development.log test.log production.log )
HTML_FILES = %w( 404.html 500.html index.html robots.txt favicon.ico images/rails.png
javascripts/prototype.js
javascripts/effects.js javascripts/dragdrop.js javascripts/controls.js )
-BIN_FILES = %w( about breakpointer console destroy generate performance/benchmarker performance/profiler process/reaper process/spawner process/spinner runner server plugin )
+BIN_FILES = %w( about breakpointer console destroy generate performance/benchmarker performance/profiler process/reaper process/spawner runner server plugin )
VENDOR_LIBS = %w( actionpack activerecord actionmailer activesupport actionwebservice railties )
View
3 railties/bin/process/spinner
@@ -1,3 +0,0 @@
-#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../config/boot'
-require 'commands/process/spinner'
View
25 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 @@ def spawn(port)
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 @@ def spawn(port)
end
ENV["RAILS_ENV"] = OPTIONS[:environment]
-OPTIONS[:instances].times { |i| spawn(OPTIONS[:port] + i) }
+
+if OPTIONS[:repeat]
+ loop do
+ spawn_all
+ puts "Sleeping for #{OPTIONS[:repeat]} seconds"
+ sleep OPTIONS[:repeat]
+ end
+else
+ spawn_all
+end
View
2 railties/lib/rails_generator/generators/applications/app/app_generator.rb
@@ -47,7 +47,7 @@ def manifest
m.file "environments/test.rb", "config/environments/test.rb"
# Scripts
- %w( about breakpointer console destroy generate performance/benchmarker performance/profiler process/reaper process/spawner process/spinner runner server plugin ).each do |file|
+ %w( about breakpointer console destroy generate performance/benchmarker performance/profiler process/reaper process/spawner runner server plugin ).each do |file|
m.file "bin/#{file}", "script/#{file}", script_options
end

0 comments on commit 09f89c4

Please sign in to comment.
Something went wrong with that request. Please try again.