Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

[Solved] Custom Systemd services launching graphical applications with Wayland

Graphical Environments, Managers, Multimedia & Desktop questions.
Post Reply
Message
Author
User avatar
sylvain_48
Posts: 21
Joined: 2023-11-10 19:05
Been thanked: 1 time

[Solved] Custom Systemd services launching graphical applications with Wayland

#1 Post by sylvain_48 »

Hi everyone!

I launch a bash script from a systemd service. In order to run GUI apps in the script I set two environment variables in the service: DISPLAY and XAUTHORITY.

It works fine with KDE and X11.
But with Gnome and Wayland it doesn't work. If I set the XAUTHORITY variable with the value given by "printenv" it only works during the on-going session, but not after reboot. This value changed.
I've tried to set the WAYLAND_DISPLAY variable with no success.

Should I set other variables?

Thanks and Merry Christmas!
Sylvain
Last edited by sylvain_48 on 2023-12-25 09:11, edited 2 times in total.

lindi
Debian Developer
Debian Developer
Posts: 463
Joined: 2022-07-12 14:10
Has thanked: 1 time
Been thanked: 88 times

Re: Systemd and Wayland

#2 Post by lindi »

Is this a system or user service?

User avatar
sylvain_48
Posts: 21
Joined: 2023-11-10 19:05
Been thanked: 1 time

Re: Systemd and Wayland

#3 Post by sylvain_48 »

The service is launched by an udev rule in a system environment. But the service switches in an user environment:

Code: Select all

[Unit]
Description=Backup on MYDISK
ConditionPathExists=/dev/disk/by-label/MYDISK
OnSuccess=send_mails_now.service

[Service]
Type=oneshot
RemainAfterExit=no
User=sylvain
Group=sylvain

Environment="DISPLAY=:0"
Environment="XAUTHORITY=/home/sylvain/.Xauthority"
Environment="DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus"

ExecStart=/home/sylvain/.local/bin/rsync-MYDISK

[Install]
WantedBy=graphical.target
Last edited by sylvain_48 on 2023-12-24 17:56, edited 1 time in total.

User avatar
sylvain_48
Posts: 21
Joined: 2023-11-10 19:05
Been thanked: 1 time

Re: Systemd and Wayland

#4 Post by sylvain_48 »

Ok, I've solved the issue...
If Wayland is used, the environment variable XAUTHORITY must be updated in the script launched by the service.
In this case the new value of this variable is a file : /run/user/<user uid>/.mutter-Xwaylandauth.*. The end is a hash that changes after each reboot.

Aki
Global Moderator
Global Moderator
Posts: 3082
Joined: 2014-07-20 18:12
Location: Europe
Has thanked: 76 times
Been thanked: 418 times

Re: Systemd and Wayland

#5 Post by Aki »

Hello,
sylvain_48 wrote: 2023-12-24 17:55 Ok, I've solved the issue...
If Wayland is used, the environment variable XAUTHORITY must be updated in the script launched by the service.
In this case the new value of this variable is a file : /run/user/<user uid>/.mutter-Xwaylandauth.*. The end is a hash that changes after each reboot.
I would suggest to modify the subject of the first post of the discussion to make more informative to other forum viewers; for example from:
  • "[Solved] Systemd and Wayland"
to:
  • "[Solved] Custom Systemd services launching graphical applications with Wayland"
⢀⣴⠾⠻⢶⣦⠀
⣾⠁⢠⠒⠀⣿⡁ Debian - The universal operating system
⢿⡄⠘⠷⠚⠋⠀ https://www.debian.org
⠈⠳⣄⠀

lindi
Debian Developer
Debian Developer
Posts: 463
Joined: 2022-07-12 14:10
Has thanked: 1 time
Been thanked: 88 times

Re: [Solved] Systemd and Wayland

#6 Post by lindi »

You should not hardcode DISPLAY to :0. Your system can hvae multiple users. Starting gui applications from system service sounds very wrong to me. Why don't you make it a user service?

User avatar
sylvain_48
Posts: 21
Joined: 2023-11-10 19:05
Been thanked: 1 time

Re: [Solved] Systemd and Wayland

#7 Post by sylvain_48 »

lindi wrote: 2023-12-24 18:54 You should not hardcode DISPLAY to :0. Your system can have multiple users.
I don't know much about the values DISPLAY can take. I've tried to find explanations about this without success. So I simply copy the "printenv" value for DISPLAY.
What do you suggest ?
lindi wrote: 2023-12-24 18:54 Starting gui applications from system service sounds very wrong to me. Why don't you make it a user service?
In fact, the service is launched when a USB disk is plugged, which is detected by a udev rule, as root. (see here : [Solved] Systemd : path and service units.)
I didn't find the way to do this as a user. I've tried to write a user service and to launch it from the udev rule without success.

Post Reply