Last active
December 27, 2015 00:19
-
-
Save bencates/7236801 to your computer and use it in GitHub Desktop.
Capistrano 3 rails console commands
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
class TTYBackend < SSHKit::Backend::Printer | |
def execute(*args) | |
options = args.last.is_a?(Hash) ? args.pop : {} | |
command(*args).tap do |cmd| | |
output << cmd | |
cmd.started = Time.now | |
system %Q{ssh -l #{@host.user} #{@host.hostname} -t "#{cmd.to_command}"} | |
cmd.exit_status = options[:ignore_exit_status] ? 0 : $?.to_i | |
output << cmd | |
end | |
end | |
end | |
module SSHKit | |
module DSL | |
def run_interactively_on(host, &block) | |
TTYBackend.new(host, &block).run | |
end | |
end | |
end | |
namespace :rails do | |
task :console => 'deploy:set_rails_env' do | |
run_interactively_on primary(:app) do | |
within release_path do | |
execute :bundle, :exec, :rails, :console, fetch(:rails_env) | |
end | |
end | |
end | |
task :c => :console | |
task :dbconsole => 'deploy:set_rails_env' do | |
run_interactively_on primary(:app) do | |
within release_path do | |
execute :bundle, :exec, :rails, :dbconsole, fetch(:rails_env), '--include-password' | |
end | |
end | |
end | |
task :db => :dbconsole | |
desc "Tail the logs" | |
task :log => 'deploy:set_rails_env' do | |
run_interactively_on primary(:app) do | |
execute :tail, '-f', "#{shared_path}/log/#{fetch(:rails_env)}.log", | |
ignore_exit_status: true | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment