Skip to content

Instantly share code, notes, and snippets.

@scottzach1
Last active July 15, 2024 21:37
Show Gist options
  • Save scottzach1/e311654b7fe7115ba077016a5dc7b35d to your computer and use it in GitHub Desktop.
Save scottzach1/e311654b7fe7115ba077016a5dc7b35d to your computer and use it in GitHub Desktop.
Bash script to configure multiple Self-hosted GitHub Runners
#!/bin/bash
# _ _ _ _
# ___ ___ ___ | |_| |_ ______ _ ___| |__ / |
# / __|/ __/ _ \| __| __|_ / _` |/ __| '_ \| |
# \__ \ (_| (_) | |_| |_ / / (_| | (__| | | | |
# |___/\___\___/ \__|\__/___\__,_|\___|_| |_|_|
#
# Zac Scott (github.com/scottzach1)
#
# A quick and hacky script to configure n self-hosted GitHub runners.
# * Gist https://gist.github.com/scottzach1/e311654b7fe7115ba077016a5dc7b35d
# * Adapted from https://github.com/orgs/community/discussions/26769#discussioncomment-3539575
if [ "$EUID" -ne 0 ]
then
echo "Please run as root"
exit 1;
fi
set -e
export NAME=__fill_me_in__
export TOKEN=__fill_me_in__
export REPOSITORY=__fill_me_in__
export COUNT=5
export VERSION=2.317.0
for i in $(seq 1 $COUNT);
do
user="runner-$NAME-$i"
if [ ! -d "/home/$user" ] ; then
echo "Adding $user";
useradd -m -G sudo "$user";
else
echo "Using $user";
fi
cd "/home/$user" || exit 1;
mkdir -p actions-runner;
cd actions-runner || exit 1;
curl -o "actions-runner-linux-x64-$VERSION.tar.gz" -L "https://github.com/actions/runner/releases/download/v$VERSION/actions-runner-linux-x64-$VERSION.tar.gz";
tar xzf "./actions-runner-linux-x64-$VERSION.tar.gz";
chown -R "$user" ./
sudo -u "$user" bash -c "./config.sh --url '$REPOSITORY' --token '$TOKEN' --name '$NAME-$i' --unattended";
./svc.sh install "$user";
./svc.sh start "$user";
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment