Why a Fly.io Machine keeps restarting, and how to hear about it
A Fly.io Machine keeps restarting because its main process exits and the restart policy starts it again. Machines from fly launch or fly deploy use the on-failure policy. It retries up to 10 times in five minutes, then leaves the Machine stopped. fly machine status lists the Machine’s recent events with their exit codes. For the general picture, see why a container keeps restarting.
Confirm it
fly machine list
fly machine status <machine-id>
fly logs --machine <machine-id>The status shows each exit with its code. An out-of-memory kill also shows as Out of memory: Killed process in the logs; see OOM killed on Fly.io.
Fly.io restart policies
- on-failure restarts after a non-zero exit, up to 10 times by default. It is the default for Machines from
fly launchandfly deploy. - always restarts after any exit, including a clean one.
- never leaves a stopped Machine stopped.
Set the policy and the number of retries in fly.toml under [[restart]], with policy and retries. The CLI spells the same policies on-fail, always and no in fly machine update --restart.
How to fix it
- Out of memory: give the Machine more memory with
fly scale memory 1024. - A crash on boot: check the secrets with
fly secrets list, and the start command in the Dockerfile orfly.toml. - A process that finishes: keep the server in the foreground, or use the never policy for a task.
What Fly.io tells you
Apart from an email when a Machine runs out of memory, Fly.io sends nothing when a Machine restarts, or when it stops after its last retry. The metrics in Fly.io’s managed Grafana have no alerts until you build them, and restart events live per Machine, in the CLI or the Machines API.