Skip to content

Instantly share code, notes, and snippets.

@nitrag
Created May 2, 2022 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nitrag/e7854b55a97fd7df6dfab34a86a77773 to your computer and use it in GitHub Desktop.
Save nitrag/e7854b55a97fd7df6dfab34a86a77773 to your computer and use it in GitHub Desktop.
Script to install multiple github runners
#!/bin/bash
set -e
# Set the number of runners to create at the bottom of script
# Required ENV:
# export MACHINE_NAME=whimby
# export GITHUB_PERSONAL_ACCESS_TOKEN=xxxx
# export RUNNER_LABELS=self-hosted,Linux,X64
install_github_runner() {
RUNNER_NAME=$1
USER=$(who am i | awk '{print $1}')
FOLDER=/home/$USER/actions-runner-$RUNNER_NAME
mkdir $FOLDER && cd $FOLDER
LATEST_VERSION=$(curl -I -v -s https://github.com/actions/runner/releases/latest 2>&1 | perl -ne 'next unless s/^< location: //; s{.*/v}{}; s/\s+//; print')
curl -sL https://github.com/actions/runner/releases/download/v$LATEST_VERSION/actions-runner-linux-x64-$LATEST_VERSION.tar.gz \
-o actions-runner-linux-x64-$LATEST_VERSION.tar.gz
tar xzf ./actions-runner-linux-x64-$LATEST_VERSION.tar.gz
export RUNNER_ALLOW_RUNASROOT=1
export DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1
DATE=$(date '+%Y%m%d')
HASH=$(openssl rand -hex 2)
echo "Runner Labels: $RUNNER_LABELS"
ACTIONS_RUNNER_INPUT_TOKEN=$(curl -s -X POST -H "Authorization: token $GITHUB_PERSONAL_ACCESS_TOKEN" -H 'Accept: application/vnd.github.v3+json' https://api.github.com/orgs/pointivo/actions/runners/registration-token | jq -r .token)
echo "Github Registration Token: $ACTIONS_RUNNER_INPUT_TOKEN"
./config.sh --unattended --url https://github.com/Pointivo --token "$ACTIONS_RUNNER_INPUT_TOKEN" --name "$MACHINE_NAME-runner-$DATE-$RUNNER_NAME-$HASH" --labels "$RUNNER_LABELS"
sudo ./svc.sh install
cd .. && chown -R $USER:$USER $FOLDER
# Add cleanup to cron
cd /tmp
touch mycrontab
crontab -l > mycrontab || true
MINUTE=$(printf '%02d\n' $((1 + RANDOM % 10)))
echo "${MINUTE} 05 * * * rm -rf /home/$USER/actions-runner-${RUNNER_NAME}/_work/_temp/* || echo 'true' " >> mycrontab
crontab mycrontab
rm mycrontab
}
install_github_runner alpha
install_github_runner beta
install_github_runner charlie
install_github_runner delta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment