Skip to content

Instantly share code, notes, and snippets.

@vdv
Created January 30, 2012 15:23
Show Gist options
  • Save vdv/1704949 to your computer and use it in GitHub Desktop.
Save vdv/1704949 to your computer and use it in GitHub Desktop.
unicorn simple config
worker_processes 1
timeout 180
# Location of stderr/stdout logs
stderr_path "/home/www/my_server/current/log/unicorn.err.log"
#stdout_path "/home/www/my_server/current/log/unicorn.out.log"
listen '/home/www/my_server/current/tmp/sockets/unicorn.socket'
pid_file = "/home/www/my_server/current/tmp/pids/unicorn.pid"
pid pid_file
preload_app true
GC.respond_to?(:copy_on_write_friendly=) and
GC.copy_on_write_friendly = true
after_fork do |server, worker|
begin
old_pid = "#{server.config[:pid]}.oldbin"
if File.exists?(old_pid) && server.pid != old_pid
begin
# after this all request will be processed by new workers
Process.kill("WINCH", File.read(old_pid).to_i)
sleep 0.1
# send stop for the old master
Process.kill("QUIT", File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH
end
end
rescue => e
puts "[#{Process}]: #{e.message}\n"
puts "[#{Process}]: #{e.backtrace.join("\n")}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment