Skip to content

Instantly share code, notes, and snippets.

@kryachkov
Last active September 14, 2015 15:48
Show Gist options
  • Save kryachkov/25593df9b33a6b2ab412 to your computer and use it in GitHub Desktop.
Save kryachkov/25593df9b33a6b2ab412 to your computer and use it in GitHub Desktop.
staging:
adapter: postgresql
encoding: unicode
database: myapp
pool: 5
username: myapp
password: password
host: localhost
staging:
admin_name: Admin
admin_email: admin@mail.com
admin_password: password
domain_name: localhost
secret_key_base: 123qwe
rails_env = ENV['RAILS_ENV'] || 'production'
rails_root = File.expand_path( File.dirname(__FILE__) + "/..")
pid '/home/myapp/application/shared/tmp/pids/unicorn.pid'
worker_processes 1
preload_app true
timeout 30
listen 3000
stderr_path rails_root + "/log/unicorn.stderr.log"
stdout_path rails_root + "/log/unicorn.stdout.log"
before_exec do |server|
ENV["BUNDLE_GEMFILE"] = "/home/myapp/application/current/Gemfile"
end
before_fork do |server, worker|
old_pid = rails_root + '/tmp/pids/unicorn.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|
ActiveRecord::Base.establish_connection
child_pid = server.config[:pid].to_s.sub('.pid', ".#{worker.nr}.pid")
system("echo #{Process.pid} > #{child_pid}")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment