2007-01-22 14:43:50 +01:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
|
|
|
require 'webrick'
|
|
|
|
require 'optparse'
|
|
|
|
|
|
|
|
OPTIONS = {
|
|
|
|
:port => 2500,
|
|
|
|
:ip => "0.0.0.0",
|
|
|
|
:environment => "production",
|
|
|
|
:server_root => File.expand_path(File.dirname(__FILE__) + "/../public/"),
|
2007-05-30 05:39:35 +02:00
|
|
|
:server_type => WEBrick::SimpleServer,
|
|
|
|
:mime_types => WEBrick::HTTPUtils::DefaultMimeTypes.merge({
|
2007-05-30 06:02:19 +02:00
|
|
|
'avi' => 'video/x-msvideo',
|
|
|
|
'gz' => 'application/x-gzip',
|
|
|
|
'js' => 'application/x-javascript',
|
|
|
|
'nb' => 'application/mathematica',
|
|
|
|
'pdf' => 'application/pdf',
|
|
|
|
'svg' => 'application/svg+xml',
|
|
|
|
'tar' => 'application/x-tar',
|
|
|
|
'tex' => 'application/x-tex',
|
2007-09-15 07:29:20 +02:00
|
|
|
'xhtml' => 'application/xhtml+xml',
|
2007-05-30 06:02:19 +02:00
|
|
|
'xml' => 'application/xml',
|
|
|
|
'xslt' => 'application/xslt+xml'
|
|
|
|
})
|
2007-01-22 14:43:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ARGV.options do |opts|
|
|
|
|
script_name = File.basename($0)
|
|
|
|
opts.banner = "Usage: ruby #{script_name} [options]"
|
|
|
|
|
|
|
|
opts.separator ""
|
|
|
|
|
|
|
|
opts.on("-p", "--port=port", Integer,
|
|
|
|
"Runs Instiki on the specified port.",
|
2008-11-12 16:47:24 +01:00
|
|
|
"Default: 2500") { }
|
|
|
|
# "Default: 2500") { |OPTIONS[:port]| }
|
2007-01-22 14:43:50 +01:00
|
|
|
opts.on("-b", "--binding=ip", String,
|
|
|
|
"Binds Instiki to the specified ip.",
|
2008-11-12 16:47:24 +01:00
|
|
|
"Default: 0.0.0.0") { }
|
|
|
|
# "Default: 0.0.0.0") { |OPTIONS[:ip]| }
|
2007-01-22 14:43:50 +01:00
|
|
|
opts.on("-e", "--environment=name", String,
|
|
|
|
"Specifies the environment to run this server under (test/development/production).",
|
2008-11-12 16:47:24 +01:00
|
|
|
"Default: development") { }
|
|
|
|
# "Default: development") { |OPTIONS[:environment]| }
|
2007-01-22 14:43:50 +01:00
|
|
|
opts.on("-d", "--daemon",
|
|
|
|
"Make Instiki run as a Daemon (only works if fork is available -- meaning on *nix)."
|
|
|
|
) { OPTIONS[:server_type] = WEBrick::Daemon }
|
|
|
|
|
|
|
|
opts.separator ""
|
|
|
|
|
|
|
|
opts.on("-h", "--help",
|
|
|
|
"Show this help message.") { puts opts; exit }
|
|
|
|
|
|
|
|
opts.parse!
|
|
|
|
end
|
|
|
|
|
|
|
|
ENV["RAILS_ENV"] = OPTIONS[:environment]
|
|
|
|
require File.dirname(__FILE__) + "/../config/environment"
|
|
|
|
require 'webrick_server'
|
|
|
|
|
|
|
|
OPTIONS['working_directory'] = File.expand_path(RAILS_ROOT)
|
|
|
|
|
|
|
|
puts "=> Instiki started on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}"
|
|
|
|
puts "=> Ctrl-C to shutdown; call with --help for options" if OPTIONS[:server_type] == WEBrick::SimpleServer
|
|
|
|
DispatchServlet.dispatch(OPTIONS)
|