Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit 0a072e8ed7256c8d555be1b6c910767c3578cd50 1 parent ce458a7
@jeremy jeremy authored
View
2  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]
View
19 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
View
19 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 @@
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
8 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 @@
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'
Please sign in to comment.
Something went wrong with that request. Please try again.