Skip to content

Commit 5508d87

Browse files
Merge pull request #27619 from Honny1/fix-unless-stopped-reboot
Fix `unless-stopped` restart policy to match Docker behavior
2 parents 0bd2b4b + 4d3c631 commit 5508d87

15 files changed

Lines changed: 145 additions & 6 deletions

File tree

cmd/podman/common/completion.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1808,7 +1808,18 @@ func AutocompletePsFilters(cmd *cobra.Command, _ []string, toComplete string) ([
18081808
"name=": func(s string) ([]string, cobra.ShellCompDirective) { return getContainers(cmd, s, completeNames) },
18091809
"network=": func(s string) ([]string, cobra.ShellCompDirective) { return getNetworks(cmd, s, completeDefault) },
18101810
"pod=": func(s string) ([]string, cobra.ShellCompDirective) { return getPods(cmd, s, completeDefault) },
1811-
"since=": func(s string) ([]string, cobra.ShellCompDirective) { return getContainers(cmd, s, completeDefault) },
1811+
"restart-policy=": func(_ string) ([]string, cobra.ShellCompDirective) {
1812+
return []string{
1813+
define.RestartPolicyAlways,
1814+
define.RestartPolicyNo,
1815+
define.RestartPolicyOnFailure,
1816+
define.RestartPolicyUnlessStopped,
1817+
}, cobra.ShellCompDirectiveNoFileComp
1818+
},
1819+
"should-start-on-boot=": func(_ string) ([]string, cobra.ShellCompDirective) {
1820+
return []string{"true", "false"}, cobra.ShellCompDirectiveNoFileComp
1821+
},
1822+
"since=": func(s string) ([]string, cobra.ShellCompDirective) { return getContainers(cmd, s, completeDefault) },
18121823
"status=": func(_ string) ([]string, cobra.ShellCompDirective) {
18131824
return containerStatuses, cobra.ShellCompDirectiveNoFileComp
18141825
},

contrib/systemd/system/podman-restart.service.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ After=network-online.target
99
Type=oneshot
1010
RemainAfterExit=true
1111
Environment=LOGGING="--log-level=info"
12-
ExecStart=@@PODMAN@@ $LOGGING start --all --filter restart-policy=always
13-
ExecStop=@@PODMAN@@ $LOGGING stop --all --filter restart-policy=always
12+
ExecStart=@@PODMAN@@ $LOGGING start --all --filter should-start-on-boot=true
13+
ExecStop=@@PODMAN@@ $LOGGING stop --all --filter should-start-on-boot=true
1414

1515
[Install]
1616
WantedBy=default.target

docs/source/markdown/options/restart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Valid _policy_ values are:
1313
- `never` : Synonym for **no**; do not restart containers on exit
1414
- `on-failure[:max_retries]` : Restart containers when they exit with a non-zero exit code, retrying indefinitely or until the optional *max_retries* count is hit
1515
- `always` : Restart containers when they exit, regardless of status, retrying indefinitely
16-
- `unless-stopped` : Identical to **always**
16+
- `unless-stopped` : Restart containers when they exit, unless the container was explicitly stopped by the user. After a system reboot, containers with this policy will be restarted by podman-restart.service only if they were not explicitly stopped by the user before the reboot. This differs from **always**, which restarts containers after a system reboot regardless of whether they were user-stopped
1717

1818
Podman provides a systemd unit file, podman-restart.service, which restarts containers after a system reboot.
1919

docs/source/markdown/podman-pause.1.md.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Valid filters are listed below:
3333
| id | [ID] Container's ID (CID prefix match by default; accepts regex) |
3434
| name | [Name] Container's name (accepts regex) |
3535
| label | [Key] or [Key=Value] Label assigned to a container |
36+
| label! | [Key] or [Key=Value] Label NOT assigned to a container |
3637
| exited | [Int] Container's exit code |
3738
| status | [Status] Container's status: 'created', 'initialized', 'exited', 'paused', 'running', 'unknown' |
3839
| ancestor | [ImageName] Image or descendant used to create container |
@@ -42,8 +43,10 @@ Valid filters are listed below:
4243
| health | [Status] healthy or unhealthy |
4344
| pod | [Pod] name or full or partial ID of pod |
4445
| network | [Network] name or full ID of network |
46+
| restart-policy | [Policy] Container's restart policy (e.g., 'no', 'on-failure', 'always', 'unless-stopped') |
4547
| until | [DateTime] Containers created before the given duration or time. |
4648
| command | [Command] the command the container is executing, only argv[0] is taken |
49+
| should-start-on-boot | [Bool] Containers that need to be restarted after system reboot. True for containers with restart policy 'always', or 'unless-stopped' that were not explicitly stopped by the user |
4750

4851
@@option latest
4952

docs/source/markdown/podman-ps.1.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ Valid filters are listed below:
6262
| network | [Network] name or full ID of network |
6363
| until | [DateTime] container created before the given duration or time. |
6464
| command | [Command] the command the container is executing, only argv[0] is taken |
65+
| restart-policy | [Policy] Container's restart policy (e.g., 'no', 'on-failure', 'always', 'unless-stopped') |
66+
| should-start-on-boot | [Bool] Containers that need to be restarted after system reboot. True for containers with restart policy 'always', or 'unless-stopped' that were not explicitly stopped by the user |
6567

6668
#### **--format**=*format*
6769

@@ -288,6 +290,14 @@ CONTAINER ID IMAGE COMMAND CREATED STATUS
288290
5e3694604817 quay.io/centos/centos:latest sleep 300 3 minutes ago Up 3 minutes centos-test
289291
```
290292

293+
Filter containers that need to be restarted after system reboot.
294+
```
295+
$ podman ps -a --filter should-start-on-boot=true
296+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
297+
ff660efda598 docker.io/library/nginx:latest nginx -g daemon o... 3 minutes ago Up 3 minutes 0.0.0.0:8080->80/tcp webserver
298+
5693e934f4c6 docker.io/library/redis:latest redis-server 3 minutes ago Exited (0) 3 minutes ago 6379/tcp cache
299+
```
300+
291301
Use custom format to show container and pod information.
292302
```
293303
$ podman ps --format "{{.Names}} is in pod {{.PodName}} ({{.Pod}})"

docs/source/markdown/podman-restart.1.md.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Valid filters are listed below:
3636
| id | [ID] Container's ID (CID prefix match by default; accepts regex) |
3737
| name | [Name] Container's name (accepts regex) |
3838
| label | [Key] or [Key=Value] Label assigned to a container |
39+
| label! | [Key] or [Key=Value] Label NOT assigned to a container |
3940
| exited | [Int] Container's exit code |
4041
| status | [Status] Container's status: 'created', 'initialized', 'exited', 'paused', 'running', 'unknown' |
4142
| ancestor | [ImageName] Image or descendant used to create container |
@@ -45,8 +46,10 @@ Valid filters are listed below:
4546
| health | [Status] healthy or unhealthy |
4647
| pod | [Pod] name or full or partial ID of pod |
4748
| network | [Network] name or full ID of network |
49+
| restart-policy | [Policy] Container's restart policy (e.g., 'no', 'on-failure', 'always', 'unless-stopped') |
4850
| until | [DateTime] Containers created before the given duration or time. |
4951
| command | [Command] the command the container is executing, only argv[0] is taken |
52+
| should-start-on-boot | [Bool] Containers that need to be restarted after system reboot. True for containers with restart policy 'always', or 'unless-stopped' that were not explicitly stopped by the user |
5053

5154
@@option latest
5255

docs/source/markdown/podman-rm.1.md.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Valid filters are listed below:
4040
| id | [ID] Container's ID (CID prefix match by default; accepts regex) |
4141
| name | [Name] Container's name (accepts regex) |
4242
| label | [Key] or [Key=Value] Label assigned to a container |
43+
| label! | [Key] or [Key=Value] Label NOT assigned to a container |
4344
| exited | [Int] Container's exit code |
4445
| status | [Status] Container's status: 'created', 'initialized', 'exited', 'paused', 'running', 'unknown' |
4546
| ancestor | [ImageName] Image or descendant used to create container |
@@ -49,8 +50,10 @@ Valid filters are listed below:
4950
| health | [Status] healthy or unhealthy |
5051
| pod | [Pod] name or full or partial ID of pod |
5152
| network | [Network] name or full ID of network |
53+
| restart-policy | [Policy] Container's restart policy (e.g., 'no', 'on-failure', 'always', 'unless-stopped') |
5254
| until | [DateTime] Containers created before the given duration or time. |
5355
| command | [Command] the command the container is executing, only argv[0] is taken |
56+
| should-start-on-boot | [Bool] Containers that need to be restarted after system reboot. True for containers with restart policy 'always', or 'unless-stopped' that were not explicitly stopped by the user |
5457

5558
#### **--force**, **-f**
5659

docs/source/markdown/podman-start.1.md.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ starting multiple containers.
2727

2828
@@option detach-keys
2929

30-
#### **--filter**, **-f**
30+
#### **--filter**, **-f**=*filter*
3131

3232
Filter what containers are going to be started from the given arguments.
3333
Multiple filters can be given with multiple uses of the --filter flag.
@@ -41,6 +41,7 @@ Valid filters are listed below:
4141
| id | [ID] Container's ID (CID prefix match by default; accepts regex) |
4242
| name | [Name] Container's name (accepts regex) |
4343
| label | [Key] or [Key=Value] Label assigned to a container |
44+
| label! | [Key] or [Key=Value] Label NOT assigned to a container |
4445
| exited | [Int] Container's exit code |
4546
| status | [Status] Container's status: 'created', 'initialized', 'exited', 'paused', 'running', 'unknown' |
4647
| ancestor | [ImageName] Image or descendant used to create container |
@@ -50,8 +51,10 @@ Valid filters are listed below:
5051
| health | [Status] healthy or unhealthy |
5152
| pod | [Pod] name or full or partial ID of pod |
5253
| network | [Network] name or full ID of network |
54+
| restart-policy | [Policy] Container's restart policy (e.g., 'no', 'on-failure', 'always', 'unless-stopped') |
5355
| until | [DateTime] Containers created before the given duration or time. |
5456
| command | [Command] the command the container is executing, only argv[0] is taken |
57+
| should-start-on-boot | [Bool] Containers that need to be restarted after system reboot. True for containers with restart policy 'always', or 'unless-stopped' that were not explicitly stopped by the user |
5558

5659
@@option interactive
5760

docs/source/markdown/podman-stop.1.md.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Valid filters are listed below:
3939
| id | [ID] Container's ID (CID prefix match by default; accepts regex) |
4040
| name | [Name] Container's name (accepts regex) |
4141
| label | [Key] or [Key=Value] Label assigned to a container |
42+
| label! | [Key] or [Key=Value] Label NOT assigned to a container |
4243
| exited | [Int] Container's exit code |
4344
| status | [Status] Container's status: 'created', 'initialized', 'exited', 'paused', 'running', 'unknown' |
4445
| ancestor | [ImageName] Image or descendant used to create container |
@@ -48,8 +49,10 @@ Valid filters are listed below:
4849
| health | [Status] healthy or unhealthy |
4950
| pod | [Pod] name or full or partial ID of pod |
5051
| network | [Network] name or full ID of network |
52+
| restart-policy | [Policy] Container's restart policy (e.g., 'no', 'on-failure', 'always', 'unless-stopped') |
5153
| until | [DateTime] Containers created before the given duration or time. |
5254
| command | [Command] the command the container is executing, only argv[0] is taken |
55+
| should-start-on-boot | [Bool] Containers that need to be restarted after system reboot. True for containers with restart policy 'always', or 'unless-stopped' that were not explicitly stopped by the user |
5356

5457
@@option ignore
5558

docs/source/markdown/podman-unpause.1.md.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Valid filters are listed below:
3333
| id | [ID] Container's ID (CID prefix match by default; accepts regex) |
3434
| name | [Name] Container's name (accepts regex) |
3535
| label | [Key] or [Key=Value] Label assigned to a container |
36+
| label! | [Key] or [Key=Value] Label NOT assigned to a container |
3637
| exited | [Int] Container's exit code |
3738
| status | [Status] Container's status: 'created', 'initialized', 'exited', 'paused', 'running', 'unknown' |
3839
| ancestor | [ImageName] Image or descendant used to create container |
@@ -42,8 +43,10 @@ Valid filters are listed below:
4243
| health | [Status] healthy or unhealthy |
4344
| pod | [Pod] name or full or partial ID of pod |
4445
| network | [Network] name or full ID of network |
46+
| restart-policy | [Policy] Container's restart policy (e.g., 'no', 'on-failure', 'always', 'unless-stopped') |
4547
| until | [DateTime] Containers created before the given duration or time. |
4648
| command | [Command] the command the container is executing, only argv[0] is taken |
49+
| should-start-on-boot | [Bool] Containers that need to be restarted after system reboot. True for containers with restart policy 'always', or 'unless-stopped' that were not explicitly stopped by the user |
4750

4851
@@option latest
4952

0 commit comments

Comments
 (0)