[systemd-devel] How to interact with `systemd --user`?

Kok, Auke-jan H auke-jan.h.kok at intel.com
Thu Jun 14 14:36:48 PDT 2012


On Thu, Jun 14, 2012 at 2:22 PM, Ciprian Dorin Craciun
<ciprian.craciun at gmail.com> wrote:
> On Thu, Jun 14, 2012 at 11:27 PM, Kok, Auke-jan H
> <auke-jan.h.kok at intel.com> wrote:
>> On Thu, Jun 14, 2012 at 1:00 PM, Ciprian Dorin Craciun
>> <ciprian.craciun at gmail.com> wrote:
>>> On Thu, Jun 14, 2012 at 10:43 PM, Kok, Auke-jan H
>>> <auke-jan.h.kok at intel.com> wrote:
>>>> On Thu, Jun 14, 2012 at 12:29 PM, Ciprian Dorin Craciun
>>>> <ciprian.craciun at gmail.com> wrote:
>>>>>    Hello all!
>>>>>
>>>>>    I want to play a little with systemd, but first I want to use it
>>>>> in a "sandbox" user, thus I start it (as non-root) from a console with
>>>>>      systemd --log-level=info --default-standard-output=inherit
>>>>> --default-standard-error=inherit
>>>>
>>>> no need for any of those arguments, but, you forgot to add --user:
>>>>
>>>> $ /usr/lib/systemd/systemd --user
>>>
>>>    I've tried with `--user` also, but as the documentation says it's
>>> able to detect this automatically. Either way still no effect.
>>
>> perhaps. You can check if it's running with the right DBUS_SESSION_BUS_ADDRESS
>> and XDG_RUNTIME_DIR by inspecting `strings /proc/<pid>/environ
>
>    So:
> ~~~~
> dbus-daemon --session --print-address=1 --print-pid=1
> systemd --user --log-level=debug --default-standard-output=inherit
> --default-standard-error=inherit --unit sleep.service
> # (the standard-output and standard-error are required in my case it
> seems, and sleep.service contains a simple `/usr/bin/sleep 12s` for
> exec, and it works.)
> systemctl --user
> ~~~~
> # for systemd process
> strings /proc/20590/environ | grep XDG
> XDG_DATA_HOME=/home/systemd-tests/.local/share
> XDG_CONFIG_DIRS=/etc/xdg
> XDG_CONFIG_HOME=/home/systemd-tests/.config
> XDG_CACHE_HOME=/home/systemd-tests/.cache
> XDG_DATA_DIRS=/usr/local/share/:/usr/share/
> XDG_RUNTIME_DIR=/tmp/systemd-tests-run
>
> strings /proc/20590/environ | grep DBUS
> DBUS_SESSION_BUS_PID=20555
> DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-xcSICndjkx,guid=e28e135122b7479666f6bdda000032b0
>
> lsof -p 20590
> COMMAND   PID          USER   FD      TYPE     DEVICE    SIZE       NODE NAME
> ...
> systemd 20590 systemd-tests    4u     0000        0,8       0
> 6 anon_inode
> systemd 20590 systemd-tests    5u     unix 0xf3fa6f40
> 132772 @/org/freedesktop/systemd1/notify/2186741763098302303
> systemd 20590 systemd-tests    6u     unix 0xf3fa73c0             132773 socket
> systemd 20590 systemd-tests    7u     unix 0xf3fa73c0             132773 socket
> systemd 20590 systemd-tests    9u     unix 0xf3fa6d00             132774 socket
> systemd 20590 systemd-tests   10u     unix 0xf3fa6d00             132774 socket
> systemd 20590 systemd-tests   12u     unix 0xf3fa6ac0
> 132776 /tmp/systemd-tests-run/systemd/private
> ...
> ~~~~
>
>    And also:
> ~~~~
> strace -f -v -e process -- systemctl --user
> execve("/usr/bin/systemctl", ["systemctl", "--user"],
> ["XDG_DATA_HOME=/home/systemd-test"..., "SHELL=/bin/bash",
> "TERM=screen.rxvt", "DERBY_HOME=/opt/java/db",
> "DBUS_SESSION_BUS_PID=20555", "ANT_HOME=/usr/share/apache-ant",
> "USER=systemd-tests", "MOZ_PLUGIN_PATH=/usr/lib/mozilla"...,
> "MAVEN_OPTS=-Xmx512m", "XDG_CONFIG_DIRS=/etc/xdg",
> "PATH=/usr/local/bin:/usr/bin:/bi"..., "HG=/usr/bin/hg",
> "LC_COLLATE=C", "PWD=/home/systemd-tests", "JAVA_HOME=/opt/java",
> "LANG=en_US.utf8", "SHLVL=1", "HOME=/home/systemd-tests",
> "XDG_CONFIG_HOME=/home/systemd-te"...,
> "XDG_CACHE_HOME=/home/systemd-tes"..., "LOGNAME=systemd-tests",
> "DBUS_SESSION_BUS_ADDRESS=unix:ab"...,
> "XDG_DATA_DIRS=/usr/local/share/:"..., "J2SDKDIR=/opt/java",
> "GOPATH=/usr/lib/go/site", "XDG_RUNTIME_DIR=/tmp/systemd-tes"...,
> "DISPLAY=:0", "J2REDIR=/usr/lib/jvm/java-7-open"...,
> "G_BROKEN_FILENAMES=1", "_=/usr/bin/strace"]) = 0
> Failed to get D-Bus connection: No connection to service manager.
> exit_group(1)                           = ?
> +++ exited with 1 +++
> ~~~~
>
>    As such I don't see what I'm doing wrong...

lots, not helped by the fact that you're not using systemd --system as pid=1.

> XDG_RUNTIME_DIR=/tmp/systemd-tests-run

needs to be /run/usr/<user>/ instead

> DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-xcSICndjkx,guid=e28e135122b7479666f6bdda000032b0

should point to XDG_RUNTIME_DIR/dbus/user_bus_socket.

I think you really don't want to try and run a systemd --user (highly
experimental!) without a systemd --system (stable), that would be the
world upside down, and you're going to get every little part of it
wrong.

Auke


More information about the systemd-devel mailing list