You are not logged in.

#1 2020-12-08 02:19:03

52TrenchCats
Member
Registered: 2020-12-08
Posts: 4

[SOLVED] Using qdbus in service throws error when run as superuser

Recently, I've been working on a project to change my desktop wallpaper according to the time of day. I've been doing this through a bash script run automatically as a systemd service, using the following code to change the wallpaper:

qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript "
var allDesktops = desktops();
for(i=0; i < allDesktops.length; i++) {
	d = allDesktops[i];
	d.wallpaperPlugin = 'org.kde.image';
	d.currentConfigGroup = Array('Wallpaper',
				'org.kde.image',
				'General');
	d.writeConfig('Image', \"file://${wpPath}\");
};"

where $wpPath is the path to the wallpaper file.

The script runs perfectly when run directly from the terminal with

bash wallpaper-changer.sh

but when run by the systemd service I created to run it automatically, it gives me the error:

bash[628233]: Could not connect to D-Bus server: org.freedesktop.DBus.Error.NotSupported: Using X11 for dbus-daemon autolaunch was disabled at compile time, set your DBUS_SESSION_BUS_ADDRESS instead

In trying to figure out the issue myself, I've discovered that attempting to run the script as superuser gives me the exact same error. I've gone through what I could understand of the dbus documentation and people having the same error in other contexts, but nothing seemed particularly relevant to my situation. Would anyone be able to help me figure out what's causing this issue?

Last edited by 52TrenchCats (2020-12-10 22:51:54)

Offline

#2 2020-12-08 11:54:39

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: [SOLVED] Using qdbus in service throws error when run as superuser

Post the location and contents of your service file.


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#3 2020-12-08 15:18:30

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 25,361

Re: [SOLVED] Using qdbus in service throws error when run as superuser

You should not run this as superuser under any circumstances.

Use systemd user services that will run properly as your user and will have access to the same dbus session Plasma is using.

Offline

#4 2020-12-08 22:21:10

52TrenchCats
Member
Registered: 2020-12-08
Posts: 4

Re: [SOLVED] Using qdbus in service throws error when run as superuser

I see. So I should have set the service up in ~/.config/systemd/user rather than placing them in /etc/systemd/system? That actually does make a good bit more sense than how I was doing it, I'll move it there instead and see if it works. This is my first time using systemd, so I didn't understand the distinction between system services and user services.

Offline

#5 2020-12-09 03:04:02

52TrenchCats
Member
Registered: 2020-12-08
Posts: 4

Re: [SOLVED] Using qdbus in service throws error when run as superuser

Alright, so on moving the services in use to ~/.config/systemd/user, and attempting to get them running as they should be, now my journalctl is showing the following output looped each time the service is run:

Dec 08 18:20:14 bionis systemd[612]: Starting Change the system wallpaper based on time of day...
Dec 08 18:20:14 bionis systemd[1366]: wallpaper-changer.service: Failed to determine supplementary groups: Operation not permitted
Dec 08 18:20:14 bionis systemd[1366]: wallpaper-changer.service: Failed at step GROUP spawning /bin/bash: Operation not permitted
Dec 08 18:20:14 bionis systemd[612]: wallpaper-changer.service: Main process exited, code=exited, status=216/GROUP
Dec 08 18:20:14 bionis systemd[612]: wallpaper-changer.service: Failed with result 'exit-code'.
Dec 08 18:20:14 bionis systemd[612]: Failed to start Change the system wallpaper based on time of day.

Currently, my service file looks like

[Unit]
Description=Change the system wallpaper based on time of day
Wants=wallpaper-changer.timer

[Service]
Type=oneshot
ExecStart=/bin/bash /usr/local/bin/wallpaper-changer.sh
User=alvis

[Install]
WantedBy=default.target

and my timer file looks like

[Unit]
Description=Timer to activate the Wallpaper Changer

[Install]
WantedBy=timers.target

[Timer]
OnBootSec=1min
OnCalendar=*-*-* *:*:00
Persistent=true
OnClockChange=true

(This is only running as often as it does because I'm still testing things. Once I get it working reliably, I intend to make it run much less often)

(EDIT) Ah, I decided to some more research into this new error, and found this thread which suggested I should remove the User line in the service file, after which it worked perfectly!

Last edited by 52TrenchCats (2020-12-09 03:27:48)

Offline

#6 2020-12-09 08:44:06

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 25,361

Re: [SOLVED] Using qdbus in service throws error when run as superuser

Yes user services already run as the properly logged in user by definition.

Please mark as [SOLVED] by editing the title in your first post (... might have to shorten it a bit, you're likely to hit the char limit)

Offline

Board footer

Powered by FluxBB