2 require 'commands/servers/base'
4 unless RUBY_PLATFORM !~
/mswin/ && !silence_stderr
{ `lighttpd -version` }.blank
?
5 puts
"PROBLEM: Lighttpd is not available on your system (or not in your path)"
10 puts
"PROBLEM: Lighttpd requires that the FCGI Ruby bindings are installed on the system"
15 configuration
= Rails
::Initializer.run(:initialize_logger).configuration
16 default_config_file
= config_file
= Pathname
.new("#{RAILS_ROOT}/config/lighttpd.conf").cleanpath
21 command_line_port
= nil
24 opt
.on("-p", "--port=port", "Changes the server.port number in the config/lighttpd.conf") { |port
| command_line_port
= port
}
25 opt
.on('-c', "--config=#{config_file}", 'Specify a different lighttpd config file.') { |path
| config_file
= path
}
26 opt
.on('-h', '--help', 'Show this message.') { puts opt
; exit
0 }
27 opt
.on('-d', '-d', 'Call with -d to detach') { detach
= true; puts
"=> Configuration in config/lighttpd.conf" }
31 unless File
.exist
?(config_file
)
32 if config_file
!= default_config_file
33 puts
"=> #{config_file} not found."
39 source
= File
.expand_path(File
.join(File
.dirname(__FILE__
),
40 "..", "..", "..", "configs", "lighttpd.conf"))
41 puts
"=> #{config_file} not found, copying from #{source}"
43 FileUtils
.cp(source
, config_file
)
46 # open the config/lighttpd.conf file and add the current user defined port setting to it
48 File
.open(config_file
, 'r+') do |config
|
49 lines
= config
.readlines
52 line
.gsub
!(/^\s*server.port\s*=\s*(\d+)/, "server.port = #{command_line_port}")
57 config
.truncate(config
.pos
)
61 config
= IO
.read(config_file
)
62 default_port
, default_ip
= 3000, '0.0.0.0'
63 port
= config
.scan(/^\s*server.port\s*=\s*(\d+)/).first
rescue default_port
64 ip
= config
.scan(/^\s*server.bind\s*=\s*"([^"]+)"/).first
rescue default_ip
65 puts
"=> Rails #{Rails.version} application starting on http://#{ip || default_ip}:#{port || default_port}"
70 puts
"=> Call with -d to detach"
71 puts
"=> Ctrl-C to shutdown server (see config/lighttpd.conf for options)"
73 tail_thread
= tail(configuration
.log_path
)
79 `rake tmp:sockets:clear` # Needed if lighttpd crashes or otherwise leaves FCGI sockets around
80 `lighttpd #{!detach ? "-D " : ""}-f #{config_file}`
83 tail_thread
.kill
if tail_thread
86 # Ensure FCGI processes are reaped
87 silence_stream(STDOUT) do
88 ARGV.replace
['-a', 'kill']
89 require 'commands/process/reaper'
92 `rake tmp:sockets:clear` # Remove sockets on clean shutdown