Systemctl --user commands return "Failed to connect to user scope bus..."

Hello

I’m trying to set up a wallpaper changing script to run on a 30-minute timer. I don’t want this to run as root or when a different user logs in. I’m doing this via a script and a systemd timer unit because I specifically want the script to set the wallpaper using pywal16.

I have .timer and .service units in my ~/.config/systemd/user directory, but anytime I run systemd with the –user flag, it returns an error. “Failed to connect to user scope bus via local transport: No such file or directory”

I checked to make sure that systemctl –user is running and it is. The Arch wiki states that environment variables need to be set up for systemd to use, but doesn’t suggest sensible defaults for them other than saying that they should go into ~/.config/environment.d as a .conf file.

I tried setting them according to the XDG Config Home spec, but that just resulted in me getting a black screen with nothing but a mouse cursor upon login.

How I I ensure systemctl knows where to look for individual user services?

Hello @_TK ,
Here is my test on wayland:
in ~/.config/systemd/user/
wallpaper_setter.timer

[Unit]
Description="Start wallpaper_setter.service"
[Timer]
OnBootSec=2min
Persistent=true
OnUnitActiveSec=30min
Unit=wallpaper_setter.service
[Install]
WantedBy=timers.target

wallpaper_setter.service

[Unit]
Description=Randomly changes the wallpaper for X11/Wayland
[Service]
ExecStart=/home/$USER/bin/wallpaper-setter.sh

wallpaper-setter.sh

#!/bin/bash
# backgrounds path
background_home=${HOME}/.backgrounds
# Shuffle backgrounds and pick one
background=$(ls $background_home | shuf -n 1)
# Replace current background
wal -i $background_home/$background

systemctl --user daemon-reload
systemctl --user enable ~/.config/systemd/user/wallpaper_setter.timer
systemctl --user start ~/.config/systemd/user/wallpaper_setter.timer
systemctl --user list-timers

2 Likes

Also, make sure you aren’t using sudo with systemctl for user services.

Thanks for the examples, but this doesn’t address the underlying problem. Any systemctl –user command at all returns the “Failed to connect to user scope bus via local transport: No such file or directory” error. Whether that is pointed at a specific service or is a more general command, like systemctl –user daemon reload

I am not running any of these commands as sudo either. It’s all in userland.

What does this return:

echo $XDG_RUNTIME_DIR

Also this:

echo $DBUS_SESSION_BUS_ADDRESS

1 Like

This led me to the correct answer. Somehow my .zshrc was setting $XDG_RUNTIME_DIR to a directory in my $HOME, but that only happened after everything else was booted, so systemd was looking in the wrong place for the runtime dir, not the services. I don’t remember adding the Runtime environment variable to it, but I must have at some point. I don’t know why I would’ve but removing it from the file hasn’t broken anything… yet that I know of.

2 Likes

Nice, thank you!

Years ago, I used a program to automatically set backgrounds, from local folders or from the web. Turns out you need to be careful with external sources in case a NSFW sneaks in, even in a collection described as SFW. I was about to give a presentation at work when the background changed. :grimacing:

Lucky that it was ‘only’ a racy one, nothing explicit. :sweat_smile:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.