1

RPI 3b+, Debian Stretch

I want to start a Qt applicaton via systemd. The app uses X and needs to open a display.

It always fails due to an Invalid MIT_MAGIC-COOKIE. But then systemd restarts it (on-failure) and it runs fine. ("Start APES Display Application is my Qt app--my grep picked up that "Light Display Manager has the same issue--fails first time, but succeeds on restart)

pi@right-display:~ $ cat /var/log/syslog | grep Display

Nov 16 10:43:26 right-display systemd[1]: Stopping Light Display Manager...

Nov 16 10:43:40 right-display systemd[1]: Started Start APES Display Application.

Nov 16 10:43:40 right-display systemd[1]: Starting Light Display Manager...

Nov 16 10:43:41 right-display x11vnc[653]: 16/11/2023 10:43:41 *** XOpenDisplay failed. No -display or DISPLAY.

Nov 16 10:43:41 right-display systemd[1]: Started Light Display Manager.

Nov 16 10:43:42 right-display APES_Display[572]: QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-pi' Nov 16 10:43:44 right-display APES_Display[572]: Invalid MIT-MAGIC-COOKIE-1 keyqt.qpa.screen: QXcbConnection: Could not connect to display :0 Nov 16 10:43:44 right-display APES_Display[572]: Could not connect to any X display.

Nov 16 10:43:44 right-display systemd[1]: Display.service: Main process exited, code=exited, status=1/FAILURE

Nov 16 10:43:44 right-display systemd[1]: Display.service: Unit entered failed state.

Nov 16 10:43:44 right-display systemd[1]: Display.service: Failed with result 'exit-code'.

Nov 16 10:43:45 right-display x11vnc[653]: 16/11/2023 10:43:45 *** XOpenDisplay of ":0" successful.

Nov 16 10:44:02 right-display systemd[1]: Display.service: Service hold-off time over, scheduling restart.

Nov 16 10:44:02 right-display systemd[1]: Stopped Start APES Display Application.

Nov 16 10:44:02 right-display systemd[1]: Started Start APES Display Application.

Nov 16 10:44:02 right-display APES_Display[1307]: QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-pi'

So, there must be some service that must be running before my app can open a display? Or, do I need to create a "magic cookie" that seems to only be needed at boot time (starting the service manually always works)

How do I figure figure out what it is?

MC68020
  • 7,981
  • Does this help? https://superuser.com/questions/759759/writing-a-service-that-depends-on-xorg – nneonneo Nov 25 '23 at 11:21
  • Some other reading... https://unix.stackexchange.com/questions/360537/cant-run-application-that-depends-on-x-as-a-systemd-service https://askubuntu.com/questions/1274402/run-a-command-at-startup-with-lightdm – nneonneo Nov 25 '23 at 11:23

1 Answers1

-1

Probably the best is to create a systemd timer which will wait several seconds so until the display is operational and to make your service dependent on this timer. OnBootSec= is the timer option that should be used. From what we can see, the first failure appears between Starting LDM & Started LDM.

admstg
  • 684
  • 1
    I'm pretty sure I can make it work by adding a delay, but wouldn't it be better to add an After=unit so that there isn't a race condition? The whole reason I'm switching to use systemd instead of starting using LXDE autostart is to eliminate race conditions that seem to cause sporadic issues. – Dave Thomas Nov 16 '23 at 16:54