Improve and fix configs. Refs #2261

This commit is contained in:
Pavel Chipiga 2011-12-06 20:35:19 +02:00
parent fcc17da1ad
commit 7e05c5b385
7 changed files with 62 additions and 50 deletions

View File

@ -59,6 +59,7 @@ group :development do
# deploy
gem 'capistrano', :require => false
gem 'capistrano-ext', :require => false
gem 'cape', :require => false
# gem 'capistrano-exts', :require => false #, :git => 'git://github.com/chipiga/capistrano-exts.git'
# gem 'capistrano-recipes', :require => false
gem 'capistrano_colors', :require => false

View File

@ -43,6 +43,7 @@ GEM
bcrypt-ruby (3.0.1)
builder (2.1.2)
cancan (1.6.7)
cape (1.0.1)
capistrano (2.9.0)
highline
net-scp (>= 1.0.0)
@ -204,6 +205,7 @@ DEPENDENCIES
airbrake (~> 3.0.5)
ancestry (~> 1.2.4)
cancan (~> 1.6.7)
cape
capistrano
capistrano-ext
capistrano_colors

View File

@ -16,7 +16,7 @@ ssh_options[:forward_agent] = true
default_run_options[:pty] = true
set :application, "rosa_build"
set :deploy_to, "/srv/#{application}"
set(:deploy_to) { "/srv/#{application}" }
set :user, "rosa"
set :use_sudo, false
set :keep_releases, 3
@ -27,60 +27,44 @@ set :scm, "git"
# set :deploy_via, :copy
# set :copy_cache, true
set :unicorn_binary, "bundle exec unicorn"
set :unicorn_config, "#{current_path}/config/unicorn.rb"
set :unicorn_pid, "#{current_path}/tmp/pids/unicorn.pid"
set :unicorn_port, 8080
require 'lib/recipes/nginx'
require 'lib/recipes/unicorn'
namespace :deploy do
task :start, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && #{try_sudo} #{unicorn_binary} -c #{unicorn_config} -p #{unicorn_port} -E #{rails_env} -D"
end
task :stop, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} kill `cat #{unicorn_pid}`"
end
task :graceful_stop, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} kill -s QUIT `cat #{unicorn_pid}`"
end
task :reload, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} kill -s USR2 `cat #{unicorn_pid}`"
end
task :restart, :roles => :app, :except => { :no_release => true } do
stop
start
end
# task :restart, :roles => :app, :except => { :no_release => true } do
# run "touch #{current_release}/tmp/restart.txt"
# end
task :stub_xml_rpc do
path = File.join(current_path, 'config', 'environment.rb')
path = File.join(release_path, 'config', 'environment.rb')
code = %Q{\nrequire 'stub_xml_rpc'\n}
puts "Stub XML RPC"
run %Q{echo "#{code}" >> #{path}}
end
task :symlink_config_files, :roles => :web do
run "mkdir -p #{deploy_to}/#{shared_dir}/config"
task :symlink_all, :roles => :web do
# run "mkdir -p #{fetch :shared_path}/config"
# Never do this!!!
# run "yes y | cp -i #{fetch :release_path}/config/database.yml.sample #{fetch :shared_path}/config/database.yml"
# run "yes y | cp -i #{fetch :release_path}/config/application.yml.sample #{fetch :shared_path}/config/application.yml"
run "yes y | cp -i #{release_path}/config/database.yml.sample #{deploy_to}/#{shared_dir}/config/database.yml"
run "yes y | cp -i #{release_path}/config/application.yml.sample #{deploy_to}/#{shared_dir}/config/application.yml"
run "ln -nfs #{fetch :shared_path}/config/database.yml #{fetch :release_path}/config/database.yml"
run "ln -nfs #{fetch :shared_path}/config/application.yml #{fetch :release_path}/config/application.yml"
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
run "ln -nfs #{shared_path}/config/application.yml #{release_path}/config/application.yml"
end
run "ln -nfs #{fetch :shared_path}/downloads/ #{fetch :release_path}/public/downloads"
task :symlink_downloads_dir, :roles => :web do
run "ln -nfs #{shared_path}/downloads/ #{release_path}/public/downloads"
end
task :symlink_tmp_dir, :roles => :web do
run "ln -nfs #{shared_path}/tmp/ #{release_path}/tmp"
run "mkdir -p #{release_path}/tmp/mount"
run "mkdir -p #{release_path}/tmp/umount"
run "ln -nfs #{fetch :shared_path}/tmp/ #{fetch :release_path}/tmp"
run "mkdir -p #{fetch :release_path}/tmp/mount"
run "mkdir -p #{fetch :release_path}/tmp/umount"
end
end
after "deploy:update_code", "deploy:symlink_config_files", "deploy:symlink_downloads_dir", "deploy:symlink_tmp_dir", "deploy:migrate"
after "deploy:update_code", "deploy:symlink_all", "deploy:migrate"
after "deploy:restart", "delayed_job:restart", "deploy:cleanup"
require 'cape'
namespace :rake_tasks do
Cape do
# mirror_rake_tasks
mirror_rake_tasks 'db:seeds'
end
end

View File

@ -7,10 +7,10 @@ working_directory File.expand_path(File.join(File.dirname(__FILE__), "..")) # a
# listen '/tmp/rosa_build.sock', :backlog => 2048
# listen "/tmp/.sock", :backlog => 64
listen 8080, :tcp_nopush => true
# listen 8080, :tcp_nopush => true
# nuke workers after 30 seconds instead of 60 seconds (the default)
timeout 1200
timeout 600
# feel free to point this anywhere accessible on the filesystem
pid File.expand_path(File.join(File.dirname(__FILE__), "..")) + '/tmp/pids/unicorn.pid'

View File

@ -2,11 +2,10 @@ Capistrano::Configuration.instance(:must_exist).load do
namespace :deploy do
namespace :nginx do
set :nginx_init_path, "/etc/init.d/nginx"
set(:nginx_config_path) { "/etc/nginx/conf.d/#{fetch :application}.conf" }
desc "Generate Nginx configuration"
task :generate_configuration, :roles => :web, :except => { :no_release => true } do
cur_path = File.join(deploy_to, current_dir)
nginx_config_path = "/etc/nginx/conf.d/#{application}.conf"
config = %Q{
upstream #{application}_backend {
server 127.0.0.1:#{unicorn_port};
@ -15,7 +14,7 @@ upstream #{application}_backend {
server {
listen 80;
server_name #{domain};
root #{cur_path}/public;
root #{fetch :current_path}/public;
location /downloads {
autoindex on;
@ -32,19 +31,19 @@ server {
proxy_redirect off;
}
access_log #{shared_path}/log/nginx.access.log;
error_log #{shared_path}/log/nginx.error.log;
access_log #{fetch :shared_path}/log/nginx.access.log;
error_log #{fetch :shared_path}/log/nginx.error.log;
error_page 500 502 503 504 /500.html;
location = /500.html {
root #{cur_path}/public;
root #{fetch :current_path}/public;
}
}
}
# puts config
puts "Write nginx config to #{nginx_config_path}"
puts "Write nginx config to #{fetch :nginx_config_path}"
put config, '/tmp/nginx.conf'
sudo "mv /tmp/nginx.conf #{nginx_config_path}"
sudo "mv /tmp/nginx.conf #{fetch :nginx_config_path}"
end
desc "Start nginx web server"

26
lib/recipes/unicorn.rb Normal file
View File

@ -0,0 +1,26 @@
Capistrano::Configuration.instance(:must_exist).load do
namespace :deploy do
set :unicorn_binary, "bundle exec unicorn"
set(:unicorn_config) { "#{fetch :current_path}/config/unicorn.rb" }
set(:unicorn_pid) { "#{fetch :shared_path}/tmp/pids/unicorn.pid" }
set :unicorn_port, 8080
task :start, :roles => :app, :except => { :no_release => true } do
run "cd #{fetch :current_path} && #{try_sudo} #{unicorn_binary} -c #{unicorn_config} -p #{unicorn_port} -E #{rails_env} -D"
end
task :stop, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} kill `cat #{unicorn_pid}`"
end
task :graceful_stop, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} kill -s QUIT `cat #{unicorn_pid}`"
end
task :reload, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} kill -s USR2 `cat #{unicorn_pid}`"
end
task :restart, :roles => :app, :except => { :no_release => true } do
reload
# stop
# start
end
end
end