|
| 1 | +# Sample verbose configuration file for Unicorn (not Rack) |
| 2 | +# |
| 3 | +# This configuration file documents many features of Unicorn |
| 4 | +# that may not be needed for some applications. See |
| 5 | +# http://unicorn.bogomips.org/examples/unicorn.conf.minimal.rb |
| 6 | +# for a much simpler configuration file. |
| 7 | +# |
| 8 | +# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete |
| 9 | +# documentation. |
| 10 | + |
| 11 | +# Uncomment and customize the last line to run in a non-root path |
| 12 | +# WARNING: We recommend creating a FQDN to host GitLab in a root path instead of this. |
| 13 | +# Note that four settings need to be changed for this to work. |
| 14 | +# 1) In your application.rb file: config.relative_url_root = "/gitlab" |
| 15 | +# 2) In your gitlab.yml file: relative_url_root: /gitlab |
| 16 | +# 3) In your unicorn.rb: ENV['RAILS_RELATIVE_URL_ROOT'] = "/gitlab" |
| 17 | +# 4) In ../gitlab-shell/config.yml: gitlab_url: "http://127.0.0.1/gitlab" |
| 18 | +# To update the path, run: sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production |
| 19 | +# |
| 20 | +ENV['RAILS_RELATIVE_URL_ROOT'] = "/gitlab" |
| 21 | + |
| 22 | +# Use at least one worker per core if you're on a dedicated server, |
| 23 | +# more will usually help for _short_ waits on databases/caches. |
| 24 | +worker_processes 2 |
| 25 | + |
| 26 | +# Since Unicorn is never exposed to outside clients, it does not need to |
| 27 | +# run on the standard HTTP port (80), there is no reason to start Unicorn |
| 28 | +# as root unless it's from system init scripts. |
| 29 | +# If running the master process as root and the workers as an unprivileged |
| 30 | +# user, do this to switch euid/egid in the workers (also chowns logs): |
| 31 | +# user "unprivileged_user", "unprivileged_group" |
| 32 | + |
| 33 | +# Help ensure your application will always spawn in the symlinked |
| 34 | +# "current" directory that Capistrano sets up. |
| 35 | +working_directory "/home/david/sites/gitlab" # available in 0.94.0+ |
| 36 | + |
| 37 | +# listen on both a Unix domain socket and a TCP port, |
| 38 | +# we use a shorter backlog for quicker failover when busy |
| 39 | +listen "/home/david/shared/socket/gitlab/gitlab.socket", :backlog => 64 |
| 40 | +listen 8181, :tcp_nopush => true |
| 41 | + |
| 42 | +# nuke workers after 30 seconds instead of 60 seconds (the default) |
| 43 | +timeout 30 |
| 44 | + |
| 45 | +# feel free to point this anywhere accessible on the filesystem |
| 46 | +pid "/home/david/shared/pid/gitlab/unicorn.pid" |
| 47 | + |
| 48 | +# By default, the Unicorn logger will write to stderr. |
| 49 | +# Additionally, some applications/frameworks log to stderr or stdout, |
| 50 | +# so prevent them from going to /dev/null when daemonized here: |
| 51 | +stderr_path "/home/david/shared/log/gitlab/unicorn.stderr.log" |
| 52 | +stdout_path "/home/david/shared/log/gitlab/unicorn.stdout.log" |
| 53 | + |
| 54 | +# combine Ruby 2.0.0dev or REE with "preload_app true" for memory savings |
| 55 | +# http://rubyenterpriseedition.com/faq.html#adapt_apps_for_cow |
| 56 | +preload_app true |
| 57 | +GC.respond_to?(:copy_on_write_friendly=) and |
| 58 | + GC.copy_on_write_friendly = true |
| 59 | + |
| 60 | +# Enable this flag to have unicorn test client connections by writing the |
| 61 | +# beginning of the HTTP headers before calling the application. This |
| 62 | +# prevents calling the application for connections that have disconnected |
| 63 | +# while queued. This is only guaranteed to detect clients on the same |
| 64 | +# host unicorn runs on, and unlikely to detect disconnects even on a |
| 65 | +# fast LAN. |
| 66 | +check_client_connection false |
| 67 | + |
| 68 | +before_fork do |server, worker| |
| 69 | + # the following is highly recomended for Rails + "preload_app true" |
| 70 | + # as there's no need for the master process to hold a connection |
| 71 | + defined?(ActiveRecord::Base) and |
| 72 | + ActiveRecord::Base.connection.disconnect! |
| 73 | + |
| 74 | + # The following is only recommended for memory/DB-constrained |
| 75 | + # installations. It is not needed if your system can house |
| 76 | + # twice as many worker_processes as you have configured. |
| 77 | + # |
| 78 | + # This allows a new master process to incrementally |
| 79 | + # phase out the old master process with SIGTTOU to avoid a |
| 80 | + # thundering herd (especially in the "preload_app false" case) |
| 81 | + # when doing a transparent upgrade. The last worker spawned |
| 82 | + # will then kill off the old master process with a SIGQUIT. |
| 83 | + old_pid = "#{server.config[:pid]}.oldbin" |
| 84 | + if old_pid != server.pid |
| 85 | + begin |
| 86 | + sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU |
| 87 | + Process.kill(sig, File.read(old_pid).to_i) |
| 88 | + rescue Errno::ENOENT, Errno::ESRCH |
| 89 | + end |
| 90 | + end |
| 91 | + # |
| 92 | + # Throttle the master from forking too quickly by sleeping. Due |
| 93 | + # to the implementation of standard Unix signal handlers, this |
| 94 | + # helps (but does not completely) prevent identical, repeated signals |
| 95 | + # from being lost when the receiving process is busy. |
| 96 | + # sleep 1 |
| 97 | +end |
| 98 | + |
| 99 | +after_fork do |server, worker| |
| 100 | + # per-process listener ports for debugging/admin/migrations |
| 101 | + # addr = "127.0.0.1:#{9293 + worker.nr}" |
| 102 | + # server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => true) |
| 103 | + |
| 104 | + # the following is *required* for Rails + "preload_app true", |
| 105 | + defined?(ActiveRecord::Base) and |
| 106 | + ActiveRecord::Base.establish_connection |
| 107 | + |
| 108 | + # if preload_app is true, then you may also want to check and |
| 109 | + # restart any other shared sockets/descriptors such as Memcached, |
| 110 | + # and Redis. TokyoCabinet file handles are safe to reuse |
| 111 | + # between any number of forked children (assuming your kernel |
| 112 | + # correctly implements pread()/pwrite() system calls) |
| 113 | +end |
0 commit comments