-
-
Save existentialmutt/c904d6e55cd09dda81ea9751d2e66e6d to your computer and use it in GitHub Desktop.
Capistrano 3 rails console tasks and log tailing tasks
This file contains hidden or 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
# Place in lib/capistrano/tasks/rails.cap and require it in your Capfile | |
# See: https://gist.github.com/existentialmutt/c904d6e55cd09dda81ea9751d2e66e6d | |
# Adapted to work with RVM installed to /usr/local | |
namespace :rails do | |
desc "tail rails logs" | |
task :tail_logs do | |
on roles(:app) do | |
execute "tail -f #{shared_path}/log/#{fetch(:rails_env)}.log" | |
end | |
end | |
desc "Open the rails console on primary app server" | |
task :console do | |
on roles(:app), primary: true do | |
rails_env = fetch(:stage) | |
execute_interactively "bin/rails console #{rails_env}" | |
end | |
end | |
desc "Open the rails dbconsole on primary db server" | |
task :dbconsole do | |
on roles(:db), primary: true do | |
rails_env = fetch(:stage) | |
execute_interactively "#{current_path}/bin/rails dbconsole #{rails_env}" | |
end | |
end | |
def execute_interactively(command) | |
user = fetch(:user) | |
port = fetch(:port) || 22 | |
cmd = "ssh" | |
if user | |
cmd << " -l #{user}" | |
end | |
cmd << " #{host} -p #{port} -t 'cd #{fetch(:deploy_to)}/current && /usr/local/rvm/bin/rvm `cat .ruby-version` do #{bundle_cmd} #{command}'" | |
info "Connecting to #{host} with command" | |
info cmd | |
exec cmd | |
end | |
def bundle_cmd | |
"bundle exec" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment