@@ -273,80 +273,78 @@ The recommended ``buildbot.tac`` settings are:
273273* ``delete_leftover_dirs = 1 `` -- automatically cleans up build directories
274274 that the master no longer needs.
275275
276+ Service management
277+ ~~~~~~~~~~~~~~~~~~
278+
276279You will also want to make sure that the worker is started when the
277280machine reboots:
278281
279282.. tab :: Linux
280283
281- * For systemd based distributions, you can create a systemd unit file in order
282- to manage the service. Create the unit file named ``buildbot-worker.service ``
283- under ``/home/buildbot/.config/systemd/user/ `` and change the paths according to where the
284- buildbot-worker binary resides. You can verify its location by running
285- ``which buildbot-worker ``.
286- If you installed the buildbot-worker through
287- your package manager it would be::
288-
289- [Unit]
290- Description=Buildbot Worker
291- Wants=network-online.target
292- After=network-online.target local-fs.target
293-
294- [Service]
295- Type=forking
296- PIDFile=/home/buildbot/buildarea/twistd.pid
297- WorkingDirectory=/home/buildbot/buildarea
298- ExecStart=/usr/bin/buildbot-worker start
299- ExecReload=/usr/bin/buildbot-worker restart
300- ExecStop=/usr/bin/buildbot-worker stop
301- Restart=always
302- User=buildbot
303-
304- [Install]
305- WantedBy=multi-user.target
306-
307-
308- If you installed the buildbot-worker through pip, the systemd unit
309- file should look like this::
310-
311- [Unit]
312- Description=Buildbot Worker
313- Wants=network-online.target
314- After=network-online.target local-fs.target
315-
316- [Service]
317- Type=forking
318- PIDFile=/home/buildbot/buildarea/twistd.pid
319- WorkingDirectory=/home/buildbot/buildarea
320- ExecStart=/usr/local/bin/buildbot-worker start
321- ExecReload=/usr/local/bin/buildbot-worker restart
322- ExecStop=/usr/local/bin/buildbot-worker stop
323- Restart=always
324- User=buildbot
325-
326- [Install]
327- WantedBy=multi-user.target
328-
329-
330- Then enable lingering for the buildbot user via the
331- ``loginctl enable-linger buildbot `` command and you can start
332- the service through a login shell of the buildbot user
333- via the ``systemctl --user enable --now buildbot-worker.service ``
334- command.
335-
336- Note that using a systemd unit file, might produce some SELinux warnings on systems
337- where the enforcing mode is enabled, usually related to the ``twistd.pid `` file.
338- If the service fails to start, you should check the output of
339- ``systemctl status buildbot-worker.service `` as well as the
340- ``/var/log/audit/audit.log `` file (for example, through
341- ``sealert -a /var/log/audit/audit.log ``) for potential issues and remedies.
342-
343- * Alternatively you can create a cronjob. Add the following line to ``/etc/crontab ``::
344-
345- @reboot buildbot-worker restart /path/to/buildarea
346-
347- Note that we use ``restart`` rather than ``start`` in case a crash has
348- left a ``twistd.pid`` file behind.
349-
284+ If you installed via a distro package (Fedora, RHEL, CentOS, Debian,
285+ Ubuntu, or FreeBSD), the service was already enabled in the installation
286+ step above.
287+
288+ **Manual systemd setup (pip installs) **
289+
290+ If you installed via pip, you need to install a systemd unit yourself.
291+ The upstream buildbot project provides a
292+ `contributed template unit <https://github.com/buildbot/buildbot/blob/master/worker/contrib/systemd/buildbot-worker%40.service >`__
293+ along with
294+ `sysusers.d and tmpfiles.d configs <https://github.com/buildbot/buildbot/tree/master/common/contrib/systemd >`__.
295+
296+ Create ``/etc/systemd/system/buildbot-worker@.service `` with the
297+ following contents::
298+
299+ [Unit]
300+ Description=Buildbot Worker %I
301+ Documentation=man:buildbot-worker(1) https://docs.buildbot.net/
302+ After=network.target
303+ ConditionDirectoryNotEmpty=/var/lib/buildbot/worker/%i
304+ ConditionFileNotEmpty=/var/lib/buildbot/worker/%i/buildbot.tac
305+
306+ [Service]
307+ Type=simple
308+ User=buildbot-worker
309+ Group=buildbot-worker
310+ WorkingDirectory=/var/lib/buildbot/worker/
311+ StateDirectory=buildbot/worker
312+ ExecStart=/usr/local/bin/buildbot-worker start --nodaemon %I
313+ Restart=always
314+ ProtectSystem=full
315+ ProtectHome=yes
316+ PrivateDevices=yes
317+ PrivateTmp=yes
318+
319+ [Install]
320+ WantedBy=multi-user.target
321+
322+ Adjust ``User ``, ``Group ``, ``WorkingDirectory ``, and the
323+ ``ExecStart `` path to match your setup. Then::
324+
325+ systemctl daemon-reload
326+ systemctl enable --now buildbot-worker@WORKERNAME.service
327+
328+ **SysV init (non-systemd distros) **
329+
330+ For distros without systemd (such as Alpine Linux with OpenRC), upstream
331+ provides a
332+ `SysV init script <https://github.com/buildbot/buildbot/blob/master/worker/contrib/init-scripts/buildbot-worker.init.sh >`__
333+ with a
334+ `default configuration file <https://github.com/buildbot/buildbot/blob/master/worker/contrib/init-scripts/buildbot-worker.default >`__.
335+ Install these as ``/etc/init.d/buildbot-worker `` and
336+ ``/etc/default/buildbot-worker `` respectively, then configure the worker
337+ instances in the default file.
338+
339+ **Cronjob alternative **
340+
341+ If neither systemd nor a SysV init script is practical, you can use a
342+ cronjob. Add the following line to ``/etc/crontab ``::
343+
344+ @reboot buildbot-worker restart /path/to/workerdir
345+
346+ Note that ``restart `` is used rather than ``start `` in case a crash has
347+ left a ``twistd.pid `` file behind.
350348
351349.. tab :: macOS
352350
0 commit comments