Skip to content

Instantly share code, notes, and snippets.

@meltingice
Last active December 25, 2015 13:09
Show Gist options
  • Save meltingice/6981448 to your computer and use it in GitHub Desktop.
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.
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
@meltingice
Copy link
Author

This also works with multistage environments since the servers are determined via your Capistrano config, e.g.:

cap production csshx:app_servers
cap staging csshx:worker_servers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment