Skip to content

Add podman machine restart subcommand#28687

Open
jaitjacob wants to merge 3 commits into
containers:mainfrom
jaitjacob:add-podman-machine-restart-command
Open

Add podman machine restart subcommand#28687
jaitjacob wants to merge 3 commits into
containers:mainfrom
jaitjacob:add-podman-machine-restart-command

Conversation

@jaitjacob
Copy link
Copy Markdown
Contributor

@jaitjacob jaitjacob commented May 11, 2026

Checklist

Ensure you have completed the following checklist for your pull request to be reviewed:

  • Certify you wrote the patch or otherwise have the right to pass it on as an open-source patch by signing all
    commits. (git commit -s). (If needed, use git commit -s --amend). The author email must match
    the sign-off email address. See CONTRIBUTING.md
    for more information.
  • Referenced issues using Fixes: #00000 in commit message (if applicable)
  • Tests have been added/updated (or no tests are needed)
  • Documentation has been updated (or no documentation changes are needed)
  • All commits pass make validatepr (format/lint checks)
  • Release note entered in the section below (or None if no user-facing changes)

Does this PR introduce a user-facing change?

Yes? No action needed when upgrading?

Fixes #28366

This PR implements podman machine restart subcommand.

Here's how I tested it,

  1. Locally build podman binary using make BUILDTAGS="selinux seccomp" PREFIX=/usr
  2. cd bin/
  3. Run ./podman machine restart --help & verify help text displays correctly.
jaitjacob@fedora:~/Documents/workbench/podman/bin$ ./podman machine restart --help
Restart an existing machine

Description:
  Restart a managed virtual machine

Usage:
  podman machine restart [MACHINE]

Examples:
  podman machine restart podman-machine-default
  1. Run ./podman machine list
jaitjacob@fedora:~/Documents/workbench/podman/bin$ ./podman machine list
NAME                     VM TYPE     CREATED      LAST UP            CPUS        MEMORY      DISK SIZE
podman-machine-default*  qemu        3 hours ago  About an hour ago  2           2GiB        10GiB
  1. Run ./podman machine start
jaitjacob@fedora:~/Documents/workbench/podman/bin$ ./podman machine start
Starting machine "podman-machine-default"

This machine is currently configured in rootless mode. If your containers
require root permissions (e.g. ports < 1024), or if you run into compatibility
issues with non-podman clients, you can switch using the following command:

        podman machine set --rootful

Mounting volume... /home/jaitjacob:/home/jaitjacob
API forwarding listening on: /run/user/1000/podman/podman-machine-default-api.sock
You can connect Docker API clients by setting DOCKER_HOST using the
following command in your terminal session:

        export DOCKER_HOST='unix:///run/user/1000/podman/podman-machine-default-api.sock'

Machine "podman-machine-default" started successfully
  1. SSH into VM and check uptime
jaitjacob@fedora:~/Documents/workbench/podman/bin$ ./podman machine ssh
Connecting to vm podman-machine-default. To close connection, use `~.` or `exit`
Fedora CoreOS 43.20260316.3.1
Tracker: https://github.com/coreos/fedora-coreos-tracker
Discuss: https://discussion.fedoraproject.org/tag/coreos

Last login: Mon May 11 22:26:20 2026 from 192.168.127.1
core@localhost:~$ uptime -p
up 0 minutes
core@localhost:~$ uptime -s
2026-05-12 00:36:59
  1. Wait couple mins and run ./podman machine restart
jaitjacob@fedora:~/Documents/workbench/podman/bin$ ./podman machine restart
Waiting for VM to exit...
Machine "podman-machine-default" stopped successfully

This machine is currently configured in rootless mode. If your containers
require root permissions (e.g. ports < 1024), or if you run into compatibility
issues with non-podman clients, you can switch using the following command:

        podman machine set --rootful

Mounting volume... /home/jaitjacob:/home/jaitjacob
API forwarding listening on: /run/user/1000/podman/podman-machine-default-api.sock
You can connect Docker API clients by setting DOCKER_HOST using the
following command in your terminal session:

        export DOCKER_HOST='unix:///run/user/1000/podman/podman-machine-default-api.sock'

Machine "podman-machine-default" started successfully
  1. SSH into VM and Check uptime again
jaitjacob@fedora:~/Documents/workbench/podman/bin$ ./podman machine ssh
Connecting to vm podman-machine-default. To close connection, use `~.` or `exit`
Fedora CoreOS 43.20260316.3.1
Tracker: https://github.com/coreos/fedora-coreos-tracker
Discuss: https://discussion.fedoraproject.org/tag/coreos

Last login: Tue May 12 00:37:17 2026 from 192.168.127.1
core@localhost:~$ uptime -p
up 0 minutes
core@localhost:~$ uptime -s
2026-05-12 00:39:14

I also built the docs locally and viewed in browser,
1

2

**[podman(1)](podman.1.md)**, **[podman-machine(1)](podman-machine.1.md)**

## HISTORY
March 2021, Originally compiled by Ashley Cui <[email protected]>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

The default machine name is `podman-machine-default`. If a machine name is not specified as an argument,
then `podman-machine-default` will be restarted.

Stopping an already stopped vm is not considered an error so running restart on a stopped vm just
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Stopping an already stopped vm is not considered an error so running restart on a stopped vm just
Stopping an already stopped virtual machine is not considered an error so running restart on a stopped virtual machine just

I realize this was probably a cut/paste form elsewhere, but we say "virtual machine" everywhere else in this doc, so we should be consistant.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes straight from a code comment i read :) fixed

| ssh | [podman-machine-ssh(1)](podman-machine-ssh.1.md) | SSH into a virtual machine |
| start | [podman-machine-start(1)](podman-machine-start.1.md) | Start a virtual machine |
| stop | [podman-machine-stop(1)](podman-machine-stop.1.md) | Stop a virtual machine |
| restart | [podman-machine-restart(1)](podman-machine-restart.1.md) | Restart a virtual machine |
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be in alpha order between reset and rm

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@TomSweeneyRedHat
Copy link
Copy Markdown
Member

@jaitjacob TYVM for the PR! It looks great overall. You should add a test or two if possible, and there are a few tweaks to do to the documenation.

By far the best description I've seen on a PR in a very long time!

Copy link
Copy Markdown
Member

@Honny1 Honny1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! At first glance, the code looks good. However, the PR is missing tests. Please implement e2e tests for machine. Here is an example you can use as a reference: https://github.com/containers/podman/blob/main/pkg/machine/e2e/start_test.go. You can add a restart_test.go file for this.

@baude
Copy link
Copy Markdown
Member

baude commented May 12, 2026

One of the reasons I never wanted this sub-command is because there were cases were if the Podman binary did not exit, then there could be collision or zombied processes of helper functions or the various sockets and pipes being used. Are you certain that this cannot happen?

@baude
Copy link
Copy Markdown
Member

baude commented May 12, 2026

in addition to tests, we might need a basic test added to podman-machine-os as well?

| stop | [podman-machine-stop(1)](podman-machine-stop.1.md) | Stop a virtual machine |
| restart | [podman-machine-restart(1)](podman-machine-restart.1.md) | Restart a virtual machine |

## SEE ALSO
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might want to add a reference here as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added ref to the command under 'See Also'

Comment thread cmd/podman/machine/restart.go Outdated
fmt.Printf("Machine %q stopped successfully\n", vmName)
newMachineEvent(events.Stop, events.Event{Name: vmName})

if err := shim.Start(mc, vmProvider, machine.StartOptions{}, nil); err != nil {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand this, passing nil here would trigger an update system connection prompt, which I'm not sure is ideal during a restart.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

passing false for updateSystemConn bool instead.

Comment thread cmd/podman/machine/restart.go Outdated
if err := shim.Start(mc, vmProvider, machine.StartOptions{}, nil); err != nil {
return err
}
fmt.Printf("Machine %q started successfully\n", vmName)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fmt.Printf("Machine %q started successfully\n", vmName)
fmt.Printf("Machine %q restarted successfully\n", vmName)

Comment thread cmd/podman/machine/restart.go Outdated
return err
}

fmt.Printf("Machine %q stopped successfully\n", vmName)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about dropping this altogether and simply printing a "restarted successfully" msg?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall I also extend this to emit a single newMachineEvent(events.Restart) instead of the current newMachineEvent(events.Stop) followed by newMachineEvent(events.Start)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont believe a "restart" event is valid. it's still a stop and a start. i would agree, line 48 is not needed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw a Restart enum defined in events/config.go which I assumed I could use here.

I've removed line 48.

@jaitjacob jaitjacob force-pushed the add-podman-machine-restart-command branch from 5fb7439 to e76d4e0 Compare May 13, 2026 20:10
@packit-as-a-service
Copy link
Copy Markdown

[NON-BLOCKING] Packit jobs failed. @containers/packit-build please check. Everyone else, feel free to ignore.

@jaitjacob jaitjacob force-pushed the add-podman-machine-restart-command branch from e76d4e0 to 1ec2c98 Compare May 13, 2026 20:50
return err
}

newMachineEvent(events.Stop, events.Event{Name: vmName})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when podman machine restart emits a stop event, and in parallel, I run podman machine start? I believe this is the issue @baude wanted to point out. Maybe this could be solved with a new function shim.StopThenStart.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review, Jan. I do not have enough understanding to create baude's concern as a test condition. I did ask AI for help but I wasn't convinced.

podman machine restart emiting a stop event implies shim.Stop was run successfully. So the machine is now definitely in Stopped state. Before restart.go can get to shim.Start a different podman binary could send start which would then result podman machine restart to error out saying,
"Starting machine "podman-machine-default" Error: unable to start "podman-machine-default": already running.

With a shim.StopThenStart are we expecting to hold a lock on the machine until we complete the restart?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

}

func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the restart command cloud has some flags that are related to stopping and starting the machine, for example, --quiet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add podman machine restart command

5 participants