Created
February 9, 2013 04:44
-
-
Save scomma/4743870 to your computer and use it in GitHub Desktop.
Run an interactive console session on a production machine with Capistrano.
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
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