Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions cmd/podman/machine/restart.go
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
}
38 changes: 38 additions & 0 deletions docs/source/markdown/podman-machine-restart.1.md
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
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.

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>
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.

1 change: 1 addition & 0 deletions docs/source/markdown/podman-machine.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
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


## 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)**
Expand Down