Skip to content

Commit cda45c4

Browse files
authored
Add machine restart policy doc (#1043)
* add machine restart policy doc * minor edits
1 parent cfafe90 commit cda45c4

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
title: Machine restart policy
3+
layout: framework_docs
4+
sitemap: false
5+
order: 35
6+
nav: firecracker
7+
---
8+
9+
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.
10+
11+
The restart policies are:
12+
13+
- **`no`**: Never try to restart a Machine automatically when its main process exits, whether that’s on purpose or on a crash.
14+
15+
- **`always`**: Always restart a Machine automatically and never let it enter a `stopped` state, even when the main process exits cleanly. `always` is the default when you create a Machine with `fly m run` and for Fly Postgres app Machines. Recommended for "always-on" apps with no services configured, since the Machine restarts regardless of the exit code.
16+
17+
- **`on-fail`**: Try up to 10 times 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 request. `on-fail` lets Machines be restarted if they crash, and allows your app Machines to effectively scale down by exiting cleanly. `on-fail` is the default when there's no explicit restart policy in a Machine's config, such as Machines created by `fly launch` and `fly deploy`. Machines with a schedule also default to the `on-fail` restart policy.
18+
19+
## Check a Machine's restart policy
20+
21+
Display a Machine's status and its config in `json` format:
22+
23+
```cmd
24+
fly m status -d <machine id>
25+
```
26+
27+
Example output with a restart policy of `always`:
28+
29+
```out
30+
...
31+
Config:
32+
{
33+
"init": {},
34+
"image": "registry-1.docker.io/flyio/hellofly:latest",
35+
"restart": {
36+
"policy": "always"
37+
},
38+
"guest": {
39+
"cpu_kind": "shared",
40+
"cpus": 1,
41+
"memory_mb": 256
42+
},
43+
"dns": {}
44+
}
45+
```
46+
47+
## Change a Machine's restart policy with flyctl
48+
49+
Update the Machine config:
50+
51+
```cmd
52+
fly m update <machine id> --restart <no | always | on-fail>
53+
```
54+
55+
The following example updates a Machine's restart policy to `on-fail`:
56+
57+
```cmd
58+
fly m update 3908032c794088 --restart on-fail
59+
```
60+
```out
61+
Configuration changes to be applied to machine: 3908032c794088 (my-app-name)
62+
63+
   ... // 2 identical lines
64+
   "image": "registry-1.docker.io/flyio/hellofly:latest",
65+
   "restart": {
66+
-  "policy": "always"
67+
+  "policy": "on-failure"
68+
   },
69+
   "guest": {
70+
   ... // 6 identical lines
71+
72+
? Apply changes? (y/N)
73+
```
74+
75+
Enter 'y' to apply the changes.
76+
77+
## Change a Machine's restart policy with the Machines API
78+
79+
With the Machines API, you can set the restart policy, and the maximum number of retries when the policy is `on-fail`.
80+
81+
Endpoint: `POST /apps/{app_name}/machines/{machine_id}`
82+
83+
For example:
84+
```
85+
...
86+
"restart": {
87+
"max_retries": 5,
88+
"policy": "on-failure"
89+
},
90+
...
91+
```
92+
93+
Refer to the Machines API docs for more information about [Machine update](https://docs.machines.dev/swagger/index.html#/Machines/Machines_update).

partials/_firecracker_nav.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@
130130
<li>
131131
<%= nav_link "Machine Sizing", "/docs/machines/guides-examples/machine-sizing/" %>
132132
</li>
133+
<li>
134+
<%= nav_link "Machine restart policy", "/docs/machines/guides-examples/machine-restart-policy/" %>
135+
</li>
133136
<li>
134137
<%= nav_link "Run User Code on Fly Machines", "/docs/machines/guides-examples/functions-with-machines/" %>
135138
</li>

0 commit comments

Comments
 (0)