22. config/deploy.rb
require 'bundler/capistrano'
require "rvm/capistrano"
set :rvm_ruby_string, '1.9.3'
set :application, 'testaws'
set :user, 'ubuntu'
set :scm, 'git'
set :repository, 'git@github.com:igas/testaws.git'
set :branch, 'master'
set :deploy_to, "/home/#{user}/www/#{application}"
set :use_sudo, false
set :domain, '184.72.181.253'
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
server domain, :web, :app, :db, primary: true
namespace :deploy do
task :start, except: { no_release: true } do
run "cd #{current_path} && bundle exec unicorn -c config/unicorn.rb -D"
end
task :stop, except: { no_release: true } do
run "cd #{current_path} && kill `cat tmp/pids/unicorn.#{application}.pid`"
end
end
22
23. config/unicorn.rb
env = ENV["RAILS_ENV"] || "development"
user = "ubuntu"
app = "testaws"
root_path = "/home/#{user}/www/#{app}"
current_path = "#{root_path}/current"
shared_path = "#{root_path}/shared"
log_path = "#{shared_path}/log"
worker_processes 2
preload_app true
timeout 240
listen "/tmp/#{app}.socket", backlog: 64
pid "#{shared_path}/pids/unicorn.#{app}.pid"
working_directory current_path
stderr_path "#{shared_path}/log/unicorn.stderr.log"
stdout_path "#{shared_path}/log/unicorn.stdout.log"
before_fork do |server, worker|
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
after_fork do |server, worker|
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
23