2006-01-12 18:57:44 -05:00
|
|
|
require 'rbconfig'
|
|
|
|
|
2005-11-07 05:42:52 -05:00
|
|
|
unless RUBY_PLATFORM !~ /mswin/ && !silence_stderr { `lighttpd -version` }.blank?
|
2005-11-07 08:31:19 -05:00
|
|
|
puts "PROBLEM: Lighttpd is not available on your system (or not in your path)"
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
|
|
|
unless defined?(FCGI)
|
|
|
|
puts "PROBLEM: Lighttpd requires that the FCGI Ruby bindings are installed on the system"
|
2005-11-07 05:42:52 -05:00
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
2005-11-30 14:18:55 -05:00
|
|
|
require 'initializer'
|
|
|
|
configuration = Rails::Initializer.run(:initialize_logger).configuration
|
2005-11-07 05:42:52 -05:00
|
|
|
|
|
|
|
config_file = "#{RAILS_ROOT}/config/lighttpd.conf"
|
|
|
|
|
2005-11-07 12:45:53 -05:00
|
|
|
unless File.exist?(config_file)
|
|
|
|
require 'fileutils'
|
|
|
|
source = File.expand_path(File.join(File.dirname(__FILE__),
|
|
|
|
"..", "..", "..", "configs", "lighttpd.conf"))
|
|
|
|
puts "=> #{config_file} not found, copying from #{source}"
|
|
|
|
FileUtils.cp source, config_file
|
|
|
|
end
|
|
|
|
|
2005-11-21 01:19:25 -05:00
|
|
|
config = IO.read(config_file)
|
|
|
|
default_port, default_ip = 3000, '0.0.0.0'
|
2005-11-30 14:18:55 -05:00
|
|
|
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
|
2005-11-21 01:19:25 -05:00
|
|
|
puts "=> Rails application started on http://#{ip || default_ip}:#{port || default_port}"
|
2005-11-07 05:42:52 -05:00
|
|
|
|
2005-11-09 17:57:05 -05:00
|
|
|
tail_thread = nil
|
|
|
|
|
2005-11-07 05:42:52 -05:00
|
|
|
if ARGV.first == "-d"
|
2006-02-12 12:41:53 -05:00
|
|
|
puts "=> Configuration in config/lighttpd.conf"
|
2005-11-07 05:42:52 -05:00
|
|
|
detach = true
|
|
|
|
else
|
2006-02-12 12:41:53 -05:00
|
|
|
puts "=> Call with -d to detach"
|
2005-11-07 05:42:52 -05:00
|
|
|
puts "=> Ctrl-C to shutdown server (see config/lighttpd.conf for options)"
|
|
|
|
detach = false
|
|
|
|
|
2005-11-30 14:18:55 -05:00
|
|
|
cursor = File.size(configuration.log_path)
|
2005-11-09 17:57:05 -05:00
|
|
|
last_checked = Time.now
|
|
|
|
tail_thread = Thread.new do
|
2005-11-30 14:18:55 -05:00
|
|
|
File.open(configuration.log_path, 'r') do |f|
|
2005-11-09 17:57:05 -05:00
|
|
|
loop do
|
|
|
|
f.seek cursor
|
|
|
|
if f.mtime > last_checked
|
|
|
|
last_checked = f.mtime
|
|
|
|
contents = f.read
|
|
|
|
cursor += contents.length
|
|
|
|
print contents
|
|
|
|
end
|
|
|
|
sleep 1
|
2005-11-07 05:42:52 -05:00
|
|
|
end
|
|
|
|
end
|
2005-11-09 17:57:05 -05:00
|
|
|
end
|
2005-11-07 05:42:52 -05:00
|
|
|
end
|
|
|
|
|
2005-11-09 17:15:01 -05:00
|
|
|
trap(:INT) { exit }
|
2006-01-12 18:57:44 -05:00
|
|
|
|
|
|
|
begin
|
|
|
|
`lighttpd #{!detach ? "-D " : ""}-f #{config_file}`
|
|
|
|
ensure
|
2006-02-12 12:41:53 -05:00
|
|
|
unless detach
|
|
|
|
tail_thread.kill if tail_thread
|
|
|
|
puts 'Exiting'
|
2006-01-12 18:57:44 -05:00
|
|
|
|
2006-02-12 12:41:53 -05:00
|
|
|
# Ensure FCGI processes are reaped
|
2006-02-22 17:43:43 -05:00
|
|
|
ARGV.replace ['-a', 'kill']
|
|
|
|
require 'commands/process/reaper'
|
2006-02-12 12:41:53 -05:00
|
|
|
end
|
2006-01-12 18:57:44 -05:00
|
|
|
end
|