Skip to content

Commit f957d20

Browse files
contrib/systemd/labgrid-exporter: improve service
The labgrid exporter needs to talk to the coordinator (crossbar), so start after the network-online.target instead of after the network.target. Also add a weak requirement for that target to make sure it is actually started. Adding `PYTHONUNBUFFERED=1` [1] to the environment forces the stdout and stderr streams to be unbuffered, so all logs end up in the journal instantly. Try to read environment variables from `/etc/environment`. This is the place where `LG_CROSSBAR` should be defined. Don't fail if that file does not exist, though. Soften the restart criteria by using `on-failure` instead of `on-abort`, which covers more failure scenarios, see [2]. The exporter exits with exit code 100 if it loses the connection to the coordinator. While this is already covered by `on-failure`, add it nonetheless for documentation purposes and users that might adjust `Restart=`. Also increase the time to sleep before restarting the exporter on failure to prevent system load on failure loops. Replace explicit `User=`/`Group=` by `DynamicUser=yes`. The labgrid user might not exist and there is no requirement for a specific user anyway. Since the exporter does not write any state, drop `CacheDirectory=`/`CacheDirectoryMode=` altogether. The caching directories on the exporter host are created by labgrid's `contrib/systemd/tmpfiles.d/labgrid.conf`. This directory is used by labgrid's ManagedFile, which is not part of the exporter. [1] https://docs.python.org/3/using/cmdline.html#envvar-PYTHONUNBUFFERED [2] https://www.freedesktop.org/software/systemd/man/systemd.service.html#Restart= Signed-off-by: Bastian Krause <[email protected]> (cherry picked from commit 0a2deef)
1 parent 8e831f9 commit f957d20

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed
+9-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
[Unit]
22
Description=Labgrid Exporter
3-
After=network.target
3+
After=network-online.target
4+
Wants=network-online.target
45

56
[Service]
7+
Environment="PYTHONUNBUFFERED=1"
8+
# Should contain LG_CROSSBAR configuration
9+
EnvironmentFile=-/etc/environment
610
ExecStart=/path/to/labgrid/venv/bin/labgrid-exporter /etc/labgrid/exporter.yaml
7-
Restart=on-abort
8-
User=labgrid
9-
Group=labgrid
11+
Restart=on-failure
12+
RestartForceExitStatus=100
13+
RestartSec=30
14+
DynamicUser=yes
1015
# Adjust to your distribution (most often "dialout" or "tty")
1116
SupplementaryGroups=dialout
12-
CacheDirectory=labgrid
13-
CacheDirectoryMode=1775
1417

1518
[Install]
1619
WantedBy=multi-user.target

0 commit comments

Comments
 (0)