Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

unicorn

  • Loading branch information...
commit d6cfb9e938d86e512d1f3e7880adcc77df68da07 1 parent fcdc39f
Paul Wilson paulanthonywilson authored

Showing 1 changed file with 68 additions and 0 deletions. Show diff stats Hide diff stats

  1. +68 0 config/unicorn.rb
68 config/unicorn.rb
... ... @@ -0,0 +1,68 @@
  1 +# config/unicorn.rb
  2 +# Set environment to development unless something else is specified
  3 +env = ENV["RAILS_ENV"] || "development"
  4 +
  5 +working_directory = File.expand_path(File.dirname(__FILE__) + '/..')
  6 +
  7 +# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete
  8 +# documentation.
  9 +worker_processes 4
  10 +
  11 +# listen on both a Unix domain socket and a TCP port,
  12 +# we use a shorter backlog for quicker failover when busy
  13 +listen "/tmp/submission_review2.socket", :backlog => 64
  14 +
  15 +# Preload our app for more speed
  16 +preload_app true
  17 +
  18 +# nuke workers after 30 seconds instead of 60 seconds (the default)
  19 +timeout 30
  20 +
  21 +pid "#{working_directory}/tmp/pids/unicorn.submission_review2.pid"
  22 +
  23 +# Production specific settings
  24 +if env == "production"
  25 + # Help ensure your application will always spawn in the symlinked
  26 + # "current" directory that Capistrano sets up.
  27 + working_directory "/home/ubuntu/apps/submission_review2/current"
  28 +
  29 + # feel free to point this anywhere accessible on the filesystem
  30 + user 'ubuntu'
  31 + shared_path = "/home/ubuntu/apps/submission_review2/shared"
  32 +
  33 + stderr_path "#{shared_path}/log/unicorn.stderr.log"
  34 + stdout_path "#{shared_path}/log/unicorn.stdout.log"
  35 +end
  36 +
  37 +before_fork do |server, worker|
  38 + # the following is highly recomended for Rails + "preload_app true"
  39 + # as there's no need for the master process to hold a connection
  40 + if defined?(ActiveRecord::Base)
  41 + ActiveRecord::Base.connection.disconnect!
  42 + end
  43 +
  44 + # Before forking, kill the master process that belongs to the .oldbin PID.
  45 + # This enables 0 downtime deploys.
  46 + old_pid = "/tmp/unicorn.submission_review2.pid.oldbin"
  47 + if File.exists?(old_pid) && server.pid != old_pid
  48 + begin
  49 + Process.kill("QUIT", File.read(old_pid).to_i)
  50 + rescue Errno::ENOENT, Errno::ESRCH
  51 + # someone else did our job for us
  52 + end
  53 + end
  54 +end
  55 +
  56 +after_fork do |server, worker|
  57 + # the following is *required* for Rails + "preload_app true",
  58 + if defined?(ActiveRecord::Base)
  59 + ActiveRecord::Base.establish_connection
  60 + end
  61 +
  62 + # if preload_app is true, then you may also want to check and
  63 + # restart any other shared sockets/descriptors such as Memcached,
  64 + # and Redis. TokyoCabinet file handles are safe to reuse
  65 + # between any number of forked children (assuming your kernel
  66 + # correctly implements pread()/pwrite() system calls)
  67 +end
  68 +

0 comments on commit d6cfb9e

Please sign in to comment.
Something went wrong with that request. Please try again.