rembrembdocs

The Machine restart policy defines whether and how flyd restarts a Machine after its main process exits. The restart policy applies per Machine, and is not an app-wide setting.

The restart policies are:

Check a Machine’s restart policy

Display a Machine’s status and its config in json format:

fly m status -d <machine id> 

Example output with a restart policy of always:

...
Config:
{
  "init": {},
  "image": "registry-1.docker.io/flyio/hellofly:latest",
  "restart": {
    "policy": "always"
  },
  "guest": {
    "cpu_kind": "shared",
    "cpus": 1,
    "memory_mb": 256
  },
  "dns": {}
}

Change a Machine’s restart policy with flyctl

Update the Machine config:

fly m update <machine id> --restart <no | always | on-fail>

The following example updates a Machine’s restart policy to on-fail:

fly m update 3908032c794088 --restart on-fail
Configuration changes to be applied to machine: 3908032c794088 (my-app-name)

      ... // 2 identical lines
        "image": "registry-1.docker.io/flyio/hellofly:latest",
        "restart": {
-      "policy": "always"
+      "policy": "on-failure"
        },
        "guest": {
      ... // 6 identical lines

? Apply changes? (y/N)

Enter 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 is on-failure.

Important: The API and the returned Machine config use on-failure instead of on-fail.

Endpoint: POST /apps/{app_name}/machines/{machine_id}

For example:

...
    "restart": {
      "max_retries": 5,
      "policy": "on-failure"
    },
...

Refer to the Machines API docs for more information about updating a Machine.

Set a restart policy in your Fly.toml

You can also set a default app-level restart policy in your Fly.toml file:

[[restart]]
  policy = "<never | always | on-failure>"
  retries = 10
  processes = ["app"]

A restart policy can be targeted to a specific process group. If a group is not specified, all machines in an app will have the same default restart policy. If needed, you can still apply different policies on individual machines using the Flyctl or Machines API methods above.