-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Add podman machine restart subcommand
#28687
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
Open
jaitjacob
wants to merge
1
commit into
containers:main
Choose a base branch
from
jaitjacob:add-podman-machine-restart-command
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+96
−0
Open
Changes from all commits
Commits
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
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,57 @@ | ||
| //go:build amd64 || arm64 | ||
|
|
||
| package machine | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| "go.podman.io/podman/v6/cmd/podman/registry" | ||
| "go.podman.io/podman/v6/libpod/events" | ||
| "go.podman.io/podman/v6/pkg/machine" | ||
| "go.podman.io/podman/v6/pkg/machine/shim" | ||
| ) | ||
|
|
||
| var restartCmd = &cobra.Command{ | ||
| Use: "restart [MACHINE]", | ||
| Short: "Restart an existing machine", | ||
| Long: "Restart a managed virtual machine", | ||
| PersistentPreRunE: machinePreRunE, | ||
| RunE: restart, | ||
| Args: cobra.MaximumNArgs(1), | ||
| Example: `podman machine restart podman-machine-default`, | ||
| ValidArgsFunction: AutocompleteMachine, | ||
| } | ||
|
|
||
| func init() { | ||
| registry.Commands = append(registry.Commands, registry.CliCommand{ | ||
| Command: restartCmd, | ||
| Parent: machineCmd, | ||
| }) | ||
| } | ||
|
|
||
| func restart(_ *cobra.Command, args []string) error { | ||
| vmName := defaultMachineName | ||
| if len(args) > 0 && len(args[0]) > 0 { | ||
| vmName = args[0] | ||
| } | ||
|
|
||
| mc, vmProvider, err := shim.VMExists(vmName) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if err := shim.Stop(mc, vmProvider, false); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| 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 { | ||
| return err | ||
| } | ||
| fmt.Printf("Machine %q started successfully\n", vmName) | ||
| newMachineEvent(events.Start, events.Event{Name: vmName}) | ||
| return nil | ||
| } |
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,38 @@ | ||
| % podman-machine-restart 1 | ||
|
|
||
| ## NAME | ||
| podman\-machine\-restart - Restart a virtual machine | ||
|
|
||
| ## SYNOPSIS | ||
| **podman machine restart** [*name*] | ||
|
|
||
| ## DESCRIPTION | ||
|
|
||
| Restarts a virtual machine for Podman. | ||
|
|
||
| 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 | ||
| starts it from a stopped state. | ||
|
|
||
| **podman machine restart** stops and then starts a Linux virtual machine where containers are run. | ||
|
|
||
| ## OPTIONS | ||
|
|
||
| #### **--help** | ||
|
|
||
| Print usage statement. | ||
|
|
||
| ## EXAMPLES | ||
|
|
||
| Restart a podman machine named myvm. | ||
| ``` | ||
| $ podman machine restart myvm | ||
| ``` | ||
|
|
||
| ## SEE ALSO | ||
| **[podman(1)](podman.1.md)**, **[podman-machine(1)](podman-machine.1.md)** | ||
|
|
||
| ## HISTORY | ||
| March 2021, Originally compiled by Ashley Cui <acui@redhat.com> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this needs to change. |
||
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 |
|---|---|---|
|
|
@@ -49,6 +49,7 @@ supported by platform. The asterisk denotes the default provider for the platfo | |
| | 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 | | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be in alpha order between |
||
|
|
||
| ## SEE ALSO | ||
| **[podman(1)](podman.1.md)**, **[podman-machine-cp(1)](podman-machine-cp.1.md)**, **[podman-machine-info(1)](podman-machine-info.1.md)**, **[podman-machine-init(1)](podman-machine-init.1.md)**, **[podman-machine-list(1)](podman-machine-list.1.md)**, **[podman-machine-os(1)](podman-machine-os.1.md)**, **[podman-machine-rm(1)](podman-machine-rm.1.md)**, **[podman-machine-ssh(1)](podman-machine-ssh.1.md)**, **[podman-machine-start(1)](podman-machine-start.1.md)**, **[podman-machine-stop(1)](podman-machine-stop.1.md)**, **[podman-machine-inspect(1)](podman-machine-inspect.1.md)**, **[podman-machine-reset(1)](podman-machine-reset.1.md)**, **[containers.conf(5)](https://github.com/containers/container-libs/blob/main/common/docs/containers.conf.5.md)** | ||
|
|
||
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.
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.
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.