How To Create Systemd Unit Files for Buildbot

Introduction

Buildbot is a Python-based continuous integration system for automating software build, test, and release processes. In the prerequisite tutorial, How To Install Buildbot on Ubuntu 16.04, we created a buildbot user and group, installed the buildmaster in /home/buildbot/master and the worker in /home/buildbot/worker, then manually started the processes the new user.

In this tutorial, we'll create systemd unit files so that the server's init system can manage the Buildbot processes.

Prerequisites

One Ubuntu 16.04 server with at least 1 GB of RAM, configured with a non-root sudo user and a firewall by following the Ubuntu 16.04 initial server setup guide with Buildbot installed and configured using the following guide:

Step 1 — Stopping the Running Services

First, if you're still logged in as the buildbot user from the previous tutorial, type exit to return to the sudo user.

As the sudo user, we'll make sure that the Buildmaster is stopped:

sudo buildbot stop /home/buildbot/master

Then, we'll ensure the worker is stopped as well:

sudo buildbot-worker stop /home/buildbot/worker

In each case, we'll get feedback that buildbot process 1234 is dead, (showing the Process ID that was stopped) or buildmaster not running, which indicates the service wasn't running in the first place.

Step 2 — Creating the Buildmaster Unit File

Next, we’ll create and open a file named buildbot-master.service:

sudo nano /etc/systemd/system/buildbot-master.service

In the [Unit] section we’ll add a description and require that networking must be available before starting the service. In the [Service] section, we’ll specify that the process runs as the buildbot user and group we created, define the working directory, and provide the commands that should be used to start or reload the master. Finally, in the [Install] section, we’ll indicate that it should start as part of the the multi-user target at boot:

Created symlink from /etc/systemd/system/multi-user.target.wants/buildbot-master.service to /etc/systemd/system/buildbot-master.service.

Now that the buildmaster is set up, we'll add the worker.

Step 3 — Creating the Worker Unit File

We’ll create and open a file called buildbot-worker.service which is configured like buildbot-master.service but with the values needed to start the worker. In the [Install] section, we’ll use set theWantedBy key to the buildbot-master.service so the worker will be started after the buildmaster.