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.('~/.hooves')
- PROJECT_CONFIG =
File.('./.hooves')
Class Method Summary collapse
- .find_config_file ⇒ Object
- .project_config? ⇒ Boolean
- .run(app, options = {}) ⇒ Object
- .user_config? ⇒ Boolean
Class Method Details
.find_config_file ⇒ Object
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
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, ={}) [:listeners] = ["#{.delete(:Host)}:#{.delete(:Port)}"] [:worker_processes] ||= 3 if .delete(:debugger) $DEBUG = true # It's difficult to debug with more than one worker on the go [:worker_processes] = 1 # The default timeout (30s) doesn't leave much time for debugging [:timeout] = 120 end daemonize = .delete(:daemonize) # override any settings that you want in your config file [:config_file] = find_config_file # :pid option is stronly discouraged except in unicorn config file = Hash[.select { |k, v| [:listeners, :worker_processes, :config_file, :timeout].include?(k) }] if daemonize ::Unicorn::Launcher.daemonize!() else ::Unicorn::HttpServer.new(app, ).start.join end end |
.user_config? ⇒ Boolean
47 48 49 |
# File 'lib/hooves/unicorn.rb', line 47 def user_config? File.exist?(USER_CONFIG) end |