Class: EmmyExtends::Thin::Controller

Inherits:
Thin::Controllers::Controller
  • Object
show all
Defined in:
lib/emmy_extends/thin/controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, app, opts = {}) ⇒ Controller

Returns a new instance of Controller.



9
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
# File 'lib/emmy_extends/thin/controller.rb', line 9

def initialize(config, app, opts={})
  @app = app
  @config = config.is_a?(Hash) ? EmmyHttp::Configuration.new(config) : config
  options = {
    environment:    config.environment,
    address:        config.url.host,
    port:           config.url.port,
    pid:            config.pid,
    user:           config.user,
    group:          config.group,
    log:            config.log || File.join(Dir.pwd, "log/#{config.backend}.log")
  }

  if config.ssl
    options.merge!(
      ssl: true,
      ssl_key_file:       config.ssl.private_key_file,
      ssl_cert_file:      config.ssl.cert_chain_file,
      ssl_disable_verify: !config.ssl.verify_peer,
      ssl_version:        config.ssl.ssl_version
    )
  end

  super(option_defaults.merge(options.merge(opts)))
  setup
end

Instance Attribute Details

#appObject

Returns the value of attribute app.



4
5
6
# File 'lib/emmy_extends/thin/controller.rb', line 4

def app
  @app
end

#backendObject

Returns the value of attribute backend.



7
8
9
# File 'lib/emmy_extends/thin/controller.rb', line 7

def backend
  @backend
end

#configObject

Returns the value of attribute config.



5
6
7
# File 'lib/emmy_extends/thin/controller.rb', line 5

def config
  @config
end

#serverObject

Returns the value of attribute server.



6
7
8
# File 'lib/emmy_extends/thin/controller.rb', line 6

def server
  @server
end

Instance Method Details

#setupObject



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
# File 'lib/emmy_extends/thin/controller.rb', line 39

def setup
  if @options[:socket]
    @server = ::Thin::Server.new(@options[:socket], @options)
  else
    @server = ::Thin::Server.new(config.url.host, config.url.port, @options)
  end
  server.backend.url = config.url

  # Set options
  server.pid_file                       = @options[:pid]
  server.log_file                       = @options[:log]
  server.timeout                        = @options[:timeout]
  server.maximum_connections            = @options[:max_conns]
  server.maximum_persistent_connections = @options[:max_persistent_conns]
  server.threaded                       = @options[:threaded]
  server.no_epoll                       = @options[:no_epoll] if server.backend.respond_to?(:no_epoll=)
  server.threadpool_size                = @options[:threadpool_size] if server.threaded?

  # ssl support
  if @options[:ssl]
    server.ssl = true
    server.ssl_options = {
      private_key_file: @options[:ssl_key_file],
      cert_chain_file: @options[:ssl_cert_file],
      verify_peer: !@options[:ssl_disable_verify],
      ssl_version: @options[:ssl_version]
    }
  end

  # Detach the process, after this line the current process returns
  server.daemonize if @options[:daemonize]

  # +config+ must be called before changing privileges since it might require superuser power.
  server.config

  server.change_privilege @options[:user], @options[:group] if @options[:user] && @options[:group]

  server.app = app

  #server.on_restart { Thin::Command.run(:start, @options) }

  # just return thin-backend
  @backend = server.backend
end

#startObject



36
37
# File 'lib/emmy_extends/thin/controller.rb', line 36

def start
end

#to_aObject



84
85
86
# File 'lib/emmy_extends/thin/controller.rb', line 84

def to_a
  @backend.to_a
end