instiki/script/server
Alexey Verkhovsky 3e4154de82 fixed a problem where Instiki wouldn't start because
require 'application' was before require 'webrick_server' (?)
2005-01-26 01:02:39 +00:00

82 lines
2.7 KiB
Ruby
Executable file

#!/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.',
'Default: 127.0.0.1') { |OPTIONS[:ip]| }
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',
'Make Instiki run as a Daemon (only works if fork is available -- meaning on *nix).'
) { 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',
'Enable debug-level logging'
) { OPTIONS[:verbose] = true }
opts.separator ''
opts.on('-h', '--help',
'Show this help message.') { puts opts; exit }
opts.parse!
end
if OPTIONS[:environment] == 'production'
storage_path = "#{OPTIONS[:storage]}/#{OPTIONS[:port]}"
else
storage_path = "#{OPTIONS[:storage]}/#{OPTIONS[:environment]}/#{OPTIONS[:port]}"
end
FileUtils.mkdir_p(storage_path)
ENV['RAILS_ENV'] = OPTIONS[:environment]
INSTIKI_DEBUG_LOG = OPTIONS[:verbose]
require File.expand_path(File.dirname(__FILE__) + '/../config/environment')
WikiService.storage_path = storage_path
if defined? INSTIKI_BATCH_JOB
require 'application'
else
puts "=> Starting Instiki on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}"
puts "=> Data files are stored in #{storage_path}"
require 'webrick_server'
require 'application'
OPTIONS[:index_controller] = 'wiki'
ApplicationController.wiki = WikiService.instance
DispatchServlet.dispatch(OPTIONS)
end