[arch-general] systemd-run --user does not work

Ismael Bouya ismael.bouya at normalesup.org
Mon May 12 14:04:10 EDT 2014


(Mon, May 12, 2014 at 11:23:33PM +0900) Savyasachee Jha :
> Well, I just tried this out on my laptop, and it gives two different error
> messages.
> 
> $ sysytemd-run --user /usr/bin/ls
> Failed to create message: Input/output error
> 
> $ sudo systemd-run --user /usr/bin/ls
> Failed to create bus connection: Connection refused
> 
> And yes, running it with --system works perfectly well. It is very odd.

(This answer is a summary of a tutorial that I wrote some days ago and you
can find the french version here:
http://immae.eu/blog/2014/05/10/gerer-sa-session-avec-systemd/
If you don't speak french, be patient, I'm working on its translation)



For me it works both with user and system.

It works for system:
That's normal, because systemd makes use of dbus, and the system bus is
always there, and he knows where to contact it.

However, systemd-run --user tries to contact the "user dbus" (AKA session
dbus), via your "systemd --user" (You can see it with "pstree -aUp login"
if it is started. If it is not, then probably you should enable the correct
module via pam). Does this process know your dbus session? If you didn't do
anything regarding that, then certainly not.

You can be sure by checking its environment which should contain something
like that:
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus

Let's say you don't have it in "systemd --user". Simply add something like
that in /etc/systemd/system/user at .service.d/dbus_env.conf
--------
[Unit]
Wants=dbus.service

[Service]
Environment=DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/%I/bus
---------
and follow the DBUS section there:
https://wiki.archlinux.org/index.php/Systemd/User#D-Bus

This will ensure that you have a dbus session and that all the services
(including systemd --user) know how to have access to it.

Then you can run your systemd-run --user. You have to restart *all* your
sessions before that of course (I.e. you muss not have any remaining
session at your name, otherwise the process won't end. Check that with
systemd-cgls or so. If you enabled lingering sessions then you probably
don't have this problem, otherwise make sure everything is killed)


(Note that your shell doesn't have to know the DBUS_SESSION_BUS_ADDRESS
variable)
-- 
Ismael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://mailman.archlinux.org/pipermail/arch-general/attachments/20140512/9c591c27/attachment.asc>


More information about the arch-general mailing list