unicorn.rb.in 4.02 KB
Newer Older
1 2 3 4 5
{{ 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
6
# (last updated for omnibus-gitlab 8.7.9+ce.1-0-gf589ad7)
7

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

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

15
working_directory '{{ gitlab_work.location }}'
16 17

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

20 21
# combine Ruby 2.0.0dev or REE with "preload_app true" for memory savings
# http://rubyenterpriseedition.com/faq.html#adapt_apps_for_cow
22
preload_app true
23 24 25 26 27 28 29 30 31


# Enable this flag to have unicorn test client connections by writing the
# beginning of the HTTP headers before calling the application.  This
# prevents calling the application for connections that have disconnected
# while queued.  This is only guaranteed to detect clients on the same
# host unicorn runs on, and unlikely to detect disconnects even on a
# fast LAN.
check_client_connection false
32

33 34 35 36 37 38 39
require_relative '{{ gitlab_work.location }}/lib/gitlab/cluster/lifecycle_events'

before_exec do |server|
  # Signal application hooks that we're about to restart
  Gitlab::Cluster::LifecycleEvents.do_before_master_restart
end

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

43 44 45 46
# 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

47 48
# What to do before we fork a worker
before_fork do |server, worker|
49 50
  # Signal application hooks that we're about to fork
  Gitlab::Cluster::LifecycleEvents.do_before_fork
51

52 53 54 55
  # The following is only recommended for memory/DB-constrained
  # installations.  It is not needed if your system can house
  # twice as many worker_processes as you have configured.
  #
56 57 58 59 60 61 62 63 64 65 66 67 68
  # 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
69 70 71 72 73 74
  #
  # Throttle the master from forking too quickly by sleeping.  Due
  # to the implementation of standard Unix signal handlers, this
  # helps (but does not completely) prevent identical, repeated signals
  # from being lost when the receiving process is busy.
  # sleep 1
75 76
end

77

78 79
# What to do after we fork a worker
after_fork do |server, worker|
80 81 82
  # Signal application hooks of worker start
  Gitlab::Cluster::LifecycleEvents.do_worker_start

83 84 85 86
  # 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)

87 88
end

89

90
# Where to drop a pidfile
91
pid '{{ directory.run }}/unicorn.pid'
92 93

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

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

99
{# we do not support Relative url
100 101 102 103
<%- if @relative_url %>
# Relative url from where GitLab is served
ENV['RAILS_RELATIVE_URL_ROOT'] = "<%= @relative_url %>"

104 105
<%- end %>
#}
106 107

# Min memory size (RSS) per worker
108
ENV['GITLAB_UNICORN_MEMORY_MIN'] = ({{ cfg('unicorn_worker_memory_limit_min') }}).to_s
109 110

# Max memory size (RSS) per worker
111
ENV['GITLAB_UNICORN_MEMORY_MAX'] = ({{ cfg('unicorn_worker_memory_limit_max') }}).to_s