How to get user desktop notifications from a sudo-run systemd service on Wayland?
1
vote
0
answers
1048
views
I'm running KDE Plasma on Nobara (Wayland), a Fedora-based distro. I'm brand new to Wayland and Nobara/Fedora, and have very limited experience with systemd.
I have a bash script that sends a desktop notification with success, warning or error, depending on the outcome of the action.
- When i run the script manually (not sudo), i get a desktop notification.
- When i run the notification command in Terminal (not sudo), i get a desktop
notification.
- When i set up the /etc/systemd/system service, i do not get desktop
notification, and i get an error in journalctl (the script otherwise runs fine):
> Cannot autolaunch D-Bus without X11 $DISPLAY
Example notification within the script:
notify-send -a 'Successful!' -u low -i vcs-normal
systemd service:
[Unit]
Description=Test Script
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
Nice=10
IOSchedulingClass=2
IOSchedulingPriority=7
ExecStart=/home/username/.local/bin/test.sh
User=username
Group=users
My search indicates that the root-run systemd service doesn't have access to the user's desktop to put a notification. I saw an attempt around it , which was to add this to the service file:
[Service]
User=username
Environment=DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/%U/bus
In my case, it stopped the error in the journal, but it did not give me the desktop notification.
I'm aware i can run systemd services as the user with
systemd --user start test
service files placed in ~/.config/systemd/user
, and the notifications will work (i have managed to achieve that). But in this instance i would like to run this script as root.
Thanks :)
Asked by EldestBizarre
(35 rep)
Oct 2, 2023, 11:47 AM
Last activity: Oct 2, 2023, 12:09 PM
Last activity: Oct 2, 2023, 12:09 PM