0

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 systemd service.

I have read the various questions about trying to access the X server as root:

I have also tried setting Environment=XAUTHORITY=/home/john/.Xauthority and 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 (sudo su)?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.