Run GitHub Runner as Service in Linux OS

GitHub Runner is a machine that executes the jobs defined in a GitHub Actions Workflow. Think of a workflow as a recipe, and the runner as the chef. The workflow, written in YAML, outlines a series of steps (jobs) that need to be performed, such as building, testing, or deploying your code. These workflows are mainly used for Continuous Integration (CI), Continuous Deployment (CD).Automated Infrastructure Management and Custom Automation tasks.

Contents

Types of GitHub Runners

There are 2 types of Runners. They are GitHub-Hosted Runners and Self-Hosted Runners.


GitHub-Hosted Runners: These are hosted and managed by GitHub in their cloud infrastructure and they provide a convenient and ready-to-use solution, ideal for standard workflows.Main advantages of the GitHub Hosted runners are quick setup and offers different machines with different operating systems as Runners.

Self-Hosted Runners: These the machines which we manage within our own infrastructure (Cloud or On-Premises). These machines offer greater customizations we can use specific hardware and specific or multiple versions of a Framework or SDK

Setting up a Self Hosted Runner

Step 1: To setup a Self Hosted Runner, go to the GitHub repository and click on Settings

Step 2: Then click on Actions –> Runners

Step 3: Then click on “New Self Hosted Runner”

Step 4: Then click on Linux for the OS Type and a set of commands will be displayed which we need to execute in our self hosted runner

Step 5: Go to the Linux machine where we need to setup a self hosted runner

Step 6: Execute the below command to dowload the Runner (Change the version of the Runner and make sure it’s always the latest)

curl -o actions-runner-linux-x64-2.322.0.tar.gz -L https://github.com/actions/runner/releases/download/v2.322.0/actions-runner-linux-x64-2.322.0.tar.gz

Step 7: Extract the Runner installer

tar xzf ./actions-runner-linux-x64-2.322.0.tar.gz

Step 8: Run the command and pass the token to setup the Runner

./config.sh --url https://github.com/xxxxx/xxxx --token xxxxxxxxx

Once we execute the commands the runner will setup as shown below

GitHub SelfHosted Runner

To start the runner, which is currently inactive, run the run.sh script. We want to ensure the GitHub Runner is always online, so we will run it as a service, not just as a temporary process.

Configuring the Runner Service

To run the runner as a service follow the steps mentioned below. The same steps can be used for different flavours of Linux namely Ubuntu, RedHat, AmazonLinux etc.,

Step 1: Go to the Runner Directory

Step 2: Execute the below command (This command will install a service for the runner and you can also mention the username in which you want to install the Runner)

sudo ./svc.sh install username

Step 3: Then execute the start command to start the Runner

 sudo ./svc.sh start

This will start the Runner as a service and you can see the status of service by executing the command “svc.sh status”

Scroll to Top