2005-01-24 19:52:04 +01:00
|
|
|
#!/usr/bin/ruby
|
|
|
|
|
|
|
|
require 'webrick'
|
|
|
|
require 'optparse'
|
|
|
|
require 'fileutils'
|
|
|
|
|
|
|
|
pwd = File.expand_path(File.dirname(__FILE__) + "/..")
|
|
|
|
|
|
|
|
OPTIONS = {
|
|
|
|
|
|
|
|
# Overridable options
|
|
|
|
:port => 2500,
|
|
|
|
:ip => '127.0.0.1',
|
|
|
|
:environment => 'production',
|
|
|
|
:server_root => File.expand_path(File.dirname(__FILE__) + '/../public/'),
|
|
|
|
:server_type => WEBrick::SimpleServer,
|
|
|
|
:storage => "#{File.expand_path(FileUtils.pwd)}/storage",
|
|
|
|
}
|
|
|
|
|
|
|
|
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.',
|
|
|
|
'Default: 2500') { |OPTIONS[:port]| }
|
|
|
|
opts.on('-b', '--binding=ip', String,
|
|
|
|
'Binds Rails to the specified ip.',
|
2005-03-25 20:11:41 +01:00
|
|
|
'Default: 0.0.0.0') { |OPTIONS[:ip]| }
|
2005-01-24 19:52:04 +01:00
|
|
|
opts.on('-e', '--environment=name', String,
|
|
|
|
'Specifies the environment to run this server under (test/development/production).',
|
|
|
|
'Default: production') { |OPTIONS[:environment]| }
|
|
|
|
opts.on('-d', '--daemon',
|
2005-01-25 23:06:34 +01:00
|
|
|
'Make Instiki run as a Daemon (only works if fork is available -- meaning on *nix).'
|
2005-01-24 19:52:04 +01:00
|
|
|
) { OPTIONS[:server_type] = WEBrick::Daemon }
|
|
|
|
opts.on('-s', '--simple', '--simple-server',
|
|
|
|
'[deprecated] Forces Instiki not to run as a Daemon if fork is available.',
|
|
|
|
'Since version 0.10.0 this option is ignored.'
|
|
|
|
) { puts "Warning: -s (--simple) option is deprecated. See instiki --help for details." }
|
|
|
|
opts.on('-t', '--storage=storage', String,
|
|
|
|
'Makes Instiki use the specified directory for storage.',
|
|
|
|
'Default: ./storage/[port]') { |OPTIONS[:storage]| }
|
|
|
|
opts.on('-v', '--verbose',
|
2005-03-25 20:11:41 +01:00
|
|
|
'Enables debug-level logging'
|
2005-01-24 19:52:04 +01:00
|
|
|
) { OPTIONS[:verbose] = true }
|
|
|
|
|
|
|
|
opts.separator ''
|
|
|
|
|
|
|
|
opts.on('-h', '--help',
|
|
|
|
'Show this help message.') { puts opts; exit }
|
|
|
|
|
|
|
|
opts.parse!
|
|
|
|
end
|
|
|
|
|
|
|
|
if OPTIONS[:environment] == 'production'
|
2005-01-25 23:06:34 +01:00
|
|
|
storage_path = "#{OPTIONS[:storage]}/#{OPTIONS[:port]}"
|
|
|
|
else
|
|
|
|
storage_path = "#{OPTIONS[:storage]}/#{OPTIONS[:environment]}/#{OPTIONS[:port]}"
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
|
|
|
FileUtils.mkdir_p(storage_path)
|
|
|
|
|
2005-01-25 23:06:34 +01:00
|
|
|
ENV['RAILS_ENV'] = OPTIONS[:environment]
|
|
|
|
INSTIKI_DEBUG_LOG = OPTIONS[:verbose]
|
|
|
|
require File.expand_path(File.dirname(__FILE__) + '/../config/environment')
|
2005-01-24 19:52:04 +01:00
|
|
|
WikiService.storage_path = storage_path
|
2005-01-25 23:06:34 +01:00
|
|
|
|
2005-01-26 02:02:39 +01:00
|
|
|
if defined? INSTIKI_BATCH_JOB
|
|
|
|
require 'application'
|
|
|
|
else
|
2005-01-25 23:06:34 +01:00
|
|
|
puts "=> Starting Instiki on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}"
|
|
|
|
puts "=> Data files are stored in #{storage_path}"
|
|
|
|
|
|
|
|
require 'webrick_server'
|
2005-03-25 20:23:26 +01:00
|
|
|
require_dependency 'application'
|
2005-01-26 02:02:39 +01:00
|
|
|
|
|
|
|
OPTIONS[:index_controller] = 'wiki'
|
2005-01-25 23:06:34 +01:00
|
|
|
ApplicationController.wiki = WikiService.instance
|
|
|
|
DispatchServlet.dispatch(OPTIONS)
|
|
|
|
end
|