How do you deploy with capistrano?

We have 2 instances behind the load balancer, which work with the same rail application with the passenger. When we deploy, the server startup time raises timeout requests. As a result, we have a script that updates each web server separately, removing one from the LB, deploying with a cap, testing the dynamic loading of the page, returning it to LB.

How can we get capistrano for this for us with one team? I was able to configure it to deploy to all instances at the same time, but all of them restart at the same time and cause the site to be unavailable for 20 seconds.

What am I missing here? It seems like this should be a common model.

+5
source share
1 answer

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
  # does what your existing deploy:create_symlink did, something like:
  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.

0

All Articles