Last active
August 31, 2025 18:59
-
-
Save Kyle-Ye/eaece97877ae4ad1257a1a1dfe5d337d to your computer and use it in GitHub Desktop.
macOS Launch Agent for GitHub Actions Runner - Automatically runs ./run.sh in background at bootup with auto-restart and logging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>com.github.actions-runner</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/bin/bash</string> | |
<string>/Users/kyle/actions-runner/run.sh</string> | |
</array> | |
<key>WorkingDirectory</key> | |
<string>/Users/kyle/actions-runner</string> | |
<key>RunAtLoad</key> | |
<true/> | |
<key>KeepAlive</key> | |
<true/> | |
<key>StandardOutPath</key> | |
<string>/tmp/actions-runner.log</string> | |
<key>StandardErrorPath</key> | |
<string>/tmp/actions-runner.error.log</string> | |
<key>EnvironmentVariables</key> | |
<dict> | |
<key>PATH</key> | |
<string>/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string> | |
<key>HOME</key> | |
<string>/Users/kyle</string> | |
</dict> | |
</dict> | |
</plist> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Colors for output | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
YELLOW='\033[1;33m' | |
NC='\033[0m' # No Color | |
echo "Setting up GitHub Actions Runner Launch Agent..." | |
# Check if run.sh exists | |
if [ ! -f "./run.sh" ]; then | |
echo -e "${RED}Error: run.sh not found in current directory${NC}" | |
exit 1 | |
fi | |
# Make run.sh executable | |
chmod +x ./run.sh | |
# Copy plist to LaunchAgents directory | |
PLIST_NAME="com.github.actions-runner.plist" | |
LAUNCH_AGENTS_DIR="$HOME/Library/LaunchAgents" | |
# Create LaunchAgents directory if it doesn't exist | |
mkdir -p "$LAUNCH_AGENTS_DIR" | |
# Copy the plist file | |
cp "$PLIST_NAME" "$LAUNCH_AGENTS_DIR/" | |
# Load the launch agent | |
launchctl load "$LAUNCH_AGENTS_DIR/$PLIST_NAME" 2>/dev/null | |
# Start the service | |
launchctl start com.github.actions-runner | |
echo -e "${GREEN}Launch agent installed successfully!${NC}" | |
echo "" | |
echo "The GitHub Actions runner will now:" | |
echo " • Start automatically at boot" | |
echo " • Restart if it crashes" | |
echo " • Log output to /tmp/actions-runner.log" | |
echo " • Log errors to /tmp/actions-runner.error.log" | |
echo "" | |
echo "Useful commands:" | |
echo " View status: launchctl list | grep com.github.actions-runner" | |
echo " Stop: launchctl stop com.github.actions-runner" | |
echo " Unload: launchctl unload ~/Library/LaunchAgents/$PLIST_NAME" | |
echo " View logs: tail -f /tmp/actions-runner.log" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment