2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2012-03-20 18:47:09 +00:00
|
|
|
#base_path = File.expand_path(File.join File.dirname(__FILE__), '..')
|
|
|
|
base_path = "/srv/rosa_build"
|
|
|
|
|
2011-10-25 23:34:57 +01:00
|
|
|
rails_env = ENV['RAILS_ENV'] || 'production'
|
2011-03-28 16:49:22 +01:00
|
|
|
|
2011-12-13 21:48:25 +00:00
|
|
|
worker_processes 4
|
2012-03-20 18:59:12 +00:00
|
|
|
working_directory File.join(base_path, 'current') # available in 0.94.0+
|
2011-10-26 00:13:22 +01:00
|
|
|
|
2011-12-13 21:48:25 +00:00
|
|
|
# listen File.join(base_path, 'tmp', 'pids', 'unicorn.sock')
|
2011-12-05 18:22:20 +00:00
|
|
|
# listen "/tmp/.sock", :backlog => 64
|
2011-12-06 18:35:19 +00:00
|
|
|
# listen 8080, :tcp_nopush => true
|
2011-12-05 18:22:20 +00:00
|
|
|
|
|
|
|
# nuke workers after 30 seconds instead of 60 seconds (the default)
|
2011-12-06 18:35:19 +00:00
|
|
|
timeout 600
|
2011-12-05 18:22:20 +00:00
|
|
|
|
|
|
|
# feel free to point this anywhere accessible on the filesystem
|
2012-03-20 18:47:09 +00:00
|
|
|
pid_file = File.join(base_path, 'shared', 'pids', 'unicorn.pid')
|
2012-03-20 19:11:59 +00:00
|
|
|
old_pid = pid_file + '.oldbin'
|
2012-03-20 18:47:09 +00:00
|
|
|
|
|
|
|
pid pid_file
|
2011-03-28 16:49:22 +01:00
|
|
|
|
2012-03-20 19:11:59 +00:00
|
|
|
# REE or Ruby 2.0
|
2011-03-28 16:49:22 +01:00
|
|
|
# http://www.rubyenterpriseedition.com/faq.html#adapt_apps_for_cow
|
2012-03-20 19:11:59 +00:00
|
|
|
GC.copy_on_write_friendly = true if GC.respond_to?(:copy_on_write_friendly=)
|
2011-03-28 16:49:22 +01:00
|
|
|
|
2012-03-20 16:54:51 +00:00
|
|
|
before_exec do |server|
|
2012-03-20 18:47:09 +00:00
|
|
|
ENV["BUNDLE_GEMFILE"] = "#{base_path}/current/Gemfile"
|
2012-03-20 16:54:51 +00:00
|
|
|
end
|
|
|
|
|
2011-03-28 16:49:22 +01:00
|
|
|
# By default, the Unicorn logger will write to stderr.
|
|
|
|
# Additionally, ome applications/frameworks log to stderr or stdout,
|
|
|
|
# so prevent them from going to /dev/null when daemonized here:
|
2012-03-20 18:47:09 +00:00
|
|
|
stderr_path File.join(base_path, 'current', 'log', 'unicorn.stderr.log')
|
|
|
|
stdout_path File.join(base_path, 'current', 'log', 'unicorn.stdout.log')
|
2011-03-28 16:49:22 +01:00
|
|
|
|
|
|
|
# combine REE with "preload_app true" for memory savings
|
|
|
|
# http://rubyenterpriseedition.com/faq.html#adapt_apps_for_cow
|
2012-03-20 16:54:51 +00:00
|
|
|
preload_app true
|
2011-03-28 16:49:22 +01:00
|
|
|
|
2011-10-25 14:23:20 +01:00
|
|
|
before_fork do |server, worker|
|
2012-03-20 16:54:51 +00:00
|
|
|
# This option works in together with preload_app true setting
|
|
|
|
# What is does is prevent the master process from holding
|
|
|
|
# the database connection
|
|
|
|
defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!
|
|
|
|
|
2011-10-25 14:23:20 +01:00
|
|
|
# When sent a USR2, Unicorn will suffix its pidfile with .oldbin and
|
|
|
|
# immediately start loading up a new version of itself (loaded with a new
|
|
|
|
# version of our app). When this new Unicorn is completely loaded
|
|
|
|
# it will begin spawning workers. The first worker spawned will check to
|
|
|
|
# see if an .oldbin pidfile exists. If so, this means we've just booted up
|
|
|
|
# a new Unicorn and need to tell the old one that it can now die. To do so
|
|
|
|
# we send it a QUIT.
|
|
|
|
#
|
|
|
|
# Using this method we get 0 downtime deploys.
|
2012-03-20 18:47:09 +00:00
|
|
|
|
2011-10-25 14:23:20 +01:00
|
|
|
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
|
2011-03-28 16:49:22 +01:00
|
|
|
|
|
|
|
after_fork do |server, worker|
|
2011-10-25 14:23:20 +01:00
|
|
|
# Here we are establishing the connection after forking worker processes
|
|
|
|
defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
|
2011-03-28 16:49:22 +01:00
|
|
|
|
|
|
|
# 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)
|
2012-03-20 16:54:51 +00:00
|
|
|
# srand
|
2011-03-28 16:49:22 +01:00
|
|
|
end
|