提交 833d9c89 编写于 作者: S Sam Stephenson

Run initialize_logger in script/lighttpd to ensure the log file exists before tailing it

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3198 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 191dfe8c
*SVN* *SVN*
* Run initialize_logger in script/lighttpd to ensure the log file exists before tailing it. [Sam Stephenson]
* Make load_fixtures include csv fixtures. #3053. [me@mdaines.com] * Make load_fixtures include csv fixtures. #3053. [me@mdaines.com]
* Fix freeze_gems so that the latest rails version is dumped by default. [Nicholas Seckar] * Fix freeze_gems so that the latest rails version is dumped by default. [Nicholas Seckar]
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
exit 1 exit 1
end end
require 'initializer'
configuration = Rails::Initializer.run(:initialize_logger).configuration
config_file = "#{RAILS_ROOT}/config/lighttpd.conf" config_file = "#{RAILS_ROOT}/config/lighttpd.conf"
...@@ -21,8 +23,8 @@ ...@@ -21,8 +23,8 @@
config = IO.read(config_file) config = IO.read(config_file)
default_port, default_ip = 3000, '0.0.0.0' default_port, default_ip = 3000, '0.0.0.0'
port = config.scan(/^server.port\s*=\s*(\d+)/).first rescue default_port port = config.scan(/^\s*server.port\s*=\s*(\d+)/).first rescue default_port
ip = config.scan(/^server.bind\s*=\s*"([^"]+)"/).first rescue default_ip ip = config.scan(/^\s*server.bind\s*=\s*"([^"]+)"/).first rescue default_ip
puts "=> Rails application started on http://#{ip || default_ip}:#{port || default_port}" puts "=> Rails application started on http://#{ip || default_ip}:#{port || default_port}"
tail_thread = nil tail_thread = nil
...@@ -35,11 +37,10 @@ ...@@ -35,11 +37,10 @@
puts "=> Ctrl-C to shutdown server (see config/lighttpd.conf for options)" puts "=> Ctrl-C to shutdown server (see config/lighttpd.conf for options)"
detach = false detach = false
log_path = "#{RAILS_ROOT}/log/#{RAILS_ENV}.log" cursor = File.size(configuration.log_path)
cursor = File.size(log_path)
last_checked = Time.now last_checked = Time.now
tail_thread = Thread.new do tail_thread = Thread.new do
File.open(log_path, 'r') do |f| File.open(configuration.log_path, 'r') do |f|
loop do loop do
f.seek cursor f.seek cursor
if f.mtime > last_checked if f.mtime > last_checked
......
...@@ -38,7 +38,9 @@ class Initializer ...@@ -38,7 +38,9 @@ class Initializer
# incuring the overhead of completely loading the entire environment. # incuring the overhead of completely loading the entire environment.
def self.run(command = :process, configuration = Configuration.new) def self.run(command = :process, configuration = Configuration.new)
yield configuration if block_given? yield configuration if block_given?
new(configuration).send(command) initializer = new configuration
initializer.send(command)
initializer
end end
# Create a new Initializer instance that references the given Configuration # Create a new Initializer instance that references the given Configuration
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册