Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
lima-vm
GitHub Repository: lima-vm/lima
Path: blob/master/cmd/limactl/restart.go
1645 views
1
// SPDX-FileCopyrightText: Copyright The Lima Authors
2
// SPDX-License-Identifier: Apache-2.0
3
4
package main
5
6
import (
7
"github.com/spf13/cobra"
8
9
"github.com/lima-vm/lima/v2/pkg/instance"
10
"github.com/lima-vm/lima/v2/pkg/store"
11
)
12
13
func newRestartCommand() *cobra.Command {
14
restartCmd := &cobra.Command{
15
Use: "restart INSTANCE",
16
Short: "Restart a running instance",
17
Args: WrapArgsError(cobra.MaximumNArgs(1)),
18
RunE: restartAction,
19
ValidArgsFunction: restartBashComplete,
20
GroupID: basicCommand,
21
}
22
23
restartCmd.Flags().BoolP("force", "f", false, "Force stop and restart the instance")
24
restartCmd.Flags().Bool("progress", false, "Show provision script progress by tailing cloud-init logs")
25
return restartCmd
26
}
27
28
func restartAction(cmd *cobra.Command, args []string) error {
29
ctx := cmd.Context()
30
instName := DefaultInstanceName
31
if len(args) > 0 {
32
instName = args[0]
33
}
34
35
inst, err := store.Inspect(ctx, instName)
36
if err != nil {
37
return err
38
}
39
40
force, err := cmd.Flags().GetBool("force")
41
if err != nil {
42
return err
43
}
44
progress, err := cmd.Flags().GetBool("progress")
45
if err != nil {
46
return err
47
}
48
49
if force {
50
return instance.RestartForcibly(ctx, inst, progress)
51
}
52
53
return instance.Restart(ctx, inst, progress)
54
}
55
56
func restartBashComplete(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
57
return bashCompleteInstanceNames(cmd)
58
}
59
60