added unicorn cinfig

This commit is contained in:
Alexander Negoda 2012-07-29 03:19:53 +04:00
parent 954e3b68ae
commit 7e9754714a
4 changed files with 170 additions and 0 deletions

View file

@ -35,6 +35,11 @@ group :development do
gem 'sqlite3'
gem 'ffaker'
gem 'machinist'
gem 'action_mailer_tls', :git => 'git://github.com/openrain/action_mailer_tls.git'
gem 'capistrano', :git => 'git://github.com/capistrano/capistrano.git'
gem 'capistrano-unicorn', :git => 'git://github.com/sosedoff/capistrano-unicorn.git'
gem 'rvm-capistrano'
gem 'capistrano_colors'
end
# -- Cloud storage

View file

@ -19,6 +19,17 @@ GIT
plupload-rails (1.0.6)
rails (~> 3.1)
GIT
remote: git://github.com/capistrano/capistrano.git
revision: dfb6295a5f649fc49449352c44ff7fbd2c54d3f8
specs:
capistrano (2.12.0)
highline
net-scp (>= 1.0.0)
net-sftp (>= 2.0.0)
net-ssh (>= 2.0.14)
net-ssh-gateway (>= 1.1.0)
GIT
remote: git://github.com/greendog/devise_omniauth_engine.git
revision: c46d449222133f709b5f0cafc31a57f1ae208f06
@ -50,6 +61,12 @@ GIT
configatron (2.9.1)
yamler (>= 0.1.0)
GIT
remote: git://github.com/openrain/action_mailer_tls.git
revision: 4c4db7e098d54b2239c1ce7c195417552718418c
specs:
action_mailer_tls (1.1.3)
GIT
remote: git://github.com/seyhunak/twitter-bootstrap-rails.git
revision: 087c17e4294ce10aeb80d31fe7388a2a524460dd
@ -60,6 +77,13 @@ GIT
railties (>= 3.1)
therubyracer (= 0.10.1)
GIT
remote: git://github.com/sosedoff/capistrano-unicorn.git
revision: bafc12cd8235307d30b5c85259914d17c5ece2d3
specs:
capistrano-unicorn (0.1.6)
capistrano
GIT
remote: git://github.com/yaroslav/russian.git
revision: e2dde13672bcee176f8b0be364a55ac256913231
@ -101,6 +125,7 @@ GEM
bcrypt-ruby (3.0.1)
builder (3.0.0)
cancan (1.6.8)
capistrano_colors (0.5.5)
carrierwave (0.6.2)
activemodel (>= 3.2.0)
activesupport (>= 3.2.0)
@ -137,6 +162,7 @@ GEM
ruby-hmac
formatador (0.2.3)
hashie (1.2.0)
highline (1.6.13)
hike (1.2.1)
httpauth (0.1)
i18n (0.6.0)
@ -169,7 +195,11 @@ GEM
multipart-post (1.1.5)
net-scp (1.0.4)
net-ssh (>= 1.99.1)
net-sftp (2.0.5)
net-ssh (>= 2.0.9)
net-ssh (2.5.2)
net-ssh-gateway (1.1.0)
net-ssh (>= 1.99.1)
nokogiri (1.5.5)
oauth (0.4.6)
oauth2 (0.8.0)
@ -234,6 +264,8 @@ GEM
ruby-openid (2.2.0)
ruby-openid-apps-discovery (1.2.0)
ruby-openid (>= 2.1.7)
rvm-capistrano (1.2.5)
capistrano (>= 2.0.0)
sass (3.1.20)
sass-rails (3.2.5)
railties (~> 3.2.0)
@ -265,9 +297,13 @@ PLATFORMS
ruby
DEPENDENCIES
action_mailer_tls!
ajaxful_rating_jquery!
breadcrumbs_on_rails!
cancan
capistrano!
capistrano-unicorn!
capistrano_colors
carrierwave (= 0.6.2)
coffee-rails
configatron!
@ -291,6 +327,7 @@ DEPENDENCIES
princely
rails (= 3.2.6)
russian!
rvm-capistrano
sass-rails
sqlite3
twitter-bootstrap-rails!

View file

@ -0,0 +1,64 @@
app_dir = "/home/apps/photomix/devel/current"
worker_processes 2
working_directory app_dir
# Load app into the master before forking workers for super-fast
# worker spawn times
preload_app true
# nuke workers after 60 seconds (the default)
timeout 30
# listen on a Unix domain socket and/or a TCP port,
#listen 8080 # listen to port 8080 on all TCP interfaces
#listen "127.0.0.1:8080" # listen to port 8080 on the loopback interface
listen "#{app_dir}/tmp/sockets/photomix.socket"
pid "#{app_dir}/tmp/pids/unicorn.pid"
stderr_path "#{app_dir}/log/unicorn.stderr.log"
stdout_path "#{app_dir}/log/unicorn.stdout.log"
# http://www.rubyenterpriseedition.com/faq.html#adapt_apps_for_cow
if GC.respond_to?(:copy_on_write_friendly=)
GC.copy_on_write_friendly = true
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
defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!
##
# 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.
old_pid = "#{server.config[:pid]}.oldbin"
if File.exists?(old_pid) && server.pid != old_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
# someone else did our job for us
end
end
end
after_fork do |server, worker|
# Unicorn master loads the app then forks off workers - because of the way
# Unix forking works, we need to make sure we aren't using any of the parent's
# sockets, e.g. db connection
defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
# Redis and Memcached would go here but their connections are established
# on demand, so the master never opens a socket
end

View file

@ -0,0 +1,64 @@
app_dir = "/home/apps/photomix/production/current"
worker_processes 2
working_directory app_dir
# Load app into the master before forking workers for super-fast
# worker spawn times
preload_app true
# nuke workers after 60 seconds (the default)
timeout 30
# listen on a Unix domain socket and/or a TCP port,
#listen 8080 # listen to port 8080 on all TCP interfaces
#listen "127.0.0.1:8080" # listen to port 8080 on the loopback interface
listen "#{app_dir}/tmp/sockets/photomix.socket"
pid "#{app_dir}/tmp/pids/unicorn.pid"
stderr_path "#{app_dir}/log/unicorn.stderr.log"
stdout_path "#{app_dir}/log/unicorn.stdout.log"
# http://www.rubyenterpriseedition.com/faq.html#adapt_apps_for_cow
if GC.respond_to?(:copy_on_write_friendly=)
GC.copy_on_write_friendly = true
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
defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!
##
# 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.
old_pid = "#{server.config[:pid]}.oldbin"
if File.exists?(old_pid) && server.pid != old_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
# someone else did our job for us
end
end
end
after_fork do |server, worker|
# Unicorn master loads the app then forks off workers - because of the way
# Unix forking works, we need to make sure we aren't using any of the parent's
# sockets, e.g. db connection
defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
# Redis and Memcached would go here but their connections are established
# on demand, so the master never opens a socket
end