Actually, it’s not so easy to serialize a deployment in capistrano, which likes to parallelize all its operations between servers. To repeat this problem, it seems that you have several servers and you want each of them to be standalone in order to upgrade your deployment.
The trick is to redefine the task deploy:create_symlinkin the deployment configuration:
def perform_task_offline options
sudo "take_this_server_offline", options
yield
sudo "put_this_server_online", options
end
def create_symlink_task options
run "rm -f /web/current && ln -s #{release_path} /web/current", options
end
namespace :deploy do
task :create_symlink, {once: true, except: {no_release: true}} do
deployed_servers = Array.new
roles[:app].servers.each do |current_server|
options = {hosts: current_server}
deployed_servers.push current_server
perform_task_offline(options) { create_symlink_task options }
end
end
end
In this case, perform_task_offlineincludes commands executed on the server specified in optionswhich remove it from the load balancer, while the yieldblock includes create_symlink_task, which creates a symbolic deployment link.
cap , , , "" , .
, , deployed_servers. ( , ) , , on_rollback do, deployed_servers.