aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--railties/CHANGELOG4
-rw-r--r--railties/lib/commands/lighttpd.rb49
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}`