Running Tasks & Consoles

Running one-off tasks on Fly can be accomplished via fly ssh console.

Rails Tasks

To execture the rails command on Fly, run:

fly ssh console -C "app/bin/rails db:migrate"

To list all the available tasks, run:

fly ssh console -C "app/bin/rails help"

Rails Console

To access an interactive Rails console, run:

fly ssh console -C "app/bin/rails console"

Then start using the console, but be careful! You're in a production environment.

Interactive Shell

To access an interactive shell, simply run:

fly ssh console

Custom Rake Tasks

You can create Custom Rake Tasks to automate frequently used commands. As an example, add the following into lib/tasks/fly.rake to reduce the number of keystrokes it takes to launch a console:

namespace :fly do
  task :ssh do
    sh 'fly ssh console'

  task :console do
    sh 'fly ssh console -C "app/bin/rails console"'

  task :dbconsole do
    sh 'fly ssh console -C "app/bin/rails dbconsole"'

You can run these tasks with bin/rails fly:ssh, bin/rails fly:console, and bin/rails fly:dbconsole respectively.