diff options
author | Nicholas Seckar <nseckar@gmail.com> | 2005-11-09 22:57:05 +0000 |
---|---|---|
committer | Nicholas Seckar <nseckar@gmail.com> | 2005-11-09 22:57:05 +0000 |
commit | 73a697c38a842dfa725185b73af3b04a49ba3d3f (patch) | |
tree | bd9e9b26ec346fe2415c7b92992701e9cfc9ac15 | |
parent | c7e5c27b51154b3c3a164cf84f08425b2e00e1d8 (diff) | |
download | rails-73a697c38a842dfa725185b73af3b04a49ba3d3f.tar.gz rails-73a697c38a842dfa725185b73af3b04a49ba3d3f.tar.bz2 rails-73a697c38a842dfa725185b73af3b04a49ba3d3f.zip |
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
-rw-r--r-- | railties/CHANGELOG | 2 | ||||
-rw-r--r-- | railties/lib/commands/servers/lighttpd.rb | 38 |
2 files changed, 21 insertions, 19 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG index a053835eba..94ce0d71af 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Don't detach or fork for script/server tailing [Nicholas Seckar] + * Added automatic browser launching on OS X when starting script/server [DHH] * Changed all script/* to use #!/usr/bin/env ruby instead of hard-coded Ruby path. public/dispatcher.* still uses the hard-coded path for compatibility with web servers that don't have Ruby in path [DHH] 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 |