Skip to content

Commit

Permalink
init: add a basic [email protected] to ensure basic runtime in…
Browse files Browse the repository at this point in the history
…tegration on initful containers (graphics, sound, keyring, authorities)

Signed-off-by: Luca Di Maio <[email protected]>
  • Loading branch information
89luca89 committed Aug 16, 2023
1 parent de322cb commit 2e08b2d
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion distrobox-init
Original file line number Diff line number Diff line change
Expand Up @@ -1864,13 +1864,43 @@ if command -v systemctl 2> /dev/null; then
done
fi

# Let's do a minimal user-integration for the user when using system
# as the [email protected] will trigger the [email protected] which will
# undo all the integration we did at the start of the script
#
# This will ensure the basic integration for x11/wayland/pipewire/keyring
if [ -e /usr/lib/systemd/system/[email protected] ]; then
cat << EOF > /usr/lib/systemd/system/[email protected]
[Unit]
Description=User runtime integration for UID %i
After=user@%i.service
Requires=user-runtime-dir@%i.service
[Service]
User=%i
Type=oneshot
ExecStart=sh -c "ln -sf /run/host/run/user/\$(id -ru)/keyring/ /run/user/\$(id -ru)/ ; \
ln -sf /run/host/run/user/\$(id -ru)/wayland-0 /run/user/\$(id -ru)/ ; \
ln -sf /run/host/run/user/\$(id -ru)/pipewire-0 /run/user/\$(id -ru)/ ; \
ln -sf /run/host/run/user/\$(id -ru)/ICEauthority /run/user/\$(id -ru)/ ; \
ln -sf /run/host/run/user/\$(id -ru)/.mutter* /run/user/\$(id -ru)/"
Slice=user-%i.slice
EOF

fi

# Now we can launch init
printf "distrobox: Firing up init system...\n"
printf "container_setup_done\n"

if [ -e /usr/lib/systemd/systemd ] || [ -e /lib/systemd/systemd ]; then
# Start user systemd unit, this will attempt until systemd is ready
sh -c "while true; do sleep 1; systemctl start user@${container_user_name}.service 2>/dev/null && exit 0; done" &
sh -c "while true; do \
sleep 1; \
systemctl start user@${container_user_name}.service 2>/dev/null && \
systemctl start user-integration@${container_user_name}.service 2>/dev/null && \
exit 0; \
done" &

[ -e /usr/lib/systemd/systemd ] && exec /usr/lib/systemd/systemd --system --log-target=console --unit=multi-user.target
[ -e /lib/systemd/systemd ] && exec /lib/systemd/systemd --system --log-target=console --unit=multi-user.target
Expand Down

0 comments on commit 2e08b2d

Please sign in to comment.