From 0c512ca990048d3ae22e9c19c728ade520e3acba Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Fri, 4 Nov 2005 20:58:38 +0000 Subject: script/lighttpd: tail the logfile when running in the foreground, and attempt to guess the port number git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2875 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- railties/lib/commands/lighttpd.rb | 49 +++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 12 deletions(-) (limited to 'railties/lib/commands') diff --git a/railties/lib/commands/lighttpd.rb b/railties/lib/commands/lighttpd.rb index 1b3212347b..6c2aeb64f9 100644 --- a/railties/lib/commands/lighttpd.rb +++ b/railties/lib/commands/lighttpd.rb @@ -1,16 +1,41 @@ -if RUBY_PLATFORM !~ /mswin/ && `lighttpd -version 2>/dev/null`.size > 0 - puts "=> Rails application started on http://0.0.0.0:3000" +unless RUBY_PLATFORM !~ /mswin/ && `lighttpd -version 2>/dev/null`.size > 0 + puts "lighttpd is not available on your system (or not in your path)" + exit 1 +end - if ARGV.first == "-d" - puts "=> Configure in config/lighttpd.conf" - detach = true - else - puts "=> Call with -d to detach (requires absolute paths in config/lighttpd.conf)" - puts "=> Ctrl-C to shutdown server (see config/lighttpd.conf for options)" - detach = false +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" - `lighttpd #{!detach ? "-D " : ""}-f #{RAILS_ROOT}/config/lighttpd.conf` +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}" + +if ARGV.first == "-d" + puts "=> Configure in config/lighttpd.conf" + detach = true else - puts "lighttpd is not available on your system (or not in your path)" -end \ No newline at end of file + puts "=> Call with -d to detach (requires absolute paths in config/lighttpd.conf)" + puts "=> Ctrl-C to shutdown server (see config/lighttpd.conf for options)" + detach = false + + 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} + end + rescue Exception + end + end +end + +`lighttpd #{!detach ? "-D " : ""}-f #{config_file}` -- cgit v1.2.3