Skip to content

feat(autostart): add --keep-alive flag to limactl autostart enable#5086

Open
resker wants to merge 5 commits into
lima-vm:masterfrom
resker:feature/autostart-keepalive
Open

feat(autostart): add --keep-alive flag to limactl autostart enable#5086
resker wants to merge 5 commits into
lima-vm:masterfrom
resker:feature/autostart-keepalive

Conversation

@resker
Copy link
Copy Markdown

@resker resker commented Jun 6, 2026

Depends on #4984.

Summary

  • Adds --keep-alive (default: true) to limactl autostart enable for both LaunchAgent and LaunchDaemon plist templates
  • When enabled, launchd restarts the Lima host agent automatically if it exits unexpectedly, preventing instances from remaining in a Broken state until the next login or reboot
  • The flag is accepted on all platforms; on Linux it is a no-op (systemd restart behavior is configured separately in the unit file)

Testing

  • Manually tested on Apple Silicon Mac (macOS 26, arm64)
  • Confirmed launchd restarts the agent after a simulated crash with --keep-alive=true
  • Confirmed no restart with --keep-alive=false

Closes #4992


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and I have signed off all commits per the DCO.

resker added 3 commits June 5, 2026 20:10
Adds `limactl autostart enable --condition=boot` to register a Lima instance
as a system-level LaunchDaemon. The VM starts at boot without requiring a user
login session, enabling headless macOS server deployments.

Also unifies the existing start-at-login functionality under the new
`limactl autostart` command and deprecates `limactl start-at-login`.

- pkg/autostart/launchd: add DaemonManager, plist template, and helpers
- pkg/autostart/managers.go: add extraTemplateVars field
- pkg/autostart/managers_darwin.go: DaemonManager constructor
- pkg/autostart/managers_{linux,others}.go: unsupported stubs
- cmd/limactl/autostart.go: cross-platform autostart command group
- cmd/limactl/autostart_darwin.go: login → LaunchAgent, boot → LaunchDaemon
- cmd/limactl/autostart_others.go: login only, boot returns unsupported error
- cmd/limactl/start-at-login.go: marked deprecated
- website/content/en/docs/usage/autostart.md: new documentation page

Signed-off-by: Robert Esker <resker@gmail.com>
Add --keep-alive (default: true) to both LaunchAgent and LaunchDaemon
plist templates. When enabled, launchd restarts the Lima host agent
automatically if it exits unexpectedly, preventing instances from
remaining in a Broken state until the next login or reboot.

The flag is accepted on all platforms; on Linux it is a no-op since
systemd restart behavior is configured separately in the unit file.

Closes: lima-vm#4992

Signed-off-by: Robert Esker <resker@gmail.com>
Signed-off-by: Robert Esker <resker@gmail.com>
@resker resker force-pushed the feature/autostart-keepalive branch from 6a6b3ee to 1c43fab Compare June 6, 2026 01:10
Without whitespace trimming, the {{if}}...{{end}} block left a blank
line in the rendered plist when KeepAlive=false, breaking unit tests.

Signed-off-by: Robert Esker <resker@gmail.com>
@resker
Copy link
Copy Markdown
Author

resker commented Jun 6, 2026

@AkihiroSuda - fyi, also submitted a follow-up PR #5086

The systemd unit uses Restart=on-failure unconditionally, so --keep-alive
is always active on Linux regardless of the flag value.

Signed-off-by: Robert Esker <resker@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

autostart: add KeepAlive to LaunchAgent and LaunchDaemon plists

1 participant