aboutsummaryrefslogtreecommitdiffstats
path: root/railties/bin/process/spawner
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-07-24 07:57:10 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-07-24 07:57:10 +0000
commitd75481c5808085935e94fcbf6460c7685ef26396 (patch)
tree4e80c3fc2dba459fb1aaab79836caaf2641f7b05 /railties/bin/process/spawner
parenteddd7c453b9f34ec95b64d1dee9b8fcf560a4b29 (diff)
downloadrails-d75481c5808085935e94fcbf6460c7685ef26396.tar.gz
rails-d75481c5808085935e94fcbf6460c7685ef26396.tar.bz2
rails-d75481c5808085935e94fcbf6460c7685ef26396.zip
Added convenience controls for FCGI processes (especially when managed remotely): spinner, spawner, and reaper. They reside in script/process. More details can be had by calling them with -h/--help
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1909 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/bin/process/spawner')
-rwxr-xr-xrailties/bin/process/spawner54
1 files changed, 54 insertions, 0 deletions
diff --git a/railties/bin/process/spawner b/railties/bin/process/spawner
new file mode 100755
index 0000000000..2ac0df04f8
--- /dev/null
+++ b/railties/bin/process/spawner
@@ -0,0 +1,54 @@
+#!/usr/local/bin/ruby
+
+require 'optparse'
+
+def spawn(port)
+ print "Starting FCGI on port: #{port}\n "
+ system("#{OPTIONS[:spawner]} -f #{OPTIONS[:dispatcher]} -p #{port}")
+end
+
+OPTIONS = {
+ :environment => "production",
+ :spawner => '/usr/bin/env spawn-fcgi',
+ :dispatcher => File.expand_path(File.dirname(__FILE__) + '/../../public/dispatch.fcgi'),
+ :port => 8000,
+ :instances => 3
+}
+
+ARGV.options do |opts|
+ opts.banner = "Usage: spawner [options]"
+
+ opts.separator ""
+
+ opts.on <<-EOF
+ Description:
+ The spawner is a wrapper for spawn-fcgi that makes it easier to start multiple FCGI
+ processes running the Rails dispatcher. The spawn-fcgi command is included with the lighttpd
+ web server, but can be used with both Apache and lighttpd (and any other web server supporting
+ externally managed FCGI processes).
+
+ 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.
+
+ Examples:
+ spawner # starts instances on 8000, 8001, and 8002
+ spawner -p 9100 -i 10 # starts 10 instances counting from 9100 to 9109
+ 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("-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) }
+
+ opts.separator ""
+
+ opts.on("-h", "--help", "Show this help message.") { puts opts; exit }
+
+ opts.parse!
+end
+
+ENV["RAILS_ENV"] = OPTIONS[:environment]
+OPTIONS[:instances].times { |i| spawn(OPTIONS[:port] + i) } \ No newline at end of file