Skip to content

Instantly share code, notes, and snippets.

@MichaelCPell
Created July 21, 2014 20:08
Show Gist options
  • Save MichaelCPell/8efe6dd14fcfa735c6c3 to your computer and use it in GitHub Desktop.
Save MichaelCPell/8efe6dd14fcfa735c6c3 to your computer and use it in GitHub Desktop.
Console recipe for Cap 2
desc "Remote console"
task :console, :roles => :app do
server = find_servers(:roles => [:app]).first
run_with_tty server, %W( ./script/rails console #{rails_env} )
end
desc "Remote dbconsole"
task :dbconsole, :roles => :app do
env = "production"
server = find_servers(:roles => [:app]).first
run_with_tty server, %W( ./script/rails dbconsole #{env} )
end
desc "tailf logs"
task :logs, :roles => :app do
server = find_servers(:roles => [:app]).first
run_with_tty server, "tailf #{current_path}/log/#{rails_env}.log"
end
def run_with_tty(server, cmd)
# looks like total pizdets
command = []
command += %W( ssh -t #{gateway} -l #{self[:gateway_user] || self[:user]} ) if self[:gateway]
command += %W( ssh -t )
command += %W( -p #{server.port}) if server.port
command += %W( -l #{user} #{server.host} )
command += %W( cd #{current_path} )
# have to escape this once if running via double ssh
command += [self[:gateway] ? '\&\&' : '&&']
command += Array(cmd)
system *command
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment