VM for one-off scripts on Rails app

I have a Rails app where people frequently need to run one-off scripts.

We’re currently doing so on the production app on one of the HTTP or Sidekiq machines, whatever gets selected by fly ssh console. This isn’t ideal for many reasons:

  • The DB connection gets killed after a short while
  • The ssh connection might get killed after a while
  • The job might gobble too much memory/cpu and interfere with HTTP traffic or job processing
    etc.

I’m thinking about setting up a VM exclusively for those tasks. The machine will need to access the Rails stuff, so it needs to live within the same production app. Something like:

[processes]
  ...
  remote_job = "tail -f /dev/null"


[[vm]]
  ... 
  processes = ["remote_job"]

Then have a script that scps your Rails script to that specific VM and runs it with bin/rake.

  1. How do people usually handle this situation? Is there a convention?
  2. Is there a cleaner way of specifying a VM with a non-exiting process, or no process at all? I just need the VM to stay alive and not quit after an exit 0.

Mind if I suggest a completely alternate approach?

Try fly console, i.e., without the ssh. But before you do, comment out the console_command if it is present in your fly.toml.

Or, take a look at fly machine run, the primary difference between these two is that the first will direct the output back to you, and the latter will direct output to logs.

What these commands will do is create an entirely new VM that lasts the duration of your console session. Feel free to launch multiple machines simultaneously running separate scripts.

If you want to get really fancy, both commands accept --dockerfile and --image options, so you can run something entirely different on your ephemeral machines.


As to your questions, no I’m not aware of a convention, and tail -f /dev/null works just fine (I prefer sleep infinity, but any command that never returns is fine).

That’s brilliant, thanks! There’s still one thing though: considering I don’t want people to have to copy-paste their script into a console in the new ephemeral machine, I’ll need a way to copy a local script to the new machine created by fly console; perhaps something like the --file-local that exists for fly machine run. Is there anything like that for console? Couldn’t find it in the docs.

Otherwise fly console will be a perfect fit.

Open an issue, assign it to me, and I’ll add it.

1 Like

Thanks! Here’s the issue, don’t think I can assign it though :slight_smile: Copy local files to ephemeral machines via `fly console` · Issue #3282 · superfly/flyctl · GitHub

EDIT just tested this with the new release and it worked flawlessly. Truly appreciate the effort!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.