Commit a3b664b7 by tady

capistrano, unicorn config

parent a171864a
...@@ -23,3 +23,5 @@ require 'capistrano/rails/migrations' ...@@ -23,3 +23,5 @@ require 'capistrano/rails/migrations'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined. # Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r } Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
require 'capistrano3/unicorn'
...@@ -25,6 +25,8 @@ gem 'jbuilder' ...@@ -25,6 +25,8 @@ gem 'jbuilder'
gem 'i18n_generators' gem 'i18n_generators'
gem 'unicorn'
group :doc do group :doc do
# bundle exec rake doc:rails generates the API under doc/api. # bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false gem 'sdoc', require: false
...@@ -77,6 +79,7 @@ group :development do ...@@ -77,6 +79,7 @@ group :development do
gem 'capistrano-bundler', '~> 1.1.2' gem 'capistrano-bundler', '~> 1.1.2'
gem 'capistrano-rails', '~> 1.1' gem 'capistrano-rails', '~> 1.1'
gem 'capistrano-rbenv', '~> 2.0' gem 'capistrano-rbenv', '~> 2.0'
gem 'capistrano3-unicorn'
end end
group :development, :test do group :development, :test do
......
...@@ -80,6 +80,8 @@ GEM ...@@ -80,6 +80,8 @@ GEM
capistrano-rbenv (2.0.2) capistrano-rbenv (2.0.2)
capistrano (~> 3.1) capistrano (~> 3.1)
sshkit (~> 1.3) sshkit (~> 1.3)
capistrano3-unicorn (0.2.1)
capistrano (~> 3.1, >= 3.1.0)
capybara (2.4.1) capybara (2.4.1)
mime-types (>= 1.16) mime-types (>= 1.16)
nokogiri (>= 1.3.3) nokogiri (>= 1.3.3)
...@@ -176,6 +178,7 @@ GEM ...@@ -176,6 +178,7 @@ GEM
json (1.8.1) json (1.8.1)
jwt (0.1.11) jwt (0.1.11)
multi_json (>= 1.5) multi_json (>= 1.5)
kgio (2.9.2)
launchy (2.4.2) launchy (2.4.2)
addressable (~> 2.3) addressable (~> 2.3)
libv8 (3.16.14.3) libv8 (3.16.14.3)
...@@ -276,6 +279,7 @@ GEM ...@@ -276,6 +279,7 @@ GEM
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.18.1, < 2.0)
rainbow (2.0.0) rainbow (2.0.0)
raindrops (0.13.0)
rake (10.3.2) rake (10.3.2)
rb-fsevent (0.9.4) rb-fsevent (0.9.4)
rb-inotify (0.9.5) rb-inotify (0.9.5)
...@@ -377,6 +381,10 @@ GEM ...@@ -377,6 +381,10 @@ GEM
unf (0.1.4) unf (0.1.4)
unf_ext unf_ext
unf_ext (0.0.6) unf_ext (0.0.6)
unicorn (4.8.3)
kgio (~> 2.6)
rack
raindrops (~> 0.7)
validates_email_format_of (1.5.3) validates_email_format_of (1.5.3)
warden (1.2.3) warden (1.2.3)
rack (>= 1.0) rack (>= 1.0)
...@@ -401,6 +409,7 @@ DEPENDENCIES ...@@ -401,6 +409,7 @@ DEPENDENCIES
capistrano-bundler (~> 1.1.2) capistrano-bundler (~> 1.1.2)
capistrano-rails (~> 1.1) capistrano-rails (~> 1.1)
capistrano-rbenv (~> 2.0) capistrano-rbenv (~> 2.0)
capistrano3-unicorn
capybara capybara
coderay coderay
coffee-rails coffee-rails
...@@ -442,4 +451,5 @@ DEPENDENCIES ...@@ -442,4 +451,5 @@ DEPENDENCIES
thin thin
turnip turnip
uglifier uglifier
unicorn
validates_email_format_of validates_email_format_of
...@@ -6,9 +6,10 @@ set :repo_url, 'git@github.com:tadyjp/rendezvous.git' ...@@ -6,9 +6,10 @@ set :repo_url, 'git@github.com:tadyjp/rendezvous.git'
# Default branch is :master # Default branch is :master
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp } # ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }
set :branch, fetch(:branch, "master")
# Default deploy_to directory is /var/www/my_app # Default deploy_to directory is /var/www/my_app
set :deploy_to, '/var/rails/rendezvous' set :deploy_to, '/var/www/rendezvous'
# Default value for :scm is :git # Default value for :scm is :git
# set :scm, :git # set :scm, :git
...@@ -35,32 +36,53 @@ set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public ...@@ -35,32 +36,53 @@ set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public
set :keep_releases, 5 set :keep_releases, 5
set :rbenv_type, :system set :rbenv_type, :system
set :rbenv_ruby, '2.0.0-p353' set :rbenv_ruby, '2.1.2'
set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec" set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"
set :rbenv_map_bins, %w{rake gem bundle ruby rails} set :rbenv_map_bins, %w{rake gem bundle ruby rails}
set :rbenv_roles, :all # default value set :rbenv_roles, :all # default value
after 'deploy:publishing', 'deploy:restart' # namespace :deploy do
# desc 'Restart application'
# task :restart do
# on roles(:app), in: :sequence, wait: 5 do
# # Your restart mechanism here, for example:
# execute :touch, release_path.join('tmp/restart.txt')
# end
# end
# after 'deploy:publishing', 'deploy:restart'
# after :publishing, :restart
# after :restart, :clear_cache do
# on roles(:web), in: :groups, limit: 3, wait: 10 do
# # Here we can do anything such as:
# within release_path do
# execute :rake, 'tmp:clear'
# end
# end
# end
# end
after 'deploy:publishing', 'deploy:restart'
namespace :deploy do namespace :deploy do
desc 'Restart application'
task :restart do task :restart do
on roles(:app), in: :sequence, wait: 5 do invoke 'unicorn:restart'
# Your restart mechanism here, for example:
execute :touch, release_path.join('tmp/restart.txt')
end
end end
end
after :publishing, :restart namespace :linked_files do
desc 'Touches all your linked files'
after :restart, :clear_cache do task :touch do
on roles(:web), in: :groups, limit: 3, wait: 10 do on release_roles :all do
# Here we can do anything such as: within shared_path do
within release_path do fetch(:linked_files, []).each do |file|
execute :rake, 'tmp:clear' execute :touch, file
info "Touched: #{file}"
end
end end
end end
end end
before 'deploy:check:make_linked_dirs', 'linked_files:touch'
before 'deploy:check:linked_files', 'linked_files:touch'
end end
# paths
app_path = "/var/www/rendezvous"
working_directory "#{app_path}/current"
pid "#{app_path}/current/tmp/pids/unicorn.pid"
# listen
listen "/tmp/unicorn-rendezvous.socket", :backlog => 64
# logging
stderr_path "log/unicorn.stderr.log"
stdout_path "log/unicorn.stdout.log"
# workers
worker_processes 3
# use correct Gemfile on restarts
before_exec do |server|
ENV['BUNDLE_GEMFILE'] = "#{app_path}/current/Gemfile"
end
# preload
preload_app true
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 = "#{server.config[: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|
if defined?(ActiveRecord::Base)
ActiveRecord::Base.establish_connection
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment