Re: [systemd-devel] "Failed to connect to bus: No such file or directory" when running systemd --user commands with runuser as root

2022-09-20 Thread Andrei Borzenkov
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@.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  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  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
>>>
>>> ,
>>>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
>>
> 



Re: [systemd-devel] "Failed to connect to bus: No such file or directory" when running systemd --user commands with runuser as root

2022-09-20 Thread Dave Houser
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
```


On Tue, Sep 20, 2022 at 12:43 AM Mantas Mikulėnas  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  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
>>
>> ,
>>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
>


Re: [systemd-devel] "Failed to connect to bus: No such file or directory" when running systemd --user commands with runuser as root

2022-09-19 Thread Mantas Mikulėnas
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  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
>
> ,
>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