Systemd units for Buildbot in Conda

Buildbot is a Python framework for continuous integration systems. In my research group we are deploying it in a Conda environment, which we also use to manage all the different moving parts of our Python-centric control infrastructure on both Windows and Linux. To start up the master and worker services, the corresponding Conda environment needs to be activated first. This is easiest to achieve using simple wrapper scripts.

For this, let’s assume we’ve created a bb user, with the master and worker configurations in its home directory (~/master and ~/worker). First, create a wrapper script to start up the master process:

#!/bin/bash
set -eo pipefail

export PATH=~/anaconda3/bin:$PATH
source activate buildbot
buildbot start --nodaemon master
~bb/start-master.sh

This assumes Conda has been installed into ~bb/anaconda3, and the environment with the Buildbot installation is called buildbot. master is the name of the configuration directory, and --nodaemon prevents daemonisation (i.e. keeps the process running in the foreground).

Make the script executable, and create a Systemd unit file that invokes it:

[Unit]
Description=Buildbot master service
After=network.target

[Service]
User=bb
Group=bb
WorkingDirectory=/home/bb
ExecStart=/home/bb/start-master.sh
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
/etc/systemd/system/buildbot-master.service

To start the master process, run

systemctl start buildbot-master

and to do so every time the system boots:

systemctl enable buildbot-master

The analogous configuration for the worker process is

#!/bin/bash
set -eo pipefail

export PATH=~/anaconda3/bin:$PATH
source activate buildbot
buildbot-worker start --nodaemon worker
~bb/start-worker.sh

and

[Unit]
Description=Buildbot worker service
After=network.target

[Service]
User=bb
Group=bb
WorkingDirectory=/home/bb
ExecStart=/home/bb/start-worker.sh
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
/etc/systemd/system/buildbot-worker.service

Start it using

systemctl enable buildbot-worker
systemctl start buildbot-worker

This is it; Buildbot is now run automatically when the system boots. To avoid starting the graphical user interface on a desktop Ubuntu install, run systemctl set-default multi-user.target.