Module: Hooves::Unicorn

Defined in:
lib/hooves/unicorn.rb

Overview

Rack Handler to use Unicorn for Rails::Application.run!

Constant Summary collapse

USER_CONFIG =
File.expand_path('~/.hooves')
PROJECT_CONFIG =
File.expand_path('./.hooves')

Class Method Summary collapse

Class Method Details

.find_config_fileObject



39
40
41
42
43
44
45
# File 'lib/hooves/unicorn.rb', line 39

def find_config_file
  if user_config?
    USER_CONFIG
  elsif project_config?
    PROJECT_CONFIG
  end
end

.project_config?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/hooves/unicorn.rb', line 51

def project_config?
  File.exist?(PROJECT_CONFIG)
end

.run(app, options = {}) ⇒ Object



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
35
# File 'lib/hooves/unicorn.rb', line 9

def run(app, options={})
  options[:listeners] = ["#{options.delete(:Host)}:#{options.delete(:Port)}"]
  options[:worker_processes] ||= 3

  if options.delete(:debugger)
    $DEBUG = true

    # It's difficult to debug with more than one worker on the go
    options[:worker_processes] = 1
    # The default timeout (30s) doesn't leave much time for debugging
    options[:timeout] = 120
  end

  daemonize = options.delete(:daemonize)

  # override any settings that you want in your config file
  options[:config_file] = find_config_file

  # :pid option is stronly discouraged except in unicorn config file
  uni_options = Hash[options.select { |k, v| [:listeners, :worker_processes, :config_file, :timeout].include?(k) }]

  if daemonize
    ::Unicorn::Launcher.daemonize!(uni_options)
  else
    ::Unicorn::HttpServer.new(app, uni_options).start.join
  end
end

.user_config?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/hooves/unicorn.rb', line 47

def user_config?
  File.exist?(USER_CONFIG)
end