Sha256: e3084fcdf9c69a0d9e34e8c5d13837dee280aa276e1474d86c506b9cc69c07be

Contents?: true

Size: 1.79 KB

Versions: 3

Compression:

Stored size: 1.79 KB

Contents

working_directory "<%= fetch(:current_path) %>"
pid "<%= fetch(:unicorn_pid) %>"
stderr_path "<%= fetch(:unicorn_log) %>"
stdout_path "<%= fetch(:unicorn_log) %>"

listen "/tmp/unicorn.<%= fetch(:application) %>.sock"
worker_processes <%= fetch(:unicorn_workers) %>
timeout 30

preload_app true

before_fork do |server, worker|
    # Disconnect since the database connection will not carry over
    if defined? ActiveRecord::Base
        ActiveRecord::Base.connection.disconnect!
    end

    # Quit the old unicorn process
    old_pid = "#{server.config[:pid]}.oldbin"
    if File.exists?(old_pid) && server.pid != old_pid
        begin
            Process.kill("QUIT", File.read(old_pid).to_i)
        rescue Errno::ENOENT, Errno::ESRCH
            # someone else did our job for us
        end
    end
end

after_fork do |server, worker|
    # Start up the database connection again in the worker
    if defined?(ActiveRecord::Base)
        ActiveRecord::Base.establish_connection
    end
    child_pid = server.config[:pid].sub(".pid", ".#{worker.nr}.pid")
    system("echo #{Process.pid} > #{child_pid}")

    begin
        uid, gid = Process.euid, Process.egid
        user, group = '<%= fetch(:unicorn_user) %>', '<%= fetch(:unicorn_user_group) %>'
        target_uid = Etc.getpwnam(user).uid
        target_gid = Etc.getgrnam(group).gid
        worker.tmp.chown(target_uid, target_gid)
        if uid != target_uid || gid != target_gid
            Process.initgroups(user, target_gid)
            Process::GID.change_privilege(target_gid)
            Process::UID.change_privilege(target_uid)
        end
    rescue => e
        if RAILS_ENV == 'development'
            STDERR.puts "couldn't change user, oh well"
            system("echo 'couldn't change user, oh well'")
        else
            raise e
        end
    end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
recipes_matic-1.3.0 lib/generators/recipes_matic/templates/config/deploy/recipes/templates/unicorn.rb.erb
recipes_matic-1.2.1 lib/generators/recipes_matic/templates/config/deploy/recipes/templates/unicorn.rb.erb
recipes_matic-1.2.0 lib/generators/recipes_matic/templates/config/deploy/recipes/templates/unicorn.rb.erb