Skip to content

Commit

Permalink
Mongrel: script/server tails the rails log like it does with lighttpd.
Browse files Browse the repository at this point in the history
…Closes #5541.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4506 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jeremy committed Jun 29, 2006
1 parent ce458a7 commit 0a072e8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
2 changes: 2 additions & 0 deletions 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]
Expand Down
19 changes: 19 additions & 0 deletions 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
19 changes: 2 additions & 17 deletions 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)"
Expand Down Expand Up @@ -52,23 +53,7 @@
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 }
Expand Down
8 changes: 6 additions & 2 deletions 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)"
Expand Down Expand Up @@ -26,16 +27,19 @@
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'
Expand Down

0 comments on commit 0a072e8

Please sign in to comment.