Skip to content

Commit 1e64b55

Browse files
Stefan WiehlerEmantor
authored andcommitted
contrib/systemd: add systemd services
Signed-off-by: Stefan Wiehler <stefan.wiehler@missinglinkelectronics.com>
1 parent 0969865 commit 1e64b55

File tree

5 files changed

+103
-1
lines changed

5 files changed

+103
-1
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[Unit]
2+
Description=Labgrid Coordinator
3+
After=network.target
4+
5+
[Service]
6+
ExecStart=/path/to/labgrid-coordinator/venv/bin/crossbar start --logformat=syslogd --cbdir /var/lib/labgrid-coordinator --config /etc/labgrid/coordinator.yaml
7+
ExecStop=/usr/bin/labgrid-coordinator stop --cbdir /var/lib/labgrid-coordinator
8+
Restart=on-abort
9+
DynamicUser=yes
10+
StateDirectory=labgrid-coordinator
11+
12+
[Install]
13+
WantedBy=multi-user.target
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[Unit]
2+
Description=Labgrid Exporter
3+
After=network.target
4+
5+
[Service]
6+
ExecStart=/path/to/labgrid/venv/bin/labgrid-exporter /etc/labgrid/exporter.yaml
7+
Restart=on-abort
8+
User=labgrid
9+
Group=labgrid
10+
# Adjust to your distribution (most often "dialout" or "tty")
11+
SupplementaryGroups=dialout
12+
CacheDirectory=labgrid
13+
CacheDirectoryMode=1775
14+
15+
[Install]
16+
WantedBy=multi-user.target
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Type Name ID GECOS Home directory Shell
2+
u labgrid - "Labgrid"

contrib/systemd/tmpfiles.d/labgrid.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
# it is advised to at least change the group from the default for your
44
# environment
55
# Path Mode UID GID Age Argument
6-
d /var/cache/labgrid 1775 root users 2d
6+
d /var/cache/labgrid 1775 labgrid labgrid 2d

doc/getting_started.rst

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ same machine. The client is used to access functionality provided by an
176176
exporter. Over the course of this tutorial we will set up a coordinator and
177177
exporter, and learn how to access the exporter via the client.
178178

179+
.. _remote-getting-started-coordinator:
180+
179181
Coordinator
180182
~~~~~~~~~~~
181183

@@ -327,6 +329,75 @@ See :ref:`remote-usage` for some more advanced features.
327329
For a complete reference have a look at the :doc:`labgrid-client(1) <man/client>`
328330
man page.
329331

332+
Systemd files
333+
~~~~~~~~~~~~~
334+
335+
Labgrid comes with several systemd files in :file:`contrib/systemd`:
336+
337+
- service files for coordinator and exporter
338+
- tmpfiles.d file to regularly remove files uploaded to the exporter in
339+
:file:`/var/cache/labgrid`
340+
- sysusers.d file to create the ``labgrid`` user and group, enabling members of
341+
the ``labgrid`` group to upload files to the exporter in :file:`/var/cache/labgrid`
342+
343+
Follow these instructions to install the systemd files on your machine(s):
344+
345+
#. Copy the service, tmpfiles.d and sysusers.d files to the respective
346+
installation paths of your distribution.
347+
#. Adapt the ``ExecStart`` paths of the service files to the respective Python
348+
virtual environments of the coordinator and exporter.
349+
#. Create the coordinator configuration file referenced in the ``ExecStart``
350+
option of the :file:`systemd-coordinator.service` file by using
351+
:file:`.crossbar/config.yaml` as a starting point. You most likely want to
352+
make sure that the ``workdir`` option matches the path given via the
353+
``--cbdir`` option in the service file; see
354+
:ref:`remote-getting-started-coordinator` for further information.
355+
#. Adjust the ``SupplementaryGroups`` option in the
356+
:file:`labgrid-exporter.service` file to your distribution so that the
357+
exporter gains read and write access on TTY devices (for ``ser2net``); most
358+
often, this group is called ``dialout`` or ``tty``.
359+
#. Set the coordinator URL the exporter should connect to by overriding the
360+
exporter service file; i.e. execute ``systemctl edit
361+
labgrid-exporter.service`` and add the following snippet:
362+
363+
.. code-block::
364+
365+
[Service]
366+
Environment="LG_CROSSBAR=ws://<your-host>:<your-port>/ws"
367+
368+
#. Create the ``labgrid`` user and group:
369+
370+
.. code-block:: console
371+
372+
# systemd-sysusers
373+
374+
#. Reload the systemd manager configuration:
375+
376+
.. code-block:: console
377+
378+
# systemctl daemon-reload
379+
380+
#. Start the coordinator, if applicable:
381+
382+
.. code-block:: console
383+
384+
# systemctl start labgrid-coordinator
385+
386+
#. After creating the exporter configuration file referenced in the
387+
``ExecStart`` option of the :file:`systemd-exporter.service` file, start the
388+
exporter:
389+
390+
.. code-block:: console
391+
392+
# systemctl start labgrid-exporter
393+
394+
#. Optionally, for users being able to upload files to the exporter, add them
395+
to the `labgrid` group on the exporter machine:
396+
397+
.. code-block:: console
398+
399+
# usermod -a -G labgrid <user>
400+
330401
.. _udev-matching:
331402

332403
udev Matching

0 commit comments

Comments
 (0)