From 0a072e8ed7256c8d555be1b6c910767c3578cd50 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 29 Jun 2006 00:31:45 +0000 Subject: Mongrel: script/server tails the rails log like it does with lighttpd. Closes #5541. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4506 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- railties/CHANGELOG | 2 ++ railties/lib/commands/servers/base.rb | 19 +++++++++++++++++++ railties/lib/commands/servers/lighttpd.rb | 19 ++----------------- railties/lib/commands/servers/mongrel.rb | 8 ++++++-- 4 files changed, 29 insertions(+), 19 deletions(-) create mode 100644 railties/lib/commands/servers/base.rb diff --git a/railties/CHANGELOG b/railties/CHANGELOG index ca87f29f01..0d697b763d 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Mongrel: script/server tails the rails log like it does with lighttpd. #5541 [mike@clarkware.com] + * Don't assume Active Record is available. #5497 [bob@sporkmonger.com] * Mongrel: script/server works on Win32. #5499 [jeremydurham@gmail.com] diff --git a/railties/lib/commands/servers/base.rb b/railties/lib/commands/servers/base.rb new file mode 100644 index 0000000000..25b2935524 --- /dev/null +++ b/railties/lib/commands/servers/base.rb @@ -0,0 +1,19 @@ +def tail(log_file) + cursor = File.size(log_file) + last_checked = Time.now + tail_thread = Thread.new do + File.open(log_file, 'r') do |f| + loop do + f.seek cursor + if f.mtime > last_checked + last_checked = f.mtime + contents = f.read + cursor += contents.length + print contents + end + sleep 1 + end + end + end + tail_thread +end diff --git a/railties/lib/commands/servers/lighttpd.rb b/railties/lib/commands/servers/lighttpd.rb index 34b51f21b8..1d5ca55f61 100644 --- a/railties/lib/commands/servers/lighttpd.rb +++ b/railties/lib/commands/servers/lighttpd.rb @@ -1,4 +1,5 @@ require 'rbconfig' +require 'commands/servers/base' unless RUBY_PLATFORM !~ /mswin/ && !silence_stderr { `lighttpd -version` }.blank? puts "PROBLEM: Lighttpd is not available on your system (or not in your path)" @@ -52,23 +53,7 @@ if !detach puts "=> Call with -d to detach" puts "=> Ctrl-C to shutdown server (see config/lighttpd.conf for options)" detach = false - - cursor = File.size(configuration.log_path) - last_checked = Time.now - tail_thread = Thread.new do - File.open(configuration.log_path, 'r') do |f| - loop do - f.seek cursor - if f.mtime > last_checked - last_checked = f.mtime - contents = f.read - cursor += contents.length - print contents - end - sleep 1 - end - end - end + tail_thread = tail(configuration.log_path) end trap(:INT) { exit } diff --git a/railties/lib/commands/servers/mongrel.rb b/railties/lib/commands/servers/mongrel.rb index b46923eb8f..a110cac7c4 100644 --- a/railties/lib/commands/servers/mongrel.rb +++ b/railties/lib/commands/servers/mongrel.rb @@ -1,4 +1,5 @@ require 'rbconfig' +require 'commands/servers/base' unless defined?(Mongrel) puts "PROBLEM: Mongrel is not available on your system (or not in your path)" @@ -26,16 +27,19 @@ end default_port, default_ip = 3000, '0.0.0.0' puts "=> Rails application started on http://#{ip || default_ip}:#{port || default_port}" +log_file = Pathname.new("#{RAILS_ROOT}/log/#{RAILS_ENV}.log").cleanpath + +tail_thread = nil + if !detach puts "=> Call with -d to detach" puts "=> Ctrl-C to shutdown server" detach = false + tail_thread = tail(log_file) end trap(:INT) { exit } -tail_thread = nil - begin ARGV.unshift("start") load 'mongrel_rails' -- cgit v1.2.3