0

I'm trying to run a python GUI application as a service. The application is using PyQt5 and python-vlc packages. I have the following service file:

[Unit]
Description="Python VLC Service Test"
After=multi-user.target

[Service]
Type=simple
User=pi
Environment="DISPLAY=:0"
Environment="XAUTHORITY=/home/pi/.Xauthority"
ExecStart=/usr/bin/python3 /opt/experimental/vlc_pyqt.py
Restart=on-failure

[Install]
WantedBy=graphical.target

However, when playing video in the vlc window, only white screen shows up. After looking in journalctl I found these two errors:

Aug 18 16:26:27 raspberrypi python3[17754]: [83ab02c8] dbus_screensaver inhibit error: cannot connect to session bus: Failed to connect to socket /tmp/dbus-ZeiFpFnTZO: Connection refused

Aug 18 16:26:33 raspberrypi python3[17754]: [84f28b10] mmal_codec filter error: Failed to alloc CMA buf: fmt=Z420, size=3133440

I think the CMA buffer error is a result of the first one. Any ideas how to fix it? The application is running just fine when run directly (not as a service).

I would like to run it as a service in order to be able to monitor the status of the application via systemctl status vlc_pyqt.service as the application should run all the time on the machine and to be able to gracefully restart it by systemctl restart vlc_pyqt.service if needed.

7
  • 1
    Possibly because the X display on :0 doesn't belong to pi before anyone logs in (running a service as a specific user does not involve a login) -- although why it opens the app at all then I dunno.
    – goldilocks
    Aug 18, 2021 at 15:37
  • Thanks for your comment, I am already logged in as the pi user when testing this. I tried to run sudo systemctl --user start vlc_test.service but got Aug 23 18:52:51 raspberrypi systemd[574]: vlc_test.service: Failed with result 'exit-code'. Any ideas how to fix this? I could not find anything explaining what could have gone wrong
    – Kwigon
    Aug 23, 2021 at 16:54
  • Do you have any logging in vlc_pyqt.py? If not, do not pass go, do not collect $200, etc. systemclt status ... may give a bit more information. There's kind of a pseudo/semi XY problem here, in that it's hard to see why you want to run this as a service. If it's because you want it to run at boot, this is probably a bad method; you should use autostart via the DE. If you are trying to get it to run at boot, then it seems completely pointless.
    – goldilocks
    Aug 24, 2021 at 15:43
  • I would like to run it as a service to be able to monitor the status of the application via systemctl status vlc_pyqt.service as the application should run all the time on the machine and be able to gracefully restart it by systemctl restart vlc_pyqt.service if needed. I will add it the explanation the question. Regarding logging: systemctl status showed only the last few messages and no more than journalctl I mentioned in the question. Those two errors do not happen when I run it the standard way. I will post a complete log from the vlc in a few hours.
    – Kwigon
    Aug 25, 2021 at 14:25
  • "I would like to run it as a service to be able to monitor the status of the application via systemctl status vlc_pyqt.service" -> This is a bad reason. Whatever you are trying to accomplish with that should be done by incorporating proper logging and controls in the application.
    – goldilocks
    Aug 26, 2021 at 14:09

1 Answer 1

0

I encountered a similar issue when trying to run VLC from a systemd unit with mmal-codec output.

Thanks to this answer I was able to make it work :

https://forum.videolan.org/viewtopic.php?t=154020#p505537

If that's an option for you, you can put the systemd unit file in '~/.config/systemd/user/', making sure to remove the User= and Environment= directives, so with your example :

[Unit]
Description="Python VLC Service Test"
After=multi-user.target

[Service]
Type=simple
ExecStart=/usr/bin/python3 /opt/experimental/vlc_pyqt.py
Restart=on-failure

[Install]
WantedBy=graphical.target

then after that, reload the daemon, enable/start the service with

systemctl --user daemon-reload
systemctl --user enable yourservicefilename.service
systemctl --user  start yourservicefilename.service

Hope it resolves the problem for you, or can help someone out there !

EDIT: Here is my unit file for running VLC as a service with http interface :

[Unit]
Description=VLC http service

[Service]
WorkingDirectory=/home/pi/
ExecStart=/usr/bin/cvlc -I http --no-osd --http-password=foo --http-host=127.0.0.1 --http-port=8000
Restart=always

[Install]
WantedBy=default.target

Notice that in the WantedBy= directive, I used 'default.target' as I'm on a cli environment ( no gui/desktop ). Also notice the absence of After= directive in the '[Unit]' section. If you find that your service does not auto-start at boot, you should check these as it's probably due to one of those conditions not being met.

Source : https://bbs.archlinux.org/viewtopic.php?id=250813

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.