aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-06-23 22:32:10 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-06-23 22:32:10 +0000
commit8b89bd779a1ddc78da63de295574b8519c3e94c8 (patch)
treeed158214af6103059a3a5b8ff323edf36cc95c53
parentb533431ce5ec76ac531a4b303aea3afd35a4dde9 (diff)
downloadrails-8b89bd779a1ddc78da63de295574b8519c3e94c8.tar.gz
rails-8b89bd779a1ddc78da63de295574b8519c3e94c8.tar.bz2
rails-8b89bd779a1ddc78da63de295574b8519c3e94c8.zip
Mongrel support for script/server. Closes #5475.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4486 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--railties/CHANGELOG2
-rw-r--r--railties/lib/commands/server.rb17
-rw-r--r--railties/lib/commands/servers/mongrel.rb46
3 files changed, 58 insertions, 7 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG
index cef30c0e72..c01ab4f01c 100644
--- a/railties/CHANGELOG
+++ b/railties/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Mongrel support for script/server. #5475 [jeremydurham@gmail.com]
+
* Fix script/plugin so it doesn't barf on invalid URLs [Rick]
* Fix plugin install bug at dir with space. (closes #5359) [Yoshimasa NIWA]
diff --git a/railties/lib/commands/server.rb b/railties/lib/commands/server.rb
index 0857a5756a..1a8d3fd29d 100644
--- a/railties/lib/commands/server.rb
+++ b/railties/lib/commands/server.rb
@@ -8,22 +8,25 @@ rescue Exception
end
server = case ARGV.first
- when "lighttpd"
- ARGV.shift
- when "webrick"
+ when "lighttpd", "mongrel", "webrick"
ARGV.shift
else
if RUBY_PLATFORM !~ /mswin/ && !silence_stderr { `lighttpd -version` }.blank? && defined?(FCGI)
"lighttpd"
+ elsif !silence_stderr { `mongrel_rails -v` }.blank?
+ "mongrel"
else
"webrick"
end
end
-if server == "webrick"
- puts "=> Booting WEBrick..."
-else
- puts "=> Booting lighttpd (use 'script/server webrick' to force WEBrick)"
+case server
+ when "webrick"
+ puts "=> Booting WEBrick..."
+ when "lighttpd"
+ puts "=> Booting lighttpd (use 'script/server webrick' to force WEBrick)"
+ when "mongrel"
+ puts "=> Booting Mongrel (use 'script/server webrick' to force WEBrick)"
end
['sessions', 'cache', 'sockets'].each { |dir_to_make| FileUtils.mkdir_p(File.join(RAILS_ROOT, 'tmp', dir_to_make)) }
diff --git a/railties/lib/commands/servers/mongrel.rb b/railties/lib/commands/servers/mongrel.rb
new file mode 100644
index 0000000000..6d42316ba2
--- /dev/null
+++ b/railties/lib/commands/servers/mongrel.rb
@@ -0,0 +1,46 @@
+require 'rbconfig'
+
+unless RUBY_PLATFORM !~ /mswin/ && !silence_stderr { `mongrel_rails` }.blank?
+ puts "PROBLEM: Mongrel is not available on your system (or not in your path)"
+ exit 1
+end
+
+require 'optparse'
+
+detach = false
+ip = nil
+port = nil
+
+ARGV.options do |opt|
+ opt.on("-p", "--port=port", Integer,
+ "Runs Rails on the specified port.",
+ "Default: 3000") { |p| port = p }
+ opt.on("-b", "--binding=ip", String,
+ "Binds Rails to the specified ip.",
+ "Default: 0.0.0.0") { |i| ip = i }
+ opt.on('-h', '--help', 'Show this message.') { puts opt; exit 0 }
+ opt.on('-d', '-d', 'Call with -d to detach') { detach = true }
+ opt.parse!
+end
+
+default_port, default_ip = 3000, '0.0.0.0'
+puts "=> Rails application started on http://#{ip || default_ip}:#{port || default_port}"
+
+if !detach
+ puts "=> Call with -d to detach"
+ puts "=> Ctrl-C to shutdown server"
+ detach = false
+end
+
+trap(:INT) { exit }
+
+tail_thread = nil
+
+begin
+ `mongrel_rails start #{detach ? "-d " : ""} -p #{port || default_port} -a #{ip || default_ip}`
+ensure
+ unless detach
+ tail_thread.kill if tail_thread
+ puts 'Exiting'
+ end
+end