Created
November 1, 2008 19:37
-
-
Save nofxx/21559 to your computer and use it in GitHub Desktop.
Cap Recipe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # | |
# CAPISTRANO 2.5.0 DEPLOY | |
# GIT, Passenger, BackgrounDRB, Juggernaut | |
# | |
# Workflow: | |
# cap <stage> <task> | |
# cap <stage> deploy:setup | |
# cap <stage> deploy:cold | |
# . . . | |
# cap <stage> deploy | |
# | |
# Config files: | |
# Copy config/.*ex files do shared/production.<file> on setup. | |
# Copy from shared on deploy. | |
# | |
set :application, "APPNAME" | |
set :stages, %w{ role1 role2 } | |
set :default_stage, 'role1' | |
# # # | |
# ROLES | |
# | |
task :role1 do | |
ssh_options[:port] = 22223 | |
# set :domain, "some.foo.com" | |
role :app, "foo.foo.com" | |
role :web, "foo.foo.com" | |
role :db, "foo.foo.com", :primary => true | |
end | |
task :role2 do | |
ssh_options[:port] = 22222 | |
role :app, "gw.foo.com.br" | |
role :web, "gw.foo.com.br" | |
role :db, "gw.foo.com.br", :primary => true | |
end | |
# # | |
# GIT | |
# | |
set :user, "deployer" | |
set :scm, :git | |
set :repository, "ssh://git@REPO/PATH.git" | |
set :branch, "master" | |
set :deploy_via, :remote_cache | |
set :keep_releases, 7 | |
# # | |
# SSH | |
# | |
ssh_options[:paranoid] = false | |
#ssh_options[:port] = 0000 | |
default_run_options[:pty] = true | |
set :use_sudo, false | |
# # | |
# DEPLOY TO | |
set :deploy_to, "/var/www/apps/#{application}" | |
# # | |
# GEMS | |
set :packages, ["postgres", "hpricot"] | |
# # | |
# TASKS | |
# | |
desc "Load fixtures" | |
task :fixtures do | |
rake = fetch(:rake, 'rake') | |
rails_env = fetch(:rails_env, 'production') | |
run "cd #{current_path}; #{rake} RAILS_ENV=#{rails_env} db:fixtures:load" | |
end | |
after "migrate", "fixtures" | |
# # | |
# BackgroundDrb | |
# | |
namespace :backgroundrb do | |
desc "Start the backgroundrb server" | |
task :start , :roles => :app do | |
run "cd #{current_path} && nohup ./script/backgroundrb start -e production > #{current_path}/log/backgroundrb-cap.log 2>&1" | |
end | |
desc "Stop the backgroundrb server" | |
task :stop, :roles => :app do | |
run "cd #{release_path} && ./script/backgroundrb stop" | |
end | |
desc "Restart the backgroundrb server" | |
task :restart, :roles => :app do | |
stop | |
start | |
end | |
end | |
# # | |
# Juggernaut | |
# | |
namespace :juggernaut do | |
desc "Stop the juggernaut push server" | |
task :stop , :roles => :app do | |
run "cd #{current_path} && rake juggernaut:stop RAILS_ENV=production" | |
end | |
desc "Start the juggernaut push server" | |
task :start, :roles => :app do | |
run "cd #{current_path} && rake juggernaut:start RAILS_ENV=production" | |
end | |
desc "Restart the juggernaut push server" | |
task :restart, :roles => :app do | |
run "cd #{current_path} && rake juggernaut:restart RAILS_ENV=production" | |
end | |
end | |
# # | |
# DEPLOY | |
# | |
namespace :deploy do | |
# não usar sudo no cleanup | |
before("deploy:cleanup") do | |
set :use_sudo, false | |
end | |
# Advanced Rails Recipes | |
desc "Roda depois de uma cada implantação bem sucedida" | |
task :after_default do | |
#backgroundrb::restart | |
#juggernaut::restart | |
cleanup | |
end | |
desc "Copiar config database" | |
task :copy_database_configuration do | |
db_config = "#{shared_path}/production.database.yml" | |
run "cp #{db_config} #{release_path}/config/database.yml" | |
end | |
after "deploy:update_code", "deploy:copy_database_configuration" | |
desc "Copiar config juggernaut" | |
task :copy_juggernaut_configuration do | |
jugger_config = "#{shared_path}/production.juggernaut_hosts.yml" | |
run "cp #{jugger_config} #{release_path}/config/juggernaut_hosts.yml" | |
end | |
after "deploy:update_code", "deploy:copy_juggernaut_configuration" | |
task :start, :roles => :app do | |
backgroundrb::start | |
juggernaut::start | |
end | |
task :stop, :roles => :app do | |
backgroundrb::stop | |
juggernaut::stop | |
end | |
task :restart, :roles => :app do | |
backgroundrb::restart | |
juggernaut::restart | |
run "touch #{release_path}/tmp/restart.txt" | |
end | |
task :after_setup do | |
run "mkdir #{shared_path}/files" | |
run "cp #{release_path}/config/database.yml.ex #{shared_path}/production.database.yml" | |
run "cp #{release_path}/config/juggernaut_hosts.yml.ex #{shared_path}/production.juggernaut_hosts.yml" | |
end | |
desc "Criar symlinks diretorios compartilhados" | |
task :after_symlink do | |
run "rm -rf #{release_path}/public/files" | |
run "ln -nfs #{shared_path}/files #{release_path}/public/files" | |
end | |
task :after_update_code, :roles => :app do | |
run "rm -rf #{release_path}/public/.htaccess" | |
end | |
end | |
# # | |
# TAIL | |
desc "Analisar multiplos arquivos de log ao mesmo tempo" | |
task :tail_log, :roles => :app do | |
stream "tail -f #{shared_path}/log/production.log #{shared_path}/log/apache-error.log #{shared_path}/log/apache-access.log" | |
end | |
desc "Tail Daemons" | |
task :tail_daemon, :roles => :app do | |
stream "tail -f #{shared_path}/log/backgroundrb-cap.log #{shared_path}/log/juggernaut.log" | |
# stream "tail -f #{shared_path}/log/backgroundrb-server.log" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment