I have a script owned by root in
/usr/local/bin/. If I run it as root user it works as expected:
$ sudo su <enter password> # runscript
If I have it started by the
systemd service (in
/etc/systemd/system/media-USBdrive.mount) then the notification aspect of the script fails:
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/10184/bus DISPLAY=:0 printf "s\n" "Success" | dzen2 -p 3
I have also tried changing the command to run as my user:
$ su john -c "DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/10184/bus DISPLAY=:0 printf \"s\n\" \"Success\" | dzen2 -p 3"
With the same result: works as root user, not from the
I have read the various questions about trying to access the X server as root:
- Setting DISPLAY in systemd service file
- How to resolve 'No protocol specified' for su user
- Linux Service Cannot Open Display
- and many others
I have also tried setting
Environment=DISPLAY=:0 in the service file.
All attempts yield:
dzen: cannot open display in the journal.
My question is: why does the service fail when run by
systemd (as root), but works when run explicitly as the root user (