capistrano3 - Capistrano 3: Run task only on a single server from a pool of servers assigned a role -
i have 20 servers in "web" role. have task need perform on 1 of them change affects shared storage. current solution hack around (below). looking better way, don't have ton of ruby or cap experience.
task :checkout_project_properties num_runs = 0 on roles(:web), in: :sequence if num_runs > 0 abort('only running on 1 server. exiting') end execute("checkout-project-properties #{uc_stage} #{repo} #{branch}") num_runs += 1 end end
i assume referring production configuration, many web servers. in case, config/deploy/production.rb contains many lines this:
server 'web_1', roles: %w(web) server 'web_2', roles: %w(web) server 'web_3', roles: %w(web) ... simply make 1 of these servers primary, looks like:
server 'web_1', roles: %w(web), primary: true server 'web_2', roles: %w(web) server 'web_3', roles: %w(web) ... then change task looks this:
task :checkout_project_properties on primary(:web) execute("checkout-project-properties #{uc_stage} #{repo} #{branch}") end end
Comments
Post a Comment