Sha256: b1381cb7a2e7fb2c25e4d376f4f0dda4b9175a1d3f18cd7a28cc2cffdf27f13a

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

require "unicorn"
require "unicorn/launcher"

module UnicornRails
  require "unicorn_rails/version"
end

module Rack
  module Handler
    class Unicorn
      class << self
        def run(app, options = {})
          unicorn_options = {}

          if ::File.exist?("config/unicorn/#{environment}.rb")
            unicorn_options[:config_file] = "config/unicorn/#{environment}.rb"
          elsif ::File.exist?("config/unicorn.rb")
            unicorn_options[:config_file] = "config/unicorn.rb"
          else
            unicorn_options[:listeners] = ["#{options[:Host]}:#{options[:Port]}"]
            unicorn_options[:timeout] = 31 * 24 * 60 * 60
            unicorn_options[:worker_processes] = (ENV["UNICORN_WORKERS"] || "1").to_i
          end

          ::Unicorn::Launcher.daemonize!(unicorn_options) if options[:daemonize]
          ::Unicorn::HttpServer.new(app, unicorn_options).start.join
        end

        def environment
          ENV["RACK_ENV"] || ENV["RAILS_ENV"]
        end
      end
    end

    register "unicorn", "Rack::Handler::Unicorn"

    def self.default(options = {})
      Rack::Handler::Unicorn
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unicorn-rails-2.1.1 lib/unicorn_rails.rb