1 app_dir = "/home/gitlab/gitlab/"
3 working_directory app_dir
5 # Load app into the master before forking workers for super-fast
9 # nuke workers after 60 seconds (the default)
12 # listen on a Unix domain socket and/or a TCP port,
14 #listen 8080 # listen to port 8080 on all TCP interfaces
15 #listen "127.0.0.1:8080" # listen to port 8080 on the loopback interface
16 listen "#{app_dir}/tmp/sockets/gitlab.socket"
18 pid "#{app_dir}/tmp/pids/unicorn.pid"
19 stderr_path "#{app_dir}/log/unicorn.stderr.log"
20 stdout_path "#{app_dir}/log/unicorn.stdout.log"
22 # http://www.rubyenterpriseedition.com/faq.html#adapt_apps_for_cow
23 if GC.respond_to?(:copy_on_write_friendly=)
24 GC.copy_on_write_friendly = true
28 before_fork do |server, worker|
29 # the following is highly recomended for Rails + "preload_app true"
30 # as there's no need for the master process to hold a connection
31 defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!
34 # When sent a USR2, Unicorn will suffix its pidfile with .oldbin and
35 # immediately start loading up a new version of itself (loaded with a new
36 # version of our app). When this new Unicorn is completely loaded
37 # it will begin spawning workers. The first worker spawned will check to
38 # see if an .oldbin pidfile exists. If so, this means we've just booted up
39 # a new Unicorn and need to tell the old one that it can now die. To do so
42 # Using this method we get 0 downtime deploys.
44 old_pid = "#{server.config[:pid]}.oldbin"
46 if File.exists?(old_pid) && server.pid != old_pid
48 sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
49 Process.kill(sig, File.read(old_pid).to_i)
50 rescue Errno::ENOENT, Errno::ESRCH
51 # someone else did our job for us
56 after_fork do |server, worker|
57 # Unicorn master loads the app then forks off workers - because of the way
58 # Unix forking works, we need to make sure we aren't using any of the parent's
59 # sockets, e.g. db connection
61 defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
62 # Redis and Memcached would go here but their connections are established
63 # on demand, so the master never opens a socket