Skip to content

Add EXIT_ON_APP_CLOSE to stop the container when the app exits - #200

Merged
thelamer merged 1 commit into
linuxserver:devfrom
junkerderprovinz:feat/exit-on-app-close
Nov 19, 2026
Merged

thelamer merged 1 commit into
linuxserver:devfrom
junkerderprovinz:feat/exit-on-app-close

Conversation

@junkerderprovinz

@junkerderprovinz junkerderprovinz commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

linuxserver.io


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

  • An LLM assisted me in writing the code or text for this PR

  • An LLM agent wrote the code or text for this PR


Description:

Hi! This adds EXIT_ON_APP_CLOSE. When it is true, a small s6 service, svc-app-exit, stops the container once the autostart app and everything it started have exited. Selkies holds a lock on $XDG_RUNTIME_DIR/selkies-autostart.lock for that whole time, so the service waits for the lock file to appear and then for the lock to disappear from /proc/locks. It only reads /proc/locks, so selkies never finds the lock taken, and it matches by inode because lslocks cannot resolve the path inside a container. Then it calls s6's halt, the same way docker stop shuts down, and the container exits with code 0. init-selkies-config removes the lock file left from the last run, so an app that quits right away still stops the container. If RESTART_APP is set as well, exiting wins, and init-selkies-config leaves SELKIES_APP_RESTART unset. The same goes for HARDEN_OPENBOX, which turns on RESTART_APP unless you set it yourself. Without the variable the service just sleeps. I used AI as a helper for the change and this text.

Benefits of this PR and context:

Closes #198. Single-app images like chromium can then run as throwaway containers: start one with --rm or --restart=no, close the app, and the container is gone. With a restart policy like unless-stopped, Docker would just start it again. The change is one small service plus two lines in init-selkies-config. A mod could add the service, but it would also have to patch init-selkies-config to keep RESTART_APP from bringing the app back. Happy to rename the variable if you prefer another name, and if this lands I'll document it in docker-documentation (security and baseimage-internals pages), as I did for DISABLE_WINDOW_BUTTONS in linuxserver/docker-documentation#51. Thanks for having a look!

How Has This Been Tested?

I mounted the changed files into the published dev image (fff78f27-ls17, built from cce318a) on Unraid, with a script running sleep 20 as the autostart app. X11, Wayland (PIXELFLUX_WAYLAND=true on an RTX 4070 Ti SUPER) and X11 with RESTART_APP=true each logged [svc-app-exit] Application has exited. Stopping the container... within a second of the app closing, and the container exited with code 0 four to five seconds after the app. With RESTART_APP the app ran only once. If the app leaves a child running for another 10 seconds, the container waits for the child. An app that quits after one second also stops the container, and a second start on the same /config waits for the new run. Without the variable the container kept running.

Source / References:

#198

@junkerderprovinz

Copy link
Copy Markdown
Contributor Author

Rebased onto dev. Since c4dede0 removed svc-watchdog, the change is now a small svc-app-exit service: it waits for the autostart's lock on $XDG_RUNTIME_DIR/selkies-autostart.lock, reads /proc/locks so it never takes the lock itself, and halts the container once the lock is released. init-selkies-config also removes the lock file left from the last run, so an app that quits right away still stops the container. I've updated the description and the test notes to match.

@github-project-automation github-project-automation Bot moved this from PRs to PRs Approved in Issue & PR Tracker Nov 19, 2026
@thelamer
thelamer merged commit 7cb371f into linuxserver:dev Nov 19, 2026
3 checks passed
@LinuxServer-CI LinuxServer-CI moved this from PRs Approved to Done in Issue & PR Tracker Nov 19, 2026
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.

2 participants