PageRenderTime 20ms CodeModel.GetById 9ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/config/unicorn.rb

https://github.com/christianhellsten/aktagon-snippets
Ruby | 42 lines | 22 code | 8 blank | 12 comment | 3 complexity | 9f659a4de88502b5569150d526a9e249 MD5 | raw file
 1worker_processes 2
 2user 'deploy', 'deploy'
 3
 4preload_app true
 5timeout 30
 6
 7working_directory "/var/www/snippets/current"
 8listen "/tmp/snippets.socket", :backlog => 64
 9
10pid '/tmp/snippets.pid'
11stderr_path "/var/www/snippets/current/log/unicorn.stderr.log"
12stdout_path "/var/www/snippets/current/log/unicorn.stdout.log"
13
14
15before_fork do |server, worker|
16  # the following is highly recomended for Rails + "preload_app true"
17  # as there's no need for the master process to hold a connection
18  #if defined?(ActiveRecord::Base)
19    #ActiveRecord::Base.connection.disconnect!
20  #end
21
22  # Before forking, kill the master process that belongs to the .oldbin PID.
23  # This enables 0 downtime deploys.
24  old_pid = "#{server.config[:pid]}.oldbin"
25  if File.exists?(old_pid) && server.pid != old_pid
26    begin
27      Process.kill("QUIT", File.read(old_pid).to_i)
28    rescue Errno::ENOENT, Errno::ESRCH
29      # someone else did our job for us
30    end
31  end
32end
33
34after_fork do |server, worker|
35  # the following is *required* for Rails + "preload_app true",
36  #if defined?(ActiveRecord::Base)
37    #ActiveRecord::Base.establish_connection
38  #end
39
40  child_pid = server.config[:pid].sub('.pid', ".#{worker.nr}.pid")
41  system("echo #{Process.pid} > #{child_pid}")
42end