Score:0

Launch GUI on startup and launch it again if failed (Systemd VS Cron)

pk flag

I have a python application that I need to be launched on Ubuntu startup I would like also that application to be launched again if it closes/crashes. That is something that Systemd can handle, but the problem is that my application open a window with the camera streaming. Because of that, a systemd service throw errors:

nov 21 19:42:54 Xavier-AGX env[14289]: 2021-11-21 19:42:54,558 Connected to mysql server: X.X.X.X
nov 21 19:42:55 Xavier-AGX env[14289]: qt.qpa.xcb: could not connect to display
nov 21 19:42:55 Xavier-AGX env[14289]: qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/atc/.local/lib/python3.6/site-packages/cv2/qt/plugins" even though it was found.
nov 21 19:42:55 Xavier-AGX env[14289]: This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
nov 21 19:42:55 Xavier-AGX env[14289]: Available platform plugins are: xcb.
nov 21 19:42:56 Xavier-AGX systemd[1]: app_cam0.service: Main process exited, code=dumped, status=6/ABRT
nov 21 19:42:56 Xavier-AGX systemd[1]: app_cam0.service: Failed with result 'core-dump'.
nov 21 19:42:57 Xavier-AGX systemd[1]: app_cam0.service: Service hold-off time over, scheduling restart.
nov 21 19:42:57 Xavier-AGX systemd[1]: app_cam0.service: Scheduled restart job, restart counter is at 3.
nov 21 19:42:57 Xavier-AGX systemd[1]: Stopped Service to launch the app (Camera 0).
nov 21 19:42:57 Xavier-AGX systemd[1]: Started Service to launch the app (Camera 0).

An alternative is to use CRON. There is a flag (@reboot), that makes CRON run your app at boot time, but in case the app crashes, it will not launch it again. :(

So, what can I do ?

Is there any solution to run a GUI app as a systemd service?

Thanks in advance.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.