Last active
December 25, 2015 13:09
-
-
Save meltingice/6981448 to your computer and use it in GitHub Desktop.
Capistrano recipes for SSHing into multiple servers simultaneously using csshX. Ensures csshX is installed if you're using homebrew on OSX. Add this or load it into your deploy.rb and profit.
This file contains hidden or 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
namespace :csshx do | |
task :install do | |
`which csshx` | |
if $? != 0 | |
Bundler.with_clean_env do | |
run_locally 'brew install csshx' | |
end | |
end | |
end | |
desc "SSH into all app servers" | |
task :app_servers, roles: :app do | |
invoke_csshx | |
end | |
desc "SSH into all worker servers" | |
task :worker_servers, roles: :worker do | |
invoke_csshx | |
end | |
end | |
def invoke_csshx | |
csshx.install | |
servers = find_servers_for_task(current_task).map { |s| "#{user}@#{s.host}" }.join(' ') | |
run_locally "csshx #{servers}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This also works with multistage environments since the servers are determined via your Capistrano config, e.g.: