macOS: wait for the old launchd job before reloading the daemon
Re-running the installer on a Mac failed with "Bootstrap failed: 5: Input/output error". bootout returns while the old job is still stopping, and the bootstrap right after it fails. setup.sh now lints the plist, waits until launchctl print no longer finds the job, re-enables it (a disabled job also fails with error 5), retries the bootstrap once, and names the commands to check if it still fails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
380243545c
commit
03604c8367
2 changed files with 19 additions and 1 deletions
|
|
@ -144,9 +144,19 @@ else
|
||||||
PLIST
|
PLIST
|
||||||
as_root install -m 644 -o root -g wheel "$plist" "/Library/LaunchDaemons/$SERVICE.plist"
|
as_root install -m 644 -o root -g wheel "$plist" "/Library/LaunchDaemons/$SERVICE.plist"
|
||||||
rm -f "$plist"
|
rm -f "$plist"
|
||||||
|
plutil -lint "/Library/LaunchDaemons/$SERVICE.plist" >/dev/null || native_die "the generated plist is invalid: plutil -lint /Library/LaunchDaemons/$SERVICE.plist"
|
||||||
|
# Unload the old job and wait until it is really gone: bootout returns while the job is
|
||||||
|
# still stopping, and bootstrapping then fails with "5: Input/output error".
|
||||||
as_root launchctl bootout "system/$SERVICE" >/dev/null 2>&1 || true
|
as_root launchctl bootout "system/$SERVICE" >/dev/null 2>&1 || true
|
||||||
as_root launchctl bootstrap system "/Library/LaunchDaemons/$SERVICE.plist"
|
i=0
|
||||||
|
while as_root launchctl print "system/$SERVICE" >/dev/null 2>&1 && [ "$i" -lt 30 ]; do sleep 0.5; i=$((i + 1)); done
|
||||||
|
# A job marked disabled (launchctl disable) can't be bootstrapped either.
|
||||||
as_root launchctl enable "system/$SERVICE" >/dev/null 2>&1 || true
|
as_root launchctl enable "system/$SERVICE" >/dev/null 2>&1 || true
|
||||||
|
if ! as_root launchctl bootstrap system "/Library/LaunchDaemons/$SERVICE.plist"; then
|
||||||
|
sleep 2 # one retry, for a job that took longer to stop
|
||||||
|
as_root launchctl bootstrap system "/Library/LaunchDaemons/$SERVICE.plist" \
|
||||||
|
|| native_die "launchctl bootstrap failed. Check: sudo launchctl print system/$SERVICE; sudo launchctl print-disabled system | grep $NAME"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
if [ "$PLATFORM" = systemd ] && [ "$AVAHI" = 1 ]; then
|
if [ "$PLATFORM" = systemd ] && [ "$AVAHI" = 1 ]; then
|
||||||
native_log "avahi: announcing $(hostname -s).local"
|
native_log "avahi: announcing $(hostname -s).local"
|
||||||
|
|
|
||||||
|
|
@ -158,3 +158,11 @@ def test_macos_daemon_runs_as_root():
|
||||||
setup = (ROOT / "native" / "setup.sh").read_text()
|
setup = (ROOT / "native" / "setup.sh").read_text()
|
||||||
plist = setup[setup.index("<plist"):setup.index("</plist>")]
|
plist = setup[setup.index("<plist"):setup.index("</plist>")]
|
||||||
assert "<key>UserName</key>" not in plist
|
assert "<key>UserName</key>" not in plist
|
||||||
|
|
||||||
|
|
||||||
|
def test_macos_reload_waits_for_the_old_job():
|
||||||
|
"""bootstrap right after bootout fails with "5: Input/output error" while the old job stops."""
|
||||||
|
setup = (ROOT / "native" / "setup.sh").read_text()
|
||||||
|
reload = setup[setup.index('launchctl bootout "system/$SERVICE"'):]
|
||||||
|
assert reload.index('launchctl print "system/$SERVICE"') < reload.index("launchctl bootstrap system")
|
||||||
|
assert reload.index('launchctl enable "system/$SERVICE"') < reload.index("launchctl bootstrap system")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue