Class: OMF::Web::Runner

Inherits:
Thin::Runner
  • Object
show all
Includes:
Common::Loggable
Defined in:
lib/omf-web/thin/runner.rb

Constant Summary collapse

@@instance =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common::Loggable

#_logger, #debug, #error, #fatal, #info, init_log, logger, set_environment, #warn

Constructor Details

#initialize(argv, opts = {}) ⇒ Runner

Returns a new instance of Runner.



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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/omf-web/thin/runner.rb', line 28

def initialize(argv, opts = {})
  raise "SINGLETON" if @@instance
  
  @argv = argv
  sopts = opts.delete(:ssl) # runner has it's own idea of ssl options
  
  # Default options values
  app_name = opts[:app_name] || 'omf_web_app'
  @options = {
    :app_name             => app_name,
    :chdir                => Dir.pwd,
    :environment          => 'development',
    :address              => '0.0.0.0',
    :port                 => Thin::Server::DEFAULT_PORT,
    :timeout              => Thin::Server::DEFAULT_TIMEOUT,
    :log                  => "/tmp/#{app_name}_thin.log",
    :pid                  => "/tmp/#{app_name}.pid",
    :max_conns            => Thin::Server::DEFAULT_MAXIMUM_CONNECTIONS,
    :max_persistent_conns => Thin::Server::DEFAULT_MAXIMUM_PERSISTENT_CONNECTIONS,
    :require              => [],
    :wait                 => Thin::Controllers::Cluster::DEFAULT_WAIT_TIME,
 
    :rackup               => File.dirname(__FILE__) + '/../config.ru',
    :static_dirs          => ["#{File.dirname(__FILE__)}/../../../share/htdocs"],
    :static_dirs_pre      => ["./resources"],  # directories to prepend to 'static_dirs'
    
    :handlers             => {}  # procs to call at various times of the server's life cycle
  }.merge(opts)
  # Search path for resource files is concatination of 'pre' and 'standard' static dirs
  @options[:static_dirs] = @options[:static_dirs_pre].concat(@options[:static_dirs])
    
 
 
  print_options = false
  p = parser
  p.separator ""
  p.separator "OMF options:"
  p.on("--theme THEME", "Select web theme") do |t| OMF::Web::Theme.theme = t end                
  
  p.separator ""
  p.separator "Testing options:"
  p.on("--disable-https", "Run server without SSL") do sopts = nil end                
  p.on("--print-options", "Print option settings after parsing command lines args") do print_options = true end                      
  
  # Allow application to add it's own parsing options
  if ph = @options[:handlers][:pre_parse]
    ph.call(p)
  end

  parse!
  # WHY IS THIS HERE
  # unless life_cycle(:post_parse)
    # puts p.to_s
    # abort()
  # end
  if sopts
    @options[:ssl] = true
    @options[:ssl_key_file] ||= sopts[:key_file]
    @options[:ssl_cert_file] ||= sopts[:cert_file]
    @options[:ssl_verify] ||= sopts[:verify_peer]
  end

  # Change the name of the root logger so we can apply different logging
  # policies depending on environment. 
  #
  OMF::Common::Loggable.set_environment @options[:environment]

  if print_options
    require 'pp'
    pp @options
  end            
  
  @@instance = self
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



26
27
28
# File 'lib/omf-web/thin/runner.rb', line 26

def options
  @options
end

Class Method Details

.instanceObject



22
23
24
# File 'lib/omf-web/thin/runner.rb', line 22

def self.instance
  @@instance
end

Instance Method Details

#life_cycle(step, &exception_block) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/omf-web/thin/runner.rb', line 103

def life_cycle(step, &exception_block)
  begin
    if (p = @options[:handlers][step])
      p.call()
    end
  rescue => ex
    if exception_block
      begin 
        exception_block.call(ex)
      rescue => ex2
        error ex2
        debug "#{ex2.backtrace.join("\n")}"
      end
    else
      error ex
      debug "#{ex.backtrace.join("\n")}"
    end
  end
end

#run!Object



123
124
125
126
127
128
129
# File 'lib/omf-web/thin/runner.rb', line 123

def run!
  if theme = @options[:theme]
    require 'omf-web/theme'
    OMF::Web::Theme.theme = theme
  end
  super
end