{{ autogenerated }}
# see:
# https://gitlab.com/gitlab-org/gitlab-ce/blob/master/config/unicorn.rb.example
# https://gitlab.com/gitlab-org/gitlab-ce/blob/master/config/unicorn.rb.example.development
# https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/files/gitlab-cookbooks/gitlab/templates/default/unicorn.rb.erb
# (last updated for omnibus-gitlab 8.4.4+ce.0-0-g1680742)

{% from 'macrolib.cfg.in' import cfg  with context %}

# What ports/sockets to listen on, and what options for them.
# we listen only on unix socket
listen "{{ unicorn.socket }}", :backlog => {{ cfg('unicorn_backlog_socket') }}
#listen "127.0.0.1:8888", :tcp_nopush => true

working_directory '{{ gitlab_work.location }}'

# What the timeout for killing busy workers is, in seconds
timeout {{ cfg('unicorn_worker_timeout') }}

# Whether the app should be pre-loaded
preload_app true

# How many worker processes
worker_processes {{ cfg('unicorn_worker_processes') }}

# about before_fork / after_fork - see:
#   https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/files/gitlab-cookbooks/gitlab/definitions/unicorn_service.rb
#   http://bogomips.org/unicorn.git/tree/examples/unicorn.conf.rb?id=3312aca8#n75

# What to do before we fork a worker
before_fork do |server, worker|
  # XXX why gitlab does not enable this?
  # # the following is highly recomended for Rails + "preload_app true"
  # # as there's no need for the master process to hold a connection
  # defined?(ActiveRecord::Base) and
  #   ActiveRecord::Base.connection.disconnect!

  # This allows a new master process to incrementally
  # phase out the old master process with SIGTTOU to avoid a
  # thundering herd (especially in the "preload_app false" case)
  # when doing a transparent upgrade.  The last worker spawned
  # will then kill off the old master process with a SIGQUIT.
  old_pid = "#{server.config[:pid]}.oldbin"
  if old_pid != server.pid
    begin
      sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
      Process.kill(sig, File.read(old_pid).to_i)
    rescue Errno::ENOENT, Errno::ESRCH
    end
  end
end

# What to do after we fork a worker
after_fork do |server, worker|
  # per-process listener ports for debugging/admin/migrations
  # addr = "127.0.0.1:#{9293 + worker.nr}"
  # server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => true)

  # XXX why gitlab does not enable this?
  # # the following is *required* for Rails + "preload_app true",
  # defined?(ActiveRecord::Base) and
  #   ActiveRecord::Base.establish_connection
end


# Where to drop a pidfile
pid '{{ directory.run }}/unicorn.pid'

# Where stderr gets logged
stderr_path '{{ unicorn.log }}/unicorn_stderr.log'

# Where stdout gets logged
stdout_path '{{ unicorn.log }}/unicorn_stdout.log'