Skip to content

Commit

Permalink
add cli flag, create package autostart, autostart templates
Browse files Browse the repository at this point in the history
Signed-off-by: roman-kiselenko <[email protected]>
  • Loading branch information
roman-kiselenko committed Jan 18, 2024
1 parent 83978c2 commit 487e118
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cmd/limactl/editflags/editflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ func registerEdit(cmd *cobra.Command, commentPrefix string) {

flags.String("set", "", commentPrefix+"modify the template inplace, using yq syntax")

flags.Bool("autostart", false, commentPrefix+"create autostart entry with launchd/systemd")

// negative performance impact: https://gitlab.com/qemu-project/qemu/-/issues/334
flags.Bool("video", false, commentPrefix+"enable video output (has negative performance impact for QEMU)")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/limactl/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ func startAction(cmd *cobra.Command, args []string) error {
if timeout > 0 {
ctx = start.WithWatchHostAgentTimeout(ctx, timeout)
}

inst.StartAtLogin, _ = cmd.Flags().GetBool("autostart")
return start.Start(ctx, inst)
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/autostart/autostart.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package autostart

import "fmt"

func CreateFile(hostOS string) error {
fmt.Printf("host: %s", hostOS)
return nil
}
26 changes: 26 additions & 0 deletions pkg/autostart/io.lima-vm.autostart.INSTANCE.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>io.lima-vm.{{ .INSTANCE }}</string>
<key>ProgramArguments</key>
<array>
<string>'"$(which limactl)"'</string>
<string>hostagent</string>
<string>--pidfile</string>
<string>ha.pid</string>
<string>--socket</string>
<string>ha.sock</string>
<string>{{ .INSTANCE }}</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>ha.stderr.log</string>
<key>StandardOutPath</key>
<string>ha.stdout.log</string>
<key>WorkingDirectory</key>
<string>'"$(limactl list {{ .INSTANCE }} --format '{{.Dir}}')"'</string>
</dict>
</plist>
10 changes: 10 additions & 0 deletions pkg/autostart/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=Lima - Linux virtual machines, with a focus on running containers.

[Service]
ExecStart={{.Binary}} start %i
Type=simple
Restart=on-failure

[Install]
WantedBy=multi-user.target
6 changes: 6 additions & 0 deletions pkg/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"time"

"github.com/coreos/go-semver/semver"
"github.com/lima-vm/lima/pkg/autostart"
"github.com/lima-vm/lima/pkg/driver"
"github.com/lima-vm/lima/pkg/driverutil"
"github.com/lima-vm/lima/pkg/osutil"
Expand Down Expand Up @@ -272,6 +273,11 @@ func watchHostAgentEvents(ctx context.Context, inst *store.Instance, haStdoutPat
} else {
logrus.Infof("READY. Run `%s` to open the shell.", LimactlShellCmd(inst.Name))
}
if inst.StartAtLogin {
if err := autostart.CreateFile(runtime.GOOS); err != nil {
logrus.Errorf("cant create autostart files error: %s", err)
}
}
_ = ShowMessage(inst)
err = nil
return true
Expand Down
1 change: 1 addition & 0 deletions pkg/store/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type Instance struct {
SSHAddress string `json:"sshAddress,omitempty"`
Protected bool `json:"protected"`
LimaVersion string `json:"limaVersion"`
StartAtLogin bool `json:"startAtLogin"`
}

func (inst *Instance) LoadYAML() (*limayaml.LimaYAML, error) {
Expand Down

0 comments on commit 487e118

Please sign in to comment.