Class: Wiki2Go::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/Wiki2Go/Server.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Server

Returns a new instance of Server.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/Wiki2Go/Server.rb', line 42

def initialize(args) 
  puts "Args = #{args.inspect}"
  opts = OptionParser.new      
  dir = Dir.pwd
  port = 8081
  wiki = 'Wiki2Go'
  single = false
  allow_dynamic = false
  modulename = ''
  cvsroot = ''
  blogstyle = false

  opts.on("-d",'--dir <directory>','(default is current directory)',String) { |val| dir = File.expand_path(val) }
  opts.on("-p",'--port <nb>',"(default is port 8081)",String) { |val| port = val }
  opts.on("-w",'--wiki <wikiname>',"(default is 'Wiki2Go')",String) { |val| wiki = val }
  opts.on("-s","--single","Single or multi-wiki (default)") { |val| single = true }
  opts.on('-r','--rublets','Allow dynamic pages') { |val| allow_dynamic = true }
  opts.on('-m','--module name','CVS module') { |val| modulename = val }
  opts.on('-c','--cvsroot root','CVS root') { |val| cvsroot = val }
  opts.on('-b','--blogstyle','RSS contains creation date') { |val| blogstyle = true }
  opts.on_tail("-h", "--help", "Show this message") do
    puts opts
    exit
  end
  opts.parse(args)

  # TODO : read CgiOptions.rb (if present) and reuse what's available

  @config = LocalConfig.new(dir)
  @config.port = port
  @config.default_web = wiki
  @config.generate_html = false
  @config.multi_wiki = !single
  @config.allow_dynamic_pages = allow_dynamic
  @config.blog_style = blogstyle
  if !cvsroot.empty? && !modulename.empty? then
    @config.use_repository(cvsroot,modulename)
  end
end

Instance Method Details

#startObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/Wiki2Go/Server.rb', line 82

def start
  begin

    yield @config if block_given?

    web_thread = Thread.new(@config) do |config|
      s = WEBrick::HTTPServer.new( :Port => config.port)

      s.mount("/scripts/", WikiServlet,config)
      s.mount("/scripts/secure/", WikiServlet,config)
      s.mount("/", WikiServlet,config)

      trap("INT"){ s.shutdown }
      s.start
    end
    web_thread
  rescue
    puts "Error during startup: #{$!}"
    puts $@
  end
end

#stopObject



104
105
106
107
108
109
# File 'lib/Wiki2Go/Server.rb', line 104

def stop
  Net::HTTP.start( @config.server, @config.port) { |http|
    response = http.get('/stop/' + @config.default_web + '/')
    page = response.body
  }
end