{"record":{"id":"f60332f37b52aa91","repo":"lima-vm/lima","slug":"failed-to-enable-launchdaemon-w","errorCode":null,"errorMessage":"failed to enable LaunchDaemon: %w","messagePattern":"failed to enable LaunchDaemon: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/limactl/autostart_darwin.go","lineNumber":136,"sourceCode":"\ttmp, err := os.CreateTemp(\"\", \"io.lima-vm.daemon.*.plist\")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create temp file: %w\", err)\n\t}\n\tdefer os.Remove(tmp.Name())\n\tif _, err := tmp.Write(content); err != nil {\n\t\treturn fmt.Errorf(\"failed to write temp plist: %w\", err)\n\t}\n\ttmp.Close()\n\n\tdestPath := launchd.GetDaemonPlistPath(instName)\n\tsvcTarget := \"system/\" + launchd.DaemonServiceNameFrom(instName)\n\n\t_ = runSudo(ctx, \"launchctl\", \"bootout\", svcTarget)\n\tif err := runSudo(ctx, \"install\", \"-m\", \"644\", tmp.Name(), destPath); err != nil {\n\t\treturn fmt.Errorf(\"failed to install plist to %s: %w\", destPath, err)\n\t}\n\tif err := runSudo(ctx, \"launchctl\", \"enable\", svcTarget); err != nil {\n\t\treturn fmt.Errorf(\"failed to enable LaunchDaemon: %w\", err)\n\t}\n\tif err := runSudo(ctx, \"launchctl\", \"bootstrap\", \"system\", destPath); err != nil {\n\t\treturn fmt.Errorf(\"failed to bootstrap LaunchDaemon: %w\", err)\n\t}\n\n\tlogrus.Infof(\"LaunchDaemon installed for instance %q (runs as %q at boot)\", instName, userName)\n\tlogrus.Infof(\"Plist: %s\", destPath)\n\treturn nil\n}\n\nfunc daemonUninstall(ctx context.Context, instName string) error {\n\tsvcTarget := \"system/\" + launchd.DaemonServiceNameFrom(instName)\n\tdestPath := launchd.GetDaemonPlistPath(instName)\n\n\t_ = runSudo(ctx, \"launchctl\", \"bootout\", svcTarget)\n\t_ = runSudo(ctx, \"launchctl\", \"disable\", svcTarget)\n\tif err := runSudo(ctx, \"rm\", \"-f\", destPath); err != nil {\n\t\treturn fmt.Errorf(\"failed to remove %s: %w\", destPath, err)","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/cmd/limactl/autostart_darwin.go#L118-L154","documentation":"daemonInstall runs `sudo launchctl enable system/<service>` after installing the plist; this error wraps that command's nonzero exit. launchctl enable failing usually means the service target is malformed, the plist is invalid, or launchd rejected the operation.","triggerScenarios":"`limactl autostart <instance> --condition=boot` on macOS when `sudo launchctl enable system/io.lima-vm.daemon.<instance>` fails: canceled sudo prompt, malformed plist at the destination, or launchctl unavailable in the current context (e.g. SSH session without proper domain access).","commonSituations":"Installing over SSH where the system domain is not accessible in older macOS versions; corrupted plist from a previous failed install; sudo session expired mid-sequence.","solutions":["Rerun the command and complete the sudo prompt","Validate the installed plist: `sudo plutil -lint /Library/LaunchDaemons/io.lima-vm.daemon.<instance>.plist`","Check the service state: `sudo launchctl print system/io.lima-vm.daemon.<instance>`","Try manual bootout then re-run limactl to get a clean state"],"exampleFix":"// before: limactl autostart myinstance --condition=boot  (fails after stale state)\n// after:  sudo launchctl bootout system/io.lima-vm.daemon.myinstance; limactl autostart myinstance --condition=boot","handlingStrategy":"try-catch","validationCode":"sudo plutil -lint /Library/LaunchDaemons/io.lima-vm.daemon.<instance>.plist || echo \"plist invalid\"\nsudo launchctl print system/io.lima-vm.daemon.<instance> >/dev/null 2>&1 && echo \"service already loaded\"","typeGuard":null,"tryCatchPattern":"if err := daemonInstall(ctx, inst.Name, inst.Dir, userName, keepAlive); err != nil {\n\tif strings.Contains(err.Error(), \"failed to enable LaunchDaemon\") {\n\t\t// recover: bootout stale state and retry once\n\t\t_ = runSudo(ctx, \"launchctl\", \"bootout\", \"system/io.lima-vm.daemon.\"+inst.Name)\n\t\treturn daemonInstall(ctx, inst.Name, inst.Dir, userName, keepAlive)\n\t}\n\treturn err\n}","preventionTips":["Bootout the service before re-enabling on existing installs","Lint the plist with plutil after any manual edits","Avoid installing system daemons over SSH on macOS versions that restrict the system domain","Keep sudo sessions fresh across multi-step installs"],"tags":["macos","launchd","sudo","daemon"],"backgroundTag":"launchctl-command-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}