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.
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.