Skip to content

Instantly share code, notes, and snippets.

@scomma
Created February 9, 2013 04:44
Show Gist options
  • Save scomma/4743870 to your computer and use it in GitHub Desktop.
Save scomma/4743870 to your computer and use it in GitHub Desktop.
Run an interactive console session on a production machine with Capistrano.
require 'bundler/capistrano'
set :bundle_flags, "--deployment --binstubs"
set :default_environment, 'PATH' => '$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH'
role :web, "your.ip.here"
set :user, "passenger"
namespace :rails do
desc "Remote console"
task :console, roles: :app do
run_interactively "bin/rails console #{rails_env}"
end
desc "Remote dbconsole"
task :dbconsole, roles: :app do
run_interactively "bin/rails dbconsole #{rails_env}"
end
end
def run_interactively(command, server=nil)
server ||= find_servers_for_task(current_task).first
system 'ssh', '-l', user, server.host, '-t', "cd '#{current_path}' && env #{environment} #{command}"
end
def environment
default_environment.map { |k, v| "#{k}=#{v}" }.join(' ')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment