跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

restart.go

60 行 · 1.7 KB历史下载
1// SPDX-FileCopyrightText: Copyright The Lima Authors
2// SPDX-License-Identifier: Apache-2.0
3
4package instance
5
6import (
7 "context"
8 "errors"
9 "fmt"
10
11 "github.com/sirupsen/logrus"
12
13 "github.com/lima-vm/lima/v2/pkg/autostart"
14 "github.com/lima-vm/lima/v2/pkg/limatype"
15 "github.com/lima-vm/lima/v2/pkg/networks/reconcile"
16)
17
18const (
19 launchHostAgentForeground = false
20)
21
22func Restart(ctx context.Context, inst *limatype.Instance, showProgress bool) error {
23 if err := StopGracefully(ctx, inst, true); err != nil {
24 return err
25 }
26
27 // Network reconciliation will be performed by the process launched by the autostart manager
28 if registered, err := autostart.IsRegistered(ctx, inst); err != nil && !errors.Is(err, autostart.ErrNotSupported) {
29 return fmt.Errorf("failed to check if the autostart entry for instance %#q is registered: %w", inst.Name, err)
30 } else if !registered {
31 if err := reconcile.Reconcile(ctx, inst.Name); err != nil {
32 return err
33 }
34 }
35
36 if err := Start(ctx, inst, launchHostAgentForeground, showProgress); err != nil {
37 return err
38 }
39
40 return nil
41}
42
43func RestartForcibly(ctx context.Context, inst *limatype.Instance, showProgress bool) error {
44 logrus.Info("Restarting the instance forcibly")
45 StopForcibly(inst)
46
47 if registered, err := autostart.IsRegistered(ctx, inst); err != nil && !errors.Is(err, autostart.ErrNotSupported) {
48 return fmt.Errorf("failed to check if the autostart entry for instance %#q is registered: %w", inst.Name, err)
49 } else if !registered {
50 if err := reconcile.Reconcile(ctx, inst.Name); err != nil {
51 return err
52 }
53 }
54
55 if err := Start(ctx, inst, launchHostAgentForeground, showProgress); err != nil {
56 return err
57 }
58
59 return nil
60}