Skip to content

Instantly share code, notes, and snippets.

@chrisbloom7
Forked from toobulkeh/deploy.rb
Last active June 14, 2016 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chrisbloom7/5de890debc104390d6d4 to your computer and use it in GitHub Desktop.
Save chrisbloom7/5de890debc104390d6d4 to your computer and use it in GitHub Desktop.
Open a Rails console via Capistrano 3 (requires capistrano-rvm gem)
require 'capistrano/rvm'
group :development do
# Use Capistrano for deployment
gem 'capistrano', '~> 3.3'
gem 'capistrano-rvm', '~> 0.1.2', require: false
end
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