2006-01-12 18:57:44 -05:00
|
|
|
require 'rbconfig'
|
2006-06-28 20:31:45 -04:00
|
|
|
require 'commands/servers/base'
|
2006-01-12 18:57:44 -05:00
|
|
|
|
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
|
|
|
|
|
2006-12-01 18:02:48 -05:00
|
|
|
require 'initializer'
|
|
|
|
configuration = Rails::Initializer.run(:initialize_logger).configuration
|
|
|
|
default_config_file = config_file = Pathname.new("#{RAILS_ROOT}/config/lighttpd.conf").cleanpath
|
|
|
|
|
2006-02-23 16:47:34 -05:00
|
|
|
require 'optparse'
|
2006-03-18 12:00:40 -05:00
|
|
|
|
|
|
|
detach = false
|
2006-08-06 17:34:28 -04:00
|
|
|
command_line_port = nil
|
2006-03-18 12:00:40 -05:00
|
|
|
|
2006-02-23 16:47:34 -05:00
|
|
|
ARGV.options do |opt|
|
2006-08-05 18:11:24 -04:00
|
|
|
opt.on("-p", "--port=port", "Changes the server.port number in the config/lighttpd.conf") { |port| command_line_port = port }
|
2006-02-23 16:47:34 -05:00
|
|
|
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 }
|
2006-03-18 12:00:40 -05:00
|
|
|
opt.on('-d', '-d', 'Call with -d to detach') { detach = true; puts "=> Configuration in config/lighttpd.conf" }
|
2006-02-23 16:47:34 -05:00
|
|
|
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
|
2006-03-20 01:17:55 -05:00
|
|
|
|
2005-11-07 12:45:53 -05:00
|
|
|
require 'fileutils'
|
2006-03-20 01:17:55 -05:00
|
|
|
|
2005-11-07 12:45:53 -05:00
|
|
|
source = File.expand_path(File.join(File.dirname(__FILE__),
|
|
|
|
"..", "..", "..", "configs", "lighttpd.conf"))
|
|
|
|
puts "=> #{config_file} not found, copying from #{source}"
|
2006-03-20 01:17:55 -05:00
|
|
|
|
|
|
|
FileUtils.cp(source, config_file)
|
2005-11-07 12:45:53 -05:00
|
|
|
end
|
|
|
|
|
2006-08-05 18:11:24 -04:00
|
|
|
# open the config/lighttpd.conf file and add the current user defined port setting to it
|
|
|
|
if command_line_port
|
|
|
|
File.open(config_file, 'r+') do |config|
|
|
|
|
lines = config.readlines
|
|
|
|
|
|
|
|
lines.each do |line|
|
|
|
|
line.gsub!(/^\s*server.port\s*=\s*(\d+)/, "server.port = #{command_line_port}")
|
|
|
|
end
|
|
|
|
|
|
|
|
config.rewind
|
|
|
|
config.print(lines)
|
|
|
|
config.truncate(config.pos)
|
|
|
|
end
|
|
|
|
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
|
2006-11-19 16:54:48 -05:00
|
|
|
puts "=> Rails application starting 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
|
|
|
|
|
2006-03-18 12:00:40 -05:00
|
|
|
if !detach
|
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
|
2006-06-28 20:31:45 -04:00
|
|
|
tail_thread = tail(configuration.log_path)
|
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
|
2006-03-04 14:39:26 -05:00
|
|
|
`rake tmp:sockets:clear` # Needed if lighttpd crashes or otherwise leaves FCGI sockets around
|
2006-01-12 18:57:44 -05:00
|
|
|
`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-03-04 14:39:26 -05:00
|
|
|
silence_stream(STDOUT) do
|
|
|
|
ARGV.replace ['-a', 'kill']
|
|
|
|
require 'commands/process/reaper'
|
|
|
|
end
|
|
|
|
|
|
|
|
`rake tmp:sockets:clear` # Remove sockets on clean shutdown
|
2006-02-12 12:41:53 -05:00
|
|
|
end
|
2006-01-12 18:57:44 -05:00
|
|
|
end
|