Skip to content

Commit

Permalink
Run initialize_logger in script/lighttpd to ensure the log file exist…
Browse files Browse the repository at this point in the history
…s before tailing it

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3198 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
sstephenson committed Nov 30, 2005
1 parent 191dfe8 commit 833d9c8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 2 additions & 0 deletions railties/CHANGELOG
@@ -1,5 +1,7 @@
*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]

* Fix freeze_gems so that the latest rails version is dumped by default. [Nicholas Seckar]
Expand Down
11 changes: 6 additions & 5 deletions railties/lib/commands/servers/lighttpd.rb
Expand Up @@ -8,6 +8,8 @@
exit 1
end

require 'initializer'
configuration = Rails::Initializer.run(:initialize_logger).configuration

config_file = "#{RAILS_ROOT}/config/lighttpd.conf"

Expand All @@ -21,8 +23,8 @@

config = IO.read(config_file)
default_port, default_ip = 3000, '0.0.0.0'
port = config.scan(/^server.port\s*=\s*(\d+)/).first rescue default_port
ip = config.scan(/^server.bind\s*=\s*"([^"]+)"/).first rescue default_ip
port = config.scan(/^\s*server.port\s*=\s*(\d+)/).first rescue default_port
ip = config.scan(/^\s*server.bind\s*=\s*"([^"]+)"/).first rescue default_ip
puts "=> Rails application started on http://#{ip || default_ip}:#{port || default_port}"

tail_thread = nil
Expand All @@ -35,11 +37,10 @@
puts "=> Ctrl-C to shutdown server (see config/lighttpd.conf for options)"
detach = false

log_path = "#{RAILS_ROOT}/log/#{RAILS_ENV}.log"
cursor = File.size(log_path)
cursor = File.size(configuration.log_path)
last_checked = Time.now
tail_thread = Thread.new do
File.open(log_path, 'r') do |f|
File.open(configuration.log_path, 'r') do |f|
loop do
f.seek cursor
if f.mtime > last_checked
Expand Down
4 changes: 3 additions & 1 deletion railties/lib/initializer.rb
Expand Up @@ -38,7 +38,9 @@ class Initializer
# incuring the overhead of completely loading the entire environment.
def self.run(command = :process, configuration = Configuration.new)
yield configuration if block_given?
new(configuration).send(command)
initializer = new configuration
initializer.send(command)
initializer
end

# Create a new Initializer instance that references the given Configuration
Expand Down

0 comments on commit 833d9c8

Please sign in to comment.