Skip to content

autostart: add KeepAlive to LaunchAgent and LaunchDaemon plists #4992

@resker

Description

@resker

Problem

On macOS, both autostart plist templates (io.lima-vm.autostart.INSTANCE.plist for LaunchAgent and io.lima-vm.daemon.INSTANCE.plist for LaunchDaemon) use RunAtLoad but do not include KeepAlive. If the Lima host agent process exits unexpectedly (crash, signal, OOM), launchd does not restart it. For example, it's left in a Broken state until the next login (LaunchAgent) or reboot (LaunchDaemon), and limactl start fails with a stale ha.sock error:

FATA[0000] errors inspecting instance: [failed to get Info from "~/.lima/k3s/ha.sock":
  Get "http://lima-hostagent/v1/info": dial unix ~/.lima/k3s/ha.sock: connect: connection refused]

The LaunchDaemon case (--condition=boot) is especially relevant: the point of boot-time startup is generally unattended operation.

Proposed fix

Add <key>KeepAlive</key><true/> to both plist templates:

<key>KeepAlive</key>
<true/>

launchd's built-in throttling prevents spin loops on repeated crashes, so this should be safe to enable unconditionally.

Questions

  • Is KeepAlive: true appropriate for the LaunchAgent case as well, or should it be limited to the LaunchDaemon?
  • Should this be an option exposed via limactl autostart enable, or always on?

Related: #4984 (adds the LaunchDaemon / --condition=boot support)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions