|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Install a user LaunchAgent that re-checks the mac-bridge runner |
| 3 | +# after reboot and periodically self-heals it. |
| 4 | + |
| 5 | +set -euo pipefail |
| 6 | + |
| 7 | +REPO_ROOT="$(cd "$(dirname "$0")/../.." && pwd)" |
| 8 | +RECOVER_SCRIPT="${REPO_ROOT}/scripts/mac_bridge/recover_runner_after_reboot.sh" |
| 9 | +PLIST_DIR="${HOME}/Library/LaunchAgents" |
| 10 | +PLIST_PATH="${PLIST_DIR}/com.kakeya.mac-bridge-runner-autorecover.plist" |
| 11 | +LABEL="com.kakeya.mac-bridge-runner-autorecover" |
| 12 | +UID_NUM="$(id -u)" |
| 13 | + |
| 14 | +mkdir -p "$PLIST_DIR" |
| 15 | +[ -x "$RECOVER_SCRIPT" ] || chmod +x "$RECOVER_SCRIPT" |
| 16 | + |
| 17 | +cat >"$PLIST_PATH" <<EOF |
| 18 | +<?xml version="1.0" encoding="UTF-8"?> |
| 19 | +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
| 20 | +<plist version="1.0"> |
| 21 | +<dict> |
| 22 | + <key>Label</key> |
| 23 | + <string>${LABEL}</string> |
| 24 | +
|
| 25 | + <key>ProgramArguments</key> |
| 26 | + <array> |
| 27 | + <string>/bin/bash</string> |
| 28 | + <string>${RECOVER_SCRIPT}</string> |
| 29 | + </array> |
| 30 | +
|
| 31 | + <key>WorkingDirectory</key> |
| 32 | + <string>${REPO_ROOT}</string> |
| 33 | +
|
| 34 | + <key>RunAtLoad</key> |
| 35 | + <true/> |
| 36 | + <key>StartInterval</key> |
| 37 | + <integer>60</integer> |
| 38 | +
|
| 39 | + <key>StandardOutPath</key> |
| 40 | + <string>${HOME}/actions-runner/_diag/launchagent-autorecover.out.log</string> |
| 41 | + <key>StandardErrorPath</key> |
| 42 | + <string>${HOME}/actions-runner/_diag/launchagent-autorecover.err.log</string> |
| 43 | +</dict> |
| 44 | +</plist> |
| 45 | +EOF |
| 46 | + |
| 47 | +launchctl bootout "gui/${UID_NUM}" "${PLIST_PATH}" >/dev/null 2>&1 || true |
| 48 | +launchctl bootstrap "gui/${UID_NUM}" "${PLIST_PATH}" |
| 49 | +launchctl enable "gui/${UID_NUM}/${LABEL}" || true |
| 50 | +launchctl kickstart -k "gui/${UID_NUM}/${LABEL}" || true |
| 51 | + |
| 52 | +echo "[mac-bridge-autorecover] installed: ${PLIST_PATH}" |
| 53 | +echo "[mac-bridge-autorecover] label: ${LABEL}" |
0 commit comments