Skip to content

Commit

Permalink
test: systemctl stop user@ now drops the root session
Browse files Browse the repository at this point in the history
With systemd 256-rc1 systemctl stop user@* also stops user@0 the root
user's service so kills the open ssh connection making `m.execute` fail.

Combine stopping the user service with the loginctl cleanup.
  • Loading branch information
jelly committed Apr 29, 2024
1 parent bf2253a commit d53d53e
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions test/common/testlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1688,18 +1688,18 @@ def terminate_sessions() -> None:
self.machine.execute("systemctl stop systemd-logind")

# Wait for sessions to be gone
sessions = self.machine.execute("loginctl --no-legend list-sessions | awk '/web console/ { print $1 }'").strip().split()
for s in sessions:
sessions = self.machine.execute("loginctl --no-legend list-sessions | awk '/web console/ { print $1,$2 }'").strip().split()
for session in sessions:
sessionid, uid = session.split(',')
try:
m.execute(f"while loginctl show-session {s}; do sleep 0.2; done", timeout=30)
m.execute(f"while loginctl show-session {sessionid}; do sleep 0.2; done", timeout=30)
# Terminate systemd user service
m.execute(f"systemctl stop user@{uid}.service")
except RuntimeError:
# show the status in debug logs, to see what's wrong
m.execute(f"loginctl session-status {s}; systemd-cgls", stdout=None)
m.execute(f"loginctl session-status {sessionid}; systemd-cgls", stdout=None)
raise

# terminate all systemd user services for users who are not logged in
self.machine.execute("systemctl stop user@*.service")

# Clean up "closing" sessions again, and clean user id cache for non-system users
self.machine.execute("systemctl stop systemd-logind; cd /run/systemd/users/; "
"for f in $(ls); do [ $f -le 500 ] || rm $f; done")
Expand Down

0 comments on commit d53d53e

Please sign in to comment.