Skip to main content

GitHub Self-Hosted Runner Setup on Ubuntu with systemctl Service

This guide provides steps to set up a GitHub self-hosted runner on an Ubuntu server and run it as a service using systemctl.

Prerequisites

  • Ubuntu server with root or sudo access.
  • GitHub repository or organization where the runner will be connected.
  • A GitHub personal access token with the necessary permissions to add self-hosted runners.

Step 1: Download and Configure the GitHub Runner

  1. Create a directory for the runner:
  2. Download the GitHub runner binary: Replace REPO_OWNER and REPO_NAME with the owner and repository names, or use your organization name if you’re adding a runner to an organization.
  3. Extract the runner:
  4. Configure the runner: You can find the registration token in the GitHub repository or organization settings under Settings > Actions > Runners.

Step 2: Create the run.sh Script

  1. Create run.sh to ensure the runner restarts automatically in case of failure.
  2. Add the following content to run.sh:
  3. Make run.sh executable:

Step 3: Set Up systemctl Service

  1. Create a new systemd service file for the runner:
  2. Add the following configuration to the service file:
    Replace $USER with your actual username or use $USER if applicable in this context. NOTE: Github runner cannot be run as root
  3. Reload the systemd daemon to recognize the new service:
  4. Enable and start the service:
  5. Verify the runner is active:
    You should see an “active (running)” status if the service is correctly set up.

Step 4: Confirm Runner Connection in GitHub

Go to your GitHub repository or organization settings under Settings > Actions > Runners to check if the runner is connected and ready.

Managing the GitHub Runner Service

  • Start the service: sudo systemctl start github-runner
  • Stop the service: sudo systemctl stop github-runner
  • Restart the service: sudo systemctl restart github-runner
  • Check service status: sudo systemctl status github-runner

Troubleshooting

  • Check the runner logs:
  • Make sure your GitHub registration token is up to date.

Unregistering the Runner

If you need to unregister the runner, stop the service and remove it:
  1. Stop the service:
  2. Remove the service:
  3. Unregister the runner in GitHub:
  4. Clean up by deleting the runner directory: