Capistrano 3.11 Tips

Tail Production Log

Add a custom Capistrano rake task to lib/capistrano/tasks/tail.rake.

namespace :logs do
  desc "tail rails logs. Usage cap production logs:tail_rails"
  task :tail_rails do
    on roles(:app) do
      execute "tail -f #{shared_path}/log/#{fetch(:rails_env)}.log"
    end
  end
end

You can now tail the production log from your local machine:

cap production logs:tail_rails

Run Commands on Server

Add :

require 'capistrano/console'

to Capfile

Now you can run:

bundle exec cap production console

to run commands on the server terminal. Useful to run commands like: uptime.

Play with Rails Production Console

Add:

gem 'capistrano-rails-console', require: false

to Gemfile and run bundle.

Add:

require 'capistrano/rails/console'

to Capfile.

Run:

cap production rails:console

to play in production rails console.

Run Migration on Deploy

Make sure you have the db role in the config/deploy/production.rb file as follows:

server 'ip-address-goes-here', user: 'deploy-user', roles: %w{app web db}


Related Articles


Create your own user feedback survey