Remote Rails Commands with Recap-Console

Run rails (db)console commands with Recap.

Recap is a reinterpretation of the capistrano deployment and multi-server management gem.

The Setup

In your Capfile, require the library.

# Capfile
require 'recap/tasks/rails/console'

The Payoff

The remote consoles will run on the first available server with the app role.

Rails commands

To run the remote equivalent of rails console, run the following.

$ cap rails:console

To run the remote equivalent of rails dbconsole, run the following.

$ cap rails:dbconsole

SSH

In addition to rails commands, you can open a vanilla ssh console.

$ cap ssh:console

Finally, to run an arbitrary shell command, pass the command in via the RUN variable. Note that the current directory is your recap project directory.

$ cap ssh:command RUN="tail -f log/production.log"

Additional Reading

  • View the source code on GitHub
  • Capistrano version 3 now uses git for server-side deployment file resolution.