Learn how to set up Azure DevOps Linux Runner as a systemd Service. Our DevOps Support team is here to help you with your questions and concerns.
How to Set up Azure DevOps Linux Runner as systemd Service
Azure DevOps offers a platform for managing and automating the development and CI/CD workflows.
Additionally, it offers the self-hosted agent feature, which allows us to run our pipelines on our machines.
In this blog, we will walk through the steps to configure a self-hosted Azure DevOps runner on an Ubuntu machine and set it up as a systemd service for smooth, automated operation.
Before we begin the configuration process, we require an active Microsoft account and an Azure account with an active subscription. Additionally, we need an Azure VM running Ubuntu 22.04. Also, generate a Personal Access Token (PAT) in Azure DevOps for authentication.
If you’re new to Azure DevOps, check out the benefits of Azure DevOps for more insights into how this platform can streamline your development processes.
An Overview:
How to Configure a Self-Hosted Azure DevOps Agent on Ubuntu
- First, head to this link: https://dev.azure.com/your_organization and sign in.
- Then, select Azure DevOps and then go to Organization Settings.
- Now, it is time to add a new Agent Pool. Go to the Agent Pools section, click “Add Pool,” and select “Self-Hosted” to create a new pool for the runner.
- When setting up the new Agent, select Linux as the operating system and copy the provided URL to download the agent.
- Then, log in to the Azure VM and install the Agent by SSHing into the Azure VM running Ubuntu and running these commands to download and set up the agent:
mkdir myagent && cd myagent
wget https://vstsagentpackage.azureedge.net/agent/3.242.1/vsts-agent-linux-x64-3.242.1.tar.gz
tar zxvf vsts-agent-linux-x64-3.242.1.tar.gz
./config.sh
- While configuring the agent, we will be prompted with the following questions:
- Enter server URL: `https://dev.azure.com/your_organization/
- Enter authentication type (press enter for PAT): Press enter to choose PAT (Personal Access Token).
- Enter personal access token: Paste the previously generated PAT here.
- Enter agent pool (press enter for default): Press enter to accept the default agent pool.
- Enter agent name (press enter for default): We can choose a name or press enter to accept the default `AZDevops-test-runner`.
For more information on managing access levels in Azure DevOps, you can check out our blog on Azure DevOps Access Levels.
- Now, let’s configure the agent to run as a service for persistent operation. Run the following commands:
sudo ./svc.sh install &
./runsvc.sh &
- To ensure that the agent runs automatically as a systemd service on boot, create a new service file by running the following command:
sudo nano /etc/systemd/system/MyTestAgent.service
Then, paste the following content into the file:
For more guidance on Azure DevOps service connections, check out our Azure DevOps Service Connections blog[Unit]
Description=Runner_AD
After=network.target
StartLimitIntervalSec=0
[Service]
User=azureuser
ExecStart=/home/azureuser/myagent/runsvc.sh
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=adrunner
[Install]
WantedBy=multi-user.target
. - Next, make sure your `runsvc.sh` script looks like this:
#!/bin/bash
# convert SIGTERM signal to SIGINT
trap 'kill -INT $PID' TERM INT
if [ -f ".path" ]; then
export PATH=`cat .path`
echo ".path=${PATH}"
fi
./externals/node20_1/bin/node --version
if [ $? == 0 ]; then
NODE_VER="node20_1"
else
NODE_VER="node16"
fi
./externals/"$NODE_VER"/bin/node ./bin/AgentService.js &
PID=$!
wait $PID
trap - TERM INT
wait $PID
- After configuring the service file, reload systemd to apply the new configuration:
sudo systemctl daemon-reload
sudo systemctl enable MyTestAgent.service
sudo systemctl start MyTestAgent.service
sudo systemctl status MyTestAgent.service
How to Update the Self-Hosted Agent
Keeping the Azure DevOps self-hosted agent up to date ensures we are using the latest features, improvements, and bug fixes. Here’s how to update the agent:
Azure DevOps will notify us if a newer version of the agent is available. However, we can manually check for updates on the Azure DevOps agent release page.
- Before updating, stop the agent service using:
sudo systemctl stop MyTestAgent.service
- Then, download the newest version of the agent:
wget https://vstsagentpackage.azureedge.net/agent/latest/vsts-agent-linux-x64-.tar.gz
- Next, extract the downloaded package:
tar zxvf vsts-agent-linux-x64-.tar.gz
- Then, re-run the agent configuration script to bind it to Azure DevOps:
./config.sh
- Once the new agent is configured, restart the service:
sudo systemctl start MyTestAgent.service
- Next, check the status of the agent to ensure it’s running correctly:
sudo systemctl status MyTestAgent.service
If you’re running into issues with agent registration, check out our Azure DevOps 403 Error troubleshooting guide.
Troubleshooting Tips for Azure DevOps Self-Hosted Agents
When setting up or managing Azure DevOps self-hosted agents, we may run into common issues. Here are some troubleshooting tips to help you out:
- If the agent fails to register with Azure DevOps, double-check the server URL and Personal Access Token (PAT) for correctness. Additionally, ensure the agent has internet access and can reach Azure DevOps endpoints. Furthermore, verify the firewall or proxy settings aren’t blocking the agent’s connection.
- If the agent isn’t accepting the PAT, confirm the PAT is valid and has the necessary permissions. Then, regenerate the PAT and reconfigure the agent if required.
- If the Agent service is not starting, verify that the service is installed and running. Use sudo systemctl status MyTestAgent.service to check its status.
Additionally, check the agent’s logs for errors. Logs can be found at /home/azureuser/myagent/_diag/.
Also, ensure that the user permissions are properly set to allow the agent to run as a service. - If the agent goes offline, restart the agent service using sudo systemctl restart MyTestAgent.service. Additionally, verify network connectivity and DNS settings to ensure the agent can successfully reach Azure DevOps.
For more detailed troubleshooting, our Azure DevOps Service Connection guide can offer additional insights.
[Need assistance with a different issue? Our team is available 24/7.]
Conclusion
With the above steps, you can easily configure and set up an Azure DevOps Self-Hosted Linux Runner as a systemd service on an Ubuntu machine.
In brief, our Support Experts demonstrated how to set up Azure DevOps Linux Runner as a systemd Service.
0 Comments