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
This commit is contained in:
parent
a6106e4ec6
commit
0c512ca990
@ -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]
|
||||
|
@ -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"
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
`lighttpd #{!detach ? "-D " : ""}-f #{RAILS_ROOT}/config/lighttpd.conf`
|
||||
else
|
||||
unless RUBY_PLATFORM !~ /mswin/ && `lighttpd -version 2>/dev/null`.size > 0
|
||||
puts "lighttpd is not available on your system (or not in your path)"
|
||||
end
|
||||
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"
|
||||
|
||||
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 "=> 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}`
|
||||
|
Loading…
Reference in New Issue
Block a user