Browse files

unicorn

  • Loading branch information...
1 parent fcdc39f commit d6cfb9e938d86e512d1f3e7880adcc77df68da07 @paulanthonywilson paulanthonywilson committed Mar 12, 2012
Showing with 68 additions and 0 deletions.
  1. +68 −0 config/unicorn.rb
View
68 config/unicorn.rb
@@ -0,0 +1,68 @@
+# config/unicorn.rb
+# Set environment to development unless something else is specified
+env = ENV["RAILS_ENV"] || "development"
+
+working_directory = File.expand_path(File.dirname(__FILE__) + '/..')
+
+# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete
+# documentation.
+worker_processes 4
+
+# listen on both a Unix domain socket and a TCP port,
+# we use a shorter backlog for quicker failover when busy
+listen "/tmp/submission_review2.socket", :backlog => 64
+
+# Preload our app for more speed
+preload_app true
+
+# nuke workers after 30 seconds instead of 60 seconds (the default)
+timeout 30
+
+pid "#{working_directory}/tmp/pids/unicorn.submission_review2.pid"
+
+# Production specific settings
+if env == "production"
+ # Help ensure your application will always spawn in the symlinked
+ # "current" directory that Capistrano sets up.
+ working_directory "/home/ubuntu/apps/submission_review2/current"
+
+ # feel free to point this anywhere accessible on the filesystem
+ user 'ubuntu'
+ shared_path = "/home/ubuntu/apps/submission_review2/shared"
+
+ stderr_path "#{shared_path}/log/unicorn.stderr.log"
+ stdout_path "#{shared_path}/log/unicorn.stdout.log"
+end
+
+before_fork do |server, worker|
+ # the following is highly recomended for Rails + "preload_app true"
+ # as there's no need for the master process to hold a connection
+ if defined?(ActiveRecord::Base)
+ ActiveRecord::Base.connection.disconnect!
+ end
+
+ # Before forking, kill the master process that belongs to the .oldbin PID.
+ # This enables 0 downtime deploys.
+ old_pid = "/tmp/unicorn.submission_review2.pid.oldbin"
+ if File.exists?(old_pid) && server.pid != old_pid
+ begin
+ Process.kill("QUIT", File.read(old_pid).to_i)
+ rescue Errno::ENOENT, Errno::ESRCH
+ # someone else did our job for us
+ end
+ end
+end
+
+after_fork do |server, worker|
+ # the following is *required* for Rails + "preload_app true",
+ if defined?(ActiveRecord::Base)
+ ActiveRecord::Base.establish_connection
+ end
+
+ # if preload_app is true, then you may also want to check and
+ # restart any other shared sockets/descriptors such as Memcached,
+ # and Redis. TokyoCabinet file handles are safe to reuse
+ # between any number of forked children (assuming your kernel
+ # correctly implements pread()/pwrite() system calls)
+end
+

0 comments on commit d6cfb9e

Please sign in to comment.