Skip to content

Commit

Permalink
Run runner as service
Browse files Browse the repository at this point in the history
  • Loading branch information
tcarmet committed Oct 5, 2023
1 parent a90e1f9 commit 33fc2d8
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions runner_manager/bin/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,38 @@ DOCKER_SERVICE_START="yes"

SSH_KEYS=${SSH_KEYS:-""}

function setup_service {
# When running the runner as a just-in-time runner, the runsvc.sh script
# is not created. Therefore we are manually creating it here.

echo "[Unit]
Description=GitHub Actions Runner
After=network.target
[Service]
ExecStart=/bin/bash /home/actions/actions-runner/bin/runsvc.sh --jitconfig \"${JIT_CONFIG}\"
User=actions
WorkingDirectory=/home/actions/actions-runner
KillMode=process
KillSignal=SIGTERM
TimeoutStopSec=5min
[Install]
WantedBy=multi-user.target" | sudo tee /etc/systemd/system/actions.runner.service

sudo systemctl daemon-reload
sudo chown -Rh actions:actions /home/actions/actions-runner

}

sudo groupadd -f docker
sudo useradd -m actions
sudo usermod -aG docker,root actions
sudo bash -c "echo 'actions ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers"
sudo -H -u actions bash -c 'mkdir -p /home/actions/.ssh'
sudo -H -u actions bash -c 'echo "${SSH_KEYS}" >> /home/actions/.ssh/authorized_keys'

if [[ ${LINUX_OS} == "ubuntu" ]]; then
if [[ ${LINUX_OS} == "ubuntu" ]] || [[ ${LINUX_OS} == "debian" ]]; then
sudo apt-get -y update
sudo DEBIAN_FRONTEND=noninteractive apt-get -y install apt-transport-https \
ca-certificates \
Expand Down Expand Up @@ -59,7 +83,7 @@ fi

if [[ ! ${LABELS} =~ "no-docker" ]]; then

if [[ ${LINUX_OS} == "ubuntu" ]]; then
if [[ ${LINUX_OS} == "ubuntu" ]] || [[ ${LINUX_OS} == "debian" ]]; then
sudo install -m 0755 -d /etc/apt/keyrings
sudo apt-get -y update
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
Expand Down Expand Up @@ -108,20 +132,12 @@ curl -L "${DOWNLOAD_URL}" -o "/tmp/${FILE}"
tar xzf /tmp/"${FILE}"
# install dependencies
sudo ./bin/installdependencies.sh
echo "[Unit]
Description={{Description}}
After=network.target

[Service]
ExecStart=/bin/bash {{RunnerRoot}}/runsvc.sh --jitconfig \"${JIT_CONFIG}\"
User={{User}}
WorkingDirectory={{RunnerRoot}}
KillMode=process
KillSignal=SIGTERM
TimeoutStopSec=5min
[Install]
WantedBy=multi-user.target" >/home/actions/actions-runner/bin/actions.runner.service.template

sudo chown -Rh actions:actions /home/actions/actions-runner
sudo -H -u actions bash -c "nohup /home/actions/actions-runner/run.sh --jitconfig \"${JIT_CONFIG}\" 2>/home/actions/actions-runner/logs &"
# check if systemctl is available
if [[ -x "$(command -v systemctl)" ]]; then
setup_service
sudo systemctl enable actions.runner.service
sudo systemctl start actions.runner.service
else
sudo -H -u actions bash -c "nohup /home/actions/actions-runner/run.sh --jitconfig \"${JIT_CONFIG}\" 2>/home/actions/actions-runner/logs &"
fi

0 comments on commit 33fc2d8

Please sign in to comment.