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
|
2006-02-23 16:47:34 -05:00
|
|
|
default_config_file = config_file = "#{RAILS_ROOT}/config/lighttpd.conf"
|
2005-11-07 05:42:52 -05:00
|
|
|
|
2006-02-23 16:47:34 -05:00
|
|
|
require 'optparse'
|
|
|
|
ARGV.options do |opt|
|
|
|
|
opt.on('-c', "--config=#{config_file}", 'Specify a different lighttpd config file.') { |path| config_file = path }
|
|
|
|
opt.on('-h', '--help', 'Show this message.') { puts opt; exit 0 }
|
|
|
|
opt.parse!
|
|
|
|
end
|
2005-11-07 05:42:52 -05:00
|
|
|
|
2005-11-07 12:45:53 -05:00
|
|
|
unless File.exist?(config_file)
|
2006-02-23 16:47:34 -05:00
|
|
|
if config_file != default_config_file
|
|
|
|
puts "=> #{config_file} not found."
|
|
|
|
exit 1
|
|
|
|
end
|
2005-11-07 12:45:53 -05:00
|
|
|
require 'fileutils'
|
|
|
|
source = File.expand_path(File.join(File.dirname(__FILE__),
|
|
|
|
"..", "..", "..", "configs", "lighttpd.conf"))
|
|
|
|
puts "=> #{config_file} not found, copying from #{source}"
|
2006-02-26 12:49:09 -05:00
|
|
|
config = File.read source
|
|
|
|
config = config.gsub "CWD", File.expand_path(RAILS_ROOT).inspect
|
|
|
|
File.open(config_file, 'w') { |f| f.write config }
|
2005-11-07 12:45:53 -05:00
|
|
|
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
|