Changeset 4570
- Timestamp:
- 07/06/06 17:21:42 (2 years ago)
- Files:
-
- trunk/railties/lib/commands/process/spawner.rb (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/railties/lib/commands/process/spawner.rb
r4502 r4570 1 require 'active_support' 1 2 require 'optparse' 2 3 require 'socket' … … 30 31 srv = nil 31 32 32 p rint "NO\n"33 p rint "Starting FCGI on port: #{port}\n"33 puts "NO" 34 puts "Starting dispatcher on port: #{port}" 34 35 35 36 FileUtils.mkdir_p(OPTIONS[:pids]) 36 37 spawn(port) 37 38 rescue 38 p rint "YES\n"39 puts "YES" 39 40 end 40 41 end … … 48 49 end 49 50 50 # TODO: 51 # class MongrelSpawner < Spawner 52 # def self.spawn(port) 53 # end 54 # end 51 class MongrelSpawner < Spawner 52 def self.spawn(port) 53 system("mongrel_rails start -d -p #{port} -P #{OPTIONS[:pids]}/#{OPTIONS[:process]}.#{port}.pid -e #{OPTIONS[:environment]}") 54 end 55 end 56 57 58 begin 59 require_library_or_gem 'fcgi' 60 rescue Exception 61 # FCGI not available 62 end 63 64 begin 65 require_library_or_gem 'mongrel' 66 rescue Exception 67 # Mongrel not available 68 end 69 70 server = case ARGV.first 71 when "fcgi", "mongrel" 72 ARGV.shift 73 else 74 if defined?(Mongrel) 75 "mongrel" 76 elsif RUBY_PLATFORM !~ /mswin/ && !silence_stderr { `spawn-fcgi -version` }.blank? && defined?(FCGI) 77 "fcgi" 78 end 79 end 80 81 case server 82 when "fcgi" 83 puts "=> Starting FCGI dispatchers" 84 spawner_class = FcgiSpawner 85 when "mongrel" 86 puts "=> Starting mongrel dispatchers" 87 spawner_class = MongrelSpawner 88 else 89 puts "Neither FCGI (spawn-fcgi) nor Mongrel was installed and available!" 90 exit(0) 91 end 92 55 93 56 94 … … 67 105 68 106 ARGV.options do |opts| 69 opts.banner = "Usage: spawner [ options]"107 opts.banner = "Usage: spawner [platform] [options]" 70 108 71 109 opts.separator "" … … 73 111 opts.on <<-EOF 74 112 Description: 75 The spawner is a wrapper for spawn-fcgi that makes it easier to start multiple FCGI113 The spawner is a wrapper for spawn-fcgi and mongrel that makes it easier to start multiple 76 114 processes running the Rails dispatcher. The spawn-fcgi command is included with the lighttpd 77 115 web server, but can be used with both Apache and lighttpd (and any other web server supporting 78 externally managed FCGI processes). 116 externally managed FCGI processes). Mongrel automatically ships with with mongrel_rails for starting 117 dispatchers. 118 119 The first choice you need to make is whether to spawn the Rails dispatchers as FCGI or Mongrel. By default, 120 this spawner will prefer Mongrel, so if that's installed, and no platform choice is made, Mongrel is used. 79 121 80 Youdecide a starting port (default is 8000) and the number of FCGI process instances you'd122 Then decide a starting port (default is 8000) and the number of FCGI process instances you'd 81 123 like to run. So if you pick 9100 and 3 instances, you'll start processes on 9100, 9101, and 9102. 82 124 … … 85 127 86 128 Examples: 87 spawner # starts instances on 8000, 8001, and 8002 88 spawner -p 9100 -i 10 # starts 10 instances counting from 9100 to 9109 129 spawner # starts instances on 8000, 8001, and 8002 using Mongrel if available 130 spawner fcgi # starts instances on 8000, 8001, and 8002 using FCGI 131 spawner mongrel -i 5 # starts instances on 8000, 8001, 8002, 8003, and 8004 using Mongrel 132 spawner -p 9100 -i 10 # starts 10 instances counting from 9100 to 9109 using Mongrel if available 89 133 spawner -p 9100 -r 5 # starts 3 instances counting from 9100 to 9102 and attempts start them every 5 seconds 90 134 EOF … … 112 156 daemonize 113 157 trap("TERM") { exit } 114 FcgiSpawner.record_pid158 spawner_class.record_pid 115 159 116 160 loop do 117 FcgiSpawner.spawn_all161 spawner_class.spawn_all 118 162 sleep(OPTIONS[:repeat]) 119 163 end 120 164 else 121 FcgiSpawner.spawn_all165 spawner_class.spawn_all 122 166 end