Created
March 27, 2015 10:51
-
-
Save olegykz/30f2461a697ae736b352 to your computer and use it in GitHub Desktop.
Capistrano 3 useful tasks to open ssh session and rails console
This file contains 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 :rails do | |
desc 'Open a rails console `cap [staging] rails:console [server_index default: 0]`' | |
task :console do | |
on roles(:app) do |server| | |
return if server != roles(:app)[ARGV[2].to_i] | |
puts "Opening a console on: #{host}...." | |
cmd = "ssh #{fetch(:ssh_options)[:user]}@#{host} -t 'source \"$HOME/.rvm/scripts/rvm\""\ | |
" && cd #{fetch(:deploy_to)}/current && RAILS_ENV=#{fetch(:rails_env)} bundle exec rails console'" | |
exec cmd | |
end | |
end | |
end | |
# Bonus | |
desc 'Open ssh `cap [staging] ssh [server_index default: 0]`' | |
task :ssh do | |
on roles(:app) do |server| | |
return if server != roles(:app)[ARGV[2].to_i] | |
puts "Opening ssh session on: #{host}...." | |
cmd = "ssh #{fetch(:ssh_options)[:user]}@#{host}" | |
exec cmd | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment