Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
lima-vm
GitHub Repository: lima-vm/lima
Path: blob/master/pkg/autostart/autostart.go
2639 views
1
// SPDX-FileCopyrightText: Copyright The Lima Authors
2
// SPDX-License-Identifier: Apache-2.0
3
4
// Package autostart manage start at login unit files for darwin/linux
5
package autostart
6
7
import (
8
"context"
9
"sync"
10
11
"github.com/lima-vm/lima/v2/pkg/limatype"
12
)
13
14
// IsRegistered checks if the instance is registered to start at login.
15
func IsRegistered(ctx context.Context, inst *limatype.Instance) (bool, error) {
16
return manager().IsRegistered(ctx, inst)
17
}
18
19
// RegisterToStartAtLogin creates a start-at-login entry for the instance.
20
func RegisterToStartAtLogin(ctx context.Context, inst *limatype.Instance) error {
21
return manager().RegisterToStartAtLogin(ctx, inst)
22
}
23
24
// UnregisterFromStartAtLogin deletes the start-at-login entry for the instance.
25
func UnregisterFromStartAtLogin(ctx context.Context, inst *limatype.Instance) error {
26
return manager().UnregisterFromStartAtLogin(ctx, inst)
27
}
28
29
// AutoStartedIdentifier returns the identifier if the current process was started by the autostart manager.
30
func AutoStartedIdentifier() string {
31
return manager().AutoStartedIdentifier()
32
}
33
34
// RequestStart requests to start the instance by identifier.
35
func RequestStart(ctx context.Context, inst *limatype.Instance) error {
36
return manager().RequestStart(ctx, inst)
37
}
38
39
// RequestStop requests to stop the instance by identifier.
40
func RequestStop(ctx context.Context, inst *limatype.Instance) (bool, error) {
41
return manager().RequestStop(ctx, inst)
42
}
43
44
type autoStartManager interface {
45
// Registration
46
IsRegistered(ctx context.Context, inst *limatype.Instance) (bool, error)
47
RegisterToStartAtLogin(ctx context.Context, inst *limatype.Instance) error
48
UnregisterFromStartAtLogin(ctx context.Context, inst *limatype.Instance) error
49
50
// Status
51
AutoStartedIdentifier() string
52
53
// Operation
54
// RequestStart requests to start the instance by identifier.
55
RequestStart(ctx context.Context, inst *limatype.Instance) error
56
// RequestStop requests to stop the instance by identifier.
57
RequestStop(ctx context.Context, inst *limatype.Instance) (bool, error)
58
}
59
60
var manager = sync.OnceValue(Manager)
61
62