Class: Rack::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/codestock/cdweb/cli_cdweb.rb

Instance Method Summary collapse

Instance Method Details

#startObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/codestock/cdweb/cli_cdweb.rb', line 10

def start
  if options[:warn]
    $-w = true
  end

  if includes = options[:include]
    $LOAD_PATH.unshift(*includes)
  end

  if library = options[:require]
    require library
  end

  if options[:debug]
    $DEBUG = true
    require 'pp'
    p options[:server]
    pp wrapped_app
    pp app
  end

  # Touch the wrapped app, so that the config.ru is loaded before
  # daemonization (i.e. before chdir, etc).
  wrapped_app

  daemonize_app if options[:daemonize]
  write_pid if options[:pid]

  trap(:INT) do
    if server.respond_to?(:shutdown)
      server.shutdown
    else
      exit
    end
  end

  server.run wrapped_app, options do
    if (options[:LaunchBrowser])
      host = options[:Host] || options[:BindAddress] # options[:BindAddress] for WEBrick
      Launchy.open("http://#{host}:#{options[:Port]}")
    end
  end
end