diff options
author | Sam Stephenson <sam@37signals.com> | 2005-11-04 20:58:38 +0000 |
---|---|---|
committer | Sam Stephenson <sam@37signals.com> | 2005-11-04 20:58:38 +0000 |
commit | 0c512ca990048d3ae22e9c19c728ade520e3acba (patch) | |
tree | af861de89d4f833e8b0b82076131ac5f58771c66 | |
parent | a6106e4ec645c0dc799ce7666d2a28b46ea6126d (diff) | |
download | rails-0c512ca990048d3ae22e9c19c728ade520e3acba.tar.gz rails-0c512ca990048d3ae22e9c19c728ade520e3acba.tar.bz2 rails-0c512ca990048d3ae22e9c19c728ade520e3acba.zip |
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
-rw-r--r-- | railties/CHANGELOG | 4 | ||||
-rw-r--r-- | railties/lib/commands/lighttpd.rb | 49 |
2 files changed, 41 insertions, 12 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG index d4f929e60c..a67872b92a 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,5 +1,9 @@ *SVN* +* Tail the logfile when running script/lighttpd in the foreground [Sam Stephenson] + +* Try to guess the port number from config/lighttpd.conf in script/lighttpd [Sam Stephenson] + * Don't reap spawn-fcgi. #2727 [matthew@walker.wattle.id.au] * Reaper knows how to find processes even if the dispatch path is very long. #2711 [matthew@walker.wattle.id.au] 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}` |