Skip to content

Commit 0d59f31

Browse files
feat(mac-bridge): reboot auto-recover scripts (the unique value of #111)
#111 (Mac bridge M1) is otherwise already superseded by the bridge in main (main's manifest.py is a 3.8x superset). Cherry-pick only its two standalone, not-in-main artifacts: recover_runner_after_reboot.sh (self-heal the GitHub Actions runner after a Mac reboot) + install_autorecover_launchagent.sh. Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
1 parent 83315bd commit 0d59f31

2 files changed

Lines changed: 102 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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}"
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
# Self-heal the GitHub Actions runner after Mac reboot.
3+
#
4+
# Idempotent:
5+
# - if Runner.Listener is already alive: no-op
6+
# - else try svc.sh start (when service is installed)
7+
# - if service is not installed/usable, fall back to foreground run.sh
8+
# via nohup so bridge jobs can still execute.
9+
10+
set -euo pipefail
11+
12+
RUNNER_DIR="${RUNNER_DIR:-$HOME/actions-runner}"
13+
LOG_DIR="${RUNNER_LOG_DIR:-$HOME/actions-runner/_diag}"
14+
mkdir -p "$LOG_DIR"
15+
16+
log() { echo "[mac-bridge-recover] $*" >&2; }
17+
18+
if pgrep -f "Runner.Listener.*${RUNNER_DIR}" >/dev/null 2>&1; then
19+
log "Runner.Listener already running."
20+
exit 0
21+
fi
22+
23+
if [ ! -x "${RUNNER_DIR}/run.sh" ]; then
24+
log "runner not found at ${RUNNER_DIR}; skipping."
25+
exit 0
26+
fi
27+
28+
if [ -x "${RUNNER_DIR}/svc.sh" ] && "${RUNNER_DIR}/svc.sh" status 2>/dev/null | grep -q "installed"; then
29+
log "service installed; attempting svc.sh start"
30+
if "${RUNNER_DIR}/svc.sh" start >/dev/null 2>&1; then
31+
sleep 2
32+
if pgrep -f "Runner.Listener.*${RUNNER_DIR}" >/dev/null 2>&1; then
33+
log "runner started via service."
34+
exit 0
35+
fi
36+
fi
37+
log "service start did not bring up listener, falling back to run.sh"
38+
fi
39+
40+
ts="$(date +%Y%m%d_%H%M%S)"
41+
nohup "${RUNNER_DIR}/run.sh" >"${LOG_DIR}/runner-nohup-${ts}.log" 2>&1 &
42+
sleep 2
43+
if pgrep -f "Runner.Listener.*${RUNNER_DIR}" >/dev/null 2>&1; then
44+
log "runner started via nohup run.sh fallback."
45+
exit 0
46+
fi
47+
48+
log "failed to start runner listener."
49+
exit 1

0 commit comments

Comments
 (0)