Skip to content

Bring Workspace sessions back after an unclean shutdown too - #113

Open
tigerblue77 wants to merge 7 commits into
linuxserver:masterfrom
tigerblue77:claude/loving-hopper-f527pj-unclean
Open

tigerblue77 wants to merge 7 commits into
linuxserver:masterfrom
tigerblue77:claude/loving-hopper-f527pj-unclean

Conversation

@tigerblue77

@tigerblue77 tigerblue77 commented Sep 23, 2026 •

Copy link
Copy Markdown

linuxserver.io


  • I have read the contributing guideline and understand that I have made the correct modifications

Description:

When svc-kasm/finish has not written /opt/kasm_sessions.state, init-config-kasm builds it from dockerd's container records (/opt/docker/containers/*/config.v2.json), before dockerd starts and rewrites them. It records the session containers (kasm.kasmid) whose record says they were running, marks the paused ones as paused, and notes their address on each network. svc-kasm/run then restores them as after a clean stop.

Benefits of this PR and context:

closes #111

Depends on #109, whose commits are included here until it is merged. Restoring after an unclean shutdown also needs dockerd to start, see #112.

How Has This Been Tested?

#109 plus this change on 1.19.0-ls150, then docker kill kasm and docker start kasm:

  • Bring Workspace sessions back after a restart #109 alone, two running sessions: both end up Exited (2) while Kasm shows them as running;
  • with this change, session A running and session B paused, neither through a clean stop yet (no pinned address): A is running at .10 and reachable, B is paused at .11 and reachable once resumed;
  • the same with Remove a stale containerd pid on start #112 added and the stale containerd pid set to 1;
  • a session stopped in Kasm stays stopped, and a clean restart still uses the file written by finish.

I also ran the extraction on records without labels, records without networks, a truncated record (skipped, the others are still extracted) and an empty containers directory.

Source / References:

Kasm routes to a session by the address its container was created with,
while Docker gives a starting container the lowest free address. Record
the address of each running or paused session on shutdown and pin the
container back to it on start.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RmwHZxdRuWgp9chBZTZTMn
dockerd restarts session containers through their unless-stopped
policy, then svc-kasm stops every running container, so Kasm keeps
listing sessions as running or paused while their containers are
stopped. Start the sessions recorded on shutdown again, pausing those
that were paused, before the services start.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RmwHZxdRuWgp9chBZTZTMn
svc-kasm/finish does not run when the container is killed, so nothing
records the sessions. dockerd's own records still show which session
containers were running or paused, and at which address, until dockerd
starts again. Build the state file from them in init-config-kasm when
finish has not written one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RmwHZxdRuWgp9chBZTZTMn
claude added 4 commits October 4, 2026 13:13
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RmwHZxdRuWgp9chBZTZTMn
…store

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RmwHZxdRuWgp9chBZTZTMn
…527pj-unclean

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RmwHZxdRuWgp9chBZTZTMn
With -exec ... {} +, jq gets every config.v2.json in a single run and
find exits non-zero when it fails. The block is the last command of
init-config-kasm, so a record truncated by a power loss would fail the
oneshot and every record after it would be dropped. Run jq once per
record instead: a bad one only loses itself and find still exits 0.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RmwHZxdRuWgp9chBZTZTMn
@tigerblue77

Copy link
Copy Markdown
Author

Hi @thespad & @thelamer, can you have a look please ? 😉🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

[BUG] Workspace sessions are still left stopped after an unclean shutdown

3 participants