#!/usr/bin/ruby require 'webrick' require 'optparse' require 'fileutils' pwd = File.expand_path(File.dirname(__FILE__) + "/..") OPTIONS = { # Overridable options :port => 2500, :ip => '0.0.0.0', :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: 0.0.0.0') { |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('-x', '--notex', 'Blocks wiki exports to TeX and PDF, even when pdflatex is available.' ) { |OPTIONS[:notex]| } opts.on('-v', '--verbose', 'Enables 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 OPTIONS[:notex] OPTIONS[:pdflatex] = false else begin OPTIONS[:pdflatex] = system "pdflatex -version" rescue Errno::ENOENT OPTIONS[:pdflatex] = false end end 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_dependency 'application' OPTIONS[:index_controller] = 'wiki' ApplicationController.wiki = WikiService.instance DispatchServlet.dispatch(OPTIONS) end