1worker_processes 3
2
3listen ENV["UNICORN_PATH"] + "/tmp/sockets/gitlab.socket", :backlog => 1024
4listen "/run/gitlab/gitlab.socket", :backlog => 1024
5
6working_directory ENV["GITLAB_PATH"]
7
8pid ENV["UNICORN_PATH"] + "/tmp/pids/unicorn.pid"
9
10timeout 60
11
12# combine Ruby 2.0.0dev or REE with "preload_app true" for memory savings
13# http://rubyenterpriseedition.com/faq.html#adapt_apps_for_cow
14preload_app true
15GC.respond_to?(:copy_on_write_friendly=) and
16 GC.copy_on_write_friendly = true
17
18check_client_connection false
19
20before_fork do |server, worker|
21 # the following is highly recommended for Rails + "preload_app true"
22 # as there's no need for the master process to hold a connection
23 defined?(ActiveRecord::Base) and
24 ActiveRecord::Base.connection.disconnect!
25
26 # The following is only recommended for memory/DB-constrained
27 # installations. It is not needed if your system can house
28 # twice as many worker_processes as you have configured.
29 #
30 # This allows a new master process to incrementally
31 # phase out the old master process with SIGTTOU to avoid a
32 # thundering herd (especially in the "preload_app false" case)
33 # when doing a transparent upgrade. The last worker spawned
34 # will then kill off the old master process with a SIGQUIT.
35 old_pid = "#{server.config[:pid]}.oldbin"
36 if old_pid != server.pid
37 begin
38 sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
39 Process.kill(sig, File.read(old_pid).to_i)
40 rescue Errno::ENOENT, Errno::ESRCH
41 end
42 end
43
44 # Throttle the master from forking too quickly by sleeping. Due
45 # to the implementation of standard Unix signal handlers, this
46 # helps (but does not completely) prevent identical, repeated signals
47 # from being lost when the receiving process is busy.
48 # sleep 1
49end
50
51after_fork do |server, worker|
52 # per-process listener ports for debugging/admin/migrations
53 # addr = "127.0.0.1:#{9293 + worker.nr}"
54 # server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => true)
55
56 # the following is *required* for Rails + "preload_app true",
57 defined?(ActiveRecord::Base) and
58 ActiveRecord::Base.establish_connection
59
60 # reset prometheus client, this will cause any opened metrics files to be closed
61 defined?(::Prometheus::Client.reinitialize_on_pid_change) &&
62 Prometheus::Client.reinitialize_on_pid_change
63
64 # if preload_app is true, then you may also want to check and
65 # restart any other shared sockets/descriptors such as Memcached,
66 # and Redis. TokyoCabinet file handles are safe to reuse
67 # between any number of forked children (assuming your kernel
68 # correctly implements pread()/pwrite() system calls)
69end