Skip to content

Instantly share code, notes, and snippets.

@jurikern
Created March 20, 2015 08:47
Show Gist options
  • Save jurikern/252dda5a109800393fd3 to your computer and use it in GitHub Desktop.
Save jurikern/252dda5a109800393fd3 to your computer and use it in GitHub Desktop.
capistrano_console.rb
namespace :rails do
desc "Open the rails console on the remote app server"
task :console => 'rvm:hook' do
on roles(:app), :primary => true do |host|
execute_interactively host, "console #{fetch(:stage)}"
end
end
desc "Open the rails dbconsole on each of the remote servers"
task :dbconsole => 'rvm:hook' do
on roles(:app), :primary => true do |host|
execute_interactively host, "dbconsole #{fetch(:stage)}"
end
end
def execute_interactively(host, command)
command = "cd #{fetch(:deploy_to)}/current && #{SSHKit.config.command_map[:bundle]} exec rails #{command}"
puts command if fetch(:log_level) == :debug
exec "ssh -l #{host.user} #{host.hostname} -p #{host.port || 22} -t '#{command}'"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment