-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add machine restart policy doc #1043
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
machines/guides-examples/machine-restart-policy.html.markerb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
--- | ||
title: Machine restart policy | ||
layout: framework_docs | ||
sitemap: false | ||
order: 35 | ||
nav: firecracker | ||
--- | ||
|
||
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: | ||
|
||
- **`no`**: Never try to restart a Machine automatically when its main process exits, whether that’s on purpose or on a crash. | ||
|
||
- **`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. | ||
|
||
- **`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. | ||
|
||
## Check a Machine's restart policy | ||
|
||
Display a Machine's status and its config in `json` format: | ||
|
||
```cmd | ||
fly m status -d <machine id> | ||
``` | ||
|
||
Example output with a restart policy of `always`: | ||
|
||
```out | ||
... | ||
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: | ||
|
||
```cmd | ||
fly m update <machine id> --restart <no | always | on-fail> | ||
``` | ||
|
||
The following example updates a Machine's restart policy to `on-fail`: | ||
|
||
```cmd | ||
fly m update 3908032c794088 --restart on-fail | ||
``` | ||
```out | ||
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-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 [Machine update](https://docs.machines.dev/swagger/index.html#/Machines/Machines_update). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
on-fail
an alias foron-failure
. Might be better if the API and flyctl match?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on-failure
mimics Docker's naming which was the goal, if the CLI is using something different, we should change it.