-
no: Never try to restart a Machine automatically when its main process exits, whether that’s on purpose or on a crash.nois the default when you use the--rmoption to create a Machine withfly m runthat auto-destroys on exit. -
always: Always restart a Machine automatically and never let it enter astoppedstate, even when the main process exits cleanly.alwaysis the default when you create a Machine withfly m runand for Fly Postgres app Machines. Recommended for “always-on” apps with no services configured, since the Machine restarts regardless of the exit code. -
on-fail(oron-failurefor the Machines API and when viewed in the Machine config): Try up tomax_retries(default 10) times within a 5-minute window to automatically restart the Machine if it exits with a non-zero exit code, before letting it stop. Recommended for most Machines with services configured, since Fly Proxy can wake them on request.on-faillets Machines be restarted if they crash, and allows your app Machines to effectively scale down by exiting cleanly.on-failis the default when there’s no explicit restart policy in a Machine’s config, such as Machines created byfly launchandfly deploy. Machines with a schedule also default to theon-failrestart policy.
Check a Machine’s restart policy
Display a Machine’s status and its config injson format:
always:
Change a Machine’s restart policy with flyctl
Update the Machine config:on-fail:
y to apply the changes.
Change a Machine’s restart policy with the Machines API
With the Machines API, you can set the restart policy, and the maximum number of retries when the policy ison-failure.
Important: The API and the returned Machine config use
on-failure instead of on-fail.POST /apps/{app_name}/machines/{machine_id}
For example: