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