Start interactive shell using systemd machine manager.
Using sudo
is not enough to communicate with the user service manager.
$ sudo --user archivebox --login
archivebox@raspberrypi:~ $ systemctl --user status archivebox
Failed to connect to bus: $DBUS_SESSION_BUS_ADDRESS and $XDG_RUNTIME_DIR not defined (consider using --machine=@.host --user to connect to bus of other user)
In short…
$ sudo -u archivebox -i systemctl --user status archivebox
Failed to connect to bus: $DBUS_SESSION_BUS_ADDRESS and $XDG_RUNTIME_DIR not defined (consider using --machine=@.host --user to connect to bus of other user)
The solution is to take advantage of the systemd machine manager.
Check whether machinectl
utility is installed.
$ machinectl
-bash: machinectl: command not found
It is provided by the systemd-container
package.
$ dpkg-query -S machinectl
systemd-container: /usr/share/zsh/vendor-completions/_machinectl systemd-container: /bin/machinectl systemd-container: /usr/share/man/man1/machinectl.1.gz systemd-container: /usr/share/bash-completion/completions/machinectl
Install systemd-container
package.
$ sudo apt install systemd-container
Reading package lists... Done Building dependency tree... Done Reading state information... Done The following additional packages will be installed: libnss-mymachines The following NEW packages will be installed: libnss-mymachines systemd-container 0 upgraded, 2 newly installed, 0 to remove and 52 not upgraded. Need to get 626 kB of archives. After this operation, 1,637 kB of additional disk space will be used. Do you want to continue? [Y/n] Get:1 http://deb.debian.org/debian bullseye/main arm64 systemd-container arm64 247.3-7+deb11u1 [410 kB] Get:2 http://deb.debian.org/debian bullseye/main arm64 libnss-mymachines arm64 247.3-7+deb11u1 [215 kB] Fetched 626 kB in 0s (1,491 kB/s) Selecting previously unselected package systemd-container. (Reading database ... 40155 files and directories currently installed.) Preparing to unpack .../systemd-container_247.3-7+deb11u1_arm64.deb ... Unpacking systemd-container (247.3-7+deb11u1) ... Selecting previously unselected package libnss-mymachines:arm64. Preparing to unpack .../libnss-mymachines_247.3-7+deb11u1_arm64.deb ... Unpacking libnss-mymachines:arm64 (247.3-7+deb11u1) ... Setting up systemd-container (247.3-7+deb11u1) ... Created symlink /etc/systemd/system/multi-user.target.wants/machines.target → /lib/systemd/system/machines.target. Setting up libnss-mymachines:arm64 (247.3-7+deb11u1) ... First installation detected... Checking NSS setup... Processing triggers for libc-bin (2.31-13+rpt2+rpi1+deb11u4) ... Processing triggers for man-db (2.9.4-2) ... Processing triggers for dbus (1.12.20-2) ... Scanning processes... Scanning processor microcode... Scanning linux images... Running kernel seems to be up-to-date. Failed to check for processor microcode upgrades. No services need to be restarted. No containers need to be restarted. No user sessions are running outdated binaries.
Use machinectl
to start interactive shell.
$ sudo machinectl shell --uid archivebox Connected to the local host. Press ^] three times within 1s to exit session.
archivebox@raspberrypi:~ $
Access user service manager.
archivebox@raspberrypi:~ $ systemctl --user status archivebox
● archivebox.service - archivebox service Loaded: loaded (/home/archivebox/.config/systemd/user/archivebox.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2022-12-23 00:42:12 CET; 12h ago Process: 525 ExecStartPre=/usr/bin/docker-compose -f docker-compose.yml down (code=exited, status=0/SUCCESS) Main PID: 981 (docker-compose) Tasks: 3 (limit: 779) CPU: 2min 25.283s CGroup: /user.slice/user-1001.slice/user@1001.service/app.slice/archivebox.service └─981 /usr/bin/python3 /usr/bin/docker-compose -f docker-compose.yml up Dec 23 12:58:59 raspberrypi docker-compose[981]: archivebox_1 | "GET /admin/login/ HTTP/1.1" 200 11144
Simple as that.