[systemd-devel] "Failed to connect to bus: No such file or directory" when running systemd --user commands with runuser as root
Andrei Borzenkov
arvidjaar at gmail.com
Tue Sep 20 18:20:25 UTC 2022
On 20.09.2022 20:29, Dave Houser wrote:
> Figured out why it was failing. I updated my post here -->
> https://askubuntu.com/questions/1430191/ubuntu-20-04-not-allowing-runuser-to-manage-systemd-user-services-failed-to/1430379#1430379
> Problem was Ubuntu default user .bashrc had the following case statement
> that required `bash -i` to be used to start an interactive shell. I removed
> it as a work around and runuser works now.
>
> ```
>
> case $- in
> *i*);;
> *) return;;
> esac
> ```
>
Well, "canonical" (pun unintended) way of connecting to the other user's
systemd instance is
systemctl --user --machine user at .host ...
This will probably fail if user instance is not running, but depending
on your requirement this may be actually a good thing.
Your solution does not work here on Ubuntu 22.04 and I fail to see how
it can help. ~/.bashrc is not read by non-interactive bash at all. It
can only work if something else reads ~/.bashrc, probably from within
/etc/profile which is sourced by login shell. But nothing in stock
/etc/profile or /etc/profile.d here does it.
>
> On Tue, Sep 20, 2022 at 12:43 AM Mantas Mikulėnas <grawity at gmail.com> wrote:
>
>> Non-interactive bash invocations generally don't read ~/.bashrc and don't
>> pay attention to environment variables that you set there.
>>
>>
>> On Mon, Sep 19, 2022 at 9:36 PM Dave Houser <davehouser1 at gmail.com> wrote:
>>
>>> I am having issues on my Ubuntu 20.04 system running systemd v245.
>>> When trying to run `runuser -l mruser -c "systemctl --user status
>>> myservice.service"` I keep getting "Failed to connect to bus: No such file
>>> or directory"
>>>
>>> This does not make sense to me because I have the same set up on a RHEL
>>> 8.4 system running systemd v239, and I dont see this issue. I can run
>>> systemd --user commands as root with runuser with no issues.
>>>
>>> Here is the troubleshooting I performed.
>>>
>>>
>>> - tried running systemctl --user status myservice.service as mruser, command
>>> runs with no errors.
>>> - I already checked loginctl for mruser, Linger=yes
>>> - Checked to make sure there was a systemd --user process running
>>> with ps
>>> - Logged into the user's account directly with separate ssh session,
>>> Then tried the same command as root in the original session, still same
>>> error.
>>> - mruser already has export XDG_RUNTIME_DIR=/run/user/$(id -u) in
>>> ~/.bashrc
>>> - Tried rebooting the system, still nothing.
>>> - Deployed a new instance of Ubuntu 20.04, same problem on it.
>>> - Already read this post
>>> <https://askubuntu.com/questions/1374347/error-running-systemd-as-user-failed-to-connect-to-bus-dbus-session-bus-addr>,
>>> was not very helpful.
>>>
>>> I made a post about this you can find it here -->
>>> https://askubuntu.com/questions/1430191/ubuntu-20-04-not-allowing-runuser-to-manage-systemd-user-services-failed-to?noredirect=1#comment2491580_1430191
>>>
>>> This seems like odd behavior so I am not sure why this is happening. Can
>>> anyone help?
>>>
>>> - Dave
>>>
>>>
>>>
>>
>> --
>> Mantas Mikulėnas
>>
>
More information about the systemd-devel
mailing list