From 73a697c38a842dfa725185b73af3b04a49ba3d3f Mon Sep 17 00:00:00 2001 From: Nicholas Seckar Date: Wed, 9 Nov 2005 22:57:05 +0000 Subject: Don't detach or fork for script/server tailing git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2961 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- railties/lib/commands/servers/lighttpd.rb | 38 +++++++++++++++---------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'railties/lib/commands/servers') diff --git a/railties/lib/commands/servers/lighttpd.rb b/railties/lib/commands/servers/lighttpd.rb index 6e3da4a9f8..456c6e0e9e 100644 --- a/railties/lib/commands/servers/lighttpd.rb +++ b/railties/lib/commands/servers/lighttpd.rb @@ -8,16 +8,6 @@ unless defined?(FCGI) exit 1 end -def tail_f(input) - loop do - line = input.gets - yield line if line - if input.eof? - sleep 1 - input.seek(input.tell) - end - end -end config_file = "#{RAILS_ROOT}/config/lighttpd.conf" @@ -32,6 +22,8 @@ end port = IO.read(config_file).scan(/^server.port\s*=\s*(\d+)/).first rescue 3000 puts "=> Rails application started on http://0.0.0.0:#{port}" +tail_thread = nil + if ARGV.first == "-d" puts "=> Configure in config/lighttpd.conf" detach = true @@ -40,18 +32,26 @@ else puts "=> Ctrl-C to shutdown server (see config/lighttpd.conf for options)" detach = false - Process.detach(fork do - begin - File.open("#{RAILS_ROOT}/log/#{RAILS_ENV}.log", 'r') do |log| - log.seek(0, IO::SEEK_END) - tail_f(log) {|line| puts line} + log_path = "#{RAILS_ROOT}/log/#{RAILS_ENV}.log" + cursor = File.size(log_path) + last_checked = Time.now + tail_thread = Thread.new do + File.open(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 - rescue Exception end - exit - end) + end end trap(:INT) { exit } Thread.new { sleep 0.5; `open http://0.0.0.0:#{port}` } if RUBY_PLATFORM =~ /darwin/ -`lighttpd #{!detach ? "-D " : ""}-f #{config_file}` \ No newline at end of file +`lighttpd #{!detach ? "-D " : ""}-f #{config_file}` +tail_thread.kill if tail_thread \ No newline at end of file -- cgit v1.2.3