Skip to content

Commit

Permalink
Use machinectl shell instead of su
Browse files Browse the repository at this point in the history
That way it's a real session and systemd is aware of it, so for example user
units get started automatically.

Fixes #18
  • Loading branch information
Trundle committed Mar 15, 2021
1 parent 7ac61b2 commit 89c644e
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion syschdemd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,24 @@ if [ ! -e "/run/systemd.pid" ]; then
LOCALE_ARCHIVE=/run/current-system/sw/lib/locale/locale-archive \
@daemonize@/bin/daemonize /run/current-system/sw/bin/unshare -fp --mount-proc systemd
/run/current-system/sw/bin/pgrep -xf systemd > /run/systemd.pid

# Wait for systemd to start
status=1
while [[ $status -gt 0 ]]; do
$sw/sleep 1
status=0
$sw/nsenter -t $(< /run/systemd.pid) -p -m -- \
$sw/systemctl is-system-running -q --wait 2>/dev/null \
|| status=$?
done
fi

userShell=$($sw/getent passwd @defaultUser@ | $sw/cut -d: -f7)
exec $sw/nsenter -t $(< /run/systemd.pid) -p -m --wd="$PWD" -- @wrapperDir@/su -s $userShell @defaultUser@ "$@"
if [[ $# -gt 0 ]]; then
# wsl seems to prefix with "-c"
shift
cmd="$@"
else
cmd="$userShell"
fi
exec $sw/nsenter -t $(< /run/systemd.pid) -p -m -- $sw/machinectl -q --uid=@defaultUser@ shell .host /bin/sh -c "cd \"$PWD\"; exec $cmd"

0 comments on commit 89c644e

Please sign in to comment.