1

I wrote a Python script that requests video frames from an nginx RTMP server. If that request comes back as an empty byte string, the VLC / FFMPEG process should be terminated and libreoffice should be showed with an Impress slide presentation. This Python script works perfectly from a terminal, but when executed from systemd, the libreoffice part of it fails.

Running htop shows the command that was executed to run libreoffice: soffice --impress --norestore -invisible --show test.pptx.

Of course, nothing is actually shown to the screen. The only error that I have been seeing is an error that states Can't get display

Here is my unit file:

[Unit]
Description=Polls the RTMP Server for a valid video feed
Wants=network-online.target
After=network-online.target

[Service]
ExecStartPre=/bin/sleep 10
ExecStart=/usr/bin/python3 -u /home/pi/stream_script/launch_stream.py
Restart=always
User=pi

[Install]
WantedBy=multi-user.target

I used the following line of code in my Python script to launch VLC

# Show the stream
vlc_process = subprocess.Popen("cvlc --fullscreen --avcodec-threads=0 " + STREAM, stdout=subprocess.PIPE, shell=True,  preexec_fn=os.setsid)

and the following to kill the process

os.killpg(os.getpgid(vlc_process.pid), signal.SIGTERM)  # Send the signal to all the process groups

I am certainly no expert with systemd, but I have used it numerous times before without an issue - but never with graphical applications. Does systemd not have access to a graphical resource?

I apologize if this is a relatively simple problem... I messed with it for days and could not come up with a solution. Most things I research related to the error I described above were about headless libreoffice operations.

1 Answer 1

1

This would work as a user service (at least one started manually or by other means only after login) but not as a system service.

$ systemctl show-environment
LANG=de_DE.UTF-8
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

$ systemctl --user show-environment
HOME=/home/hl
LANG=de_DE.UTF-8
LOGNAME=hl
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
SHELL=/bin/bash
USER=hl
XDG_RUNTIME_DIR=/run/user/1000
XDG_DATA_DIRS=/home/hl/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
DISPLAY=:0
XAUTHORITY=/home/hl/.Xauthority
3
  • Can you elaborate a little more? Is there something else I could use to accomplish my task? I just want it to start on boot and restart the process if it stops. Jun 12, 2020 at 15:33
  • @brettsalyer A process accessing X needs DISPLAY and XAUTHORITY. And that user must have access to X, of course. Maybe a virtual X server is helpful in your case. That would avoid the need for a login. Jun 12, 2020 at 15:37
  • Of course, that makes sense. Thank you for that clarification! Jun 12, 2020 at 15:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .