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
This commit is contained in:
Jeremy Kemper
2006-06-29 00:31:45 +00:00
parent ce458a74a5
commit 0a072e8ed7
4 changed files with 29 additions and 19 deletions

View File

@@ -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]

View File

@@ -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

View File

@@ -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 }

View File

@@ -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'