diff --git a/root/etc/s6-overlay/s6-rc.d/init-selkies-config/run b/root/etc/s6-overlay/s6-rc.d/init-selkies-config/run index dea6041..2578261 100755 --- a/root/etc/s6-overlay/s6-rc.d/init-selkies-config/run +++ b/root/etc/s6-overlay/s6-rc.d/init-selkies-config/run @@ -65,6 +65,8 @@ done # XDG Home printf "$HOME/.XDG" > /run/s6/container_environment/XDG_RUNTIME_DIR +# svc-app-exit takes a new lock file as the sign that the app has started +rm -f "$HOME/.XDG/selkies-autostart.lock" printf "$HOME/.XDG/Xauthority" > /run/s6/container_environment/XAUTHORITY if [[ "${PIXELFLUX_WAYLAND,,}" == "true" ]]; then printf "wayland-1" > /run/s6/container_environment/WAYLAND_DISPLAY @@ -236,7 +238,7 @@ set_unset() { export "$1=$2" fi } -if [[ ${RESTART_APP,,} == "true" ]]; then +if [[ ${RESTART_APP,,} == "true" ]] && [[ ${EXIT_ON_APP_CLOSE,,} != "true" ]]; then set_unset SELKIES_APP_RESTART true fi if [[ ! -z ${NO_FULL+x} ]]; then diff --git a/root/etc/s6-overlay/s6-rc.d/svc-app-exit/dependencies.d/svc-selkies b/root/etc/s6-overlay/s6-rc.d/svc-app-exit/dependencies.d/svc-selkies new file mode 100644 index 0000000..e69de29 diff --git a/root/etc/s6-overlay/s6-rc.d/svc-app-exit/run b/root/etc/s6-overlay/s6-rc.d/svc-app-exit/run new file mode 100755 index 0000000..3077b79 --- /dev/null +++ b/root/etc/s6-overlay/s6-rc.d/svc-app-exit/run @@ -0,0 +1,23 @@ +#!/usr/bin/with-contenv bash + +if [[ ${EXIT_ON_APP_CLOSE,,} != "true" ]]; then + exec sleep infinity +fi + +# selkies holds this lock until everything the app started has exited, only read it so selkies never finds it taken, +# by inode as lslocks cannot resolve the path inside a container +LOCK="${XDG_RUNTIME_DIR}/selkies-autostart.lock" +app_running() { + grep -qE "FLOCK +ADVISORY +WRITE +[0-9]+ [0-9a-f]+:[0-9a-f]+:$(stat -c %i "${LOCK}") " /proc/locks +} +until [[ -e "${LOCK}" ]]; do + sleep 1 +done +# selkies creates the file just before it takes the lock +sleep 1 +echo "[svc-app-exit] Application started, the container stops when it exits" +while app_running; do + sleep 1 +done +echo "[svc-app-exit] Application has exited. Stopping the container..." +exec /run/s6/basedir/bin/halt diff --git a/root/etc/s6-overlay/s6-rc.d/svc-app-exit/type b/root/etc/s6-overlay/s6-rc.d/svc-app-exit/type new file mode 100644 index 0000000..5883cff --- /dev/null +++ b/root/etc/s6-overlay/s6-rc.d/svc-app-exit/type @@ -0,0 +1 @@ +longrun diff --git a/root/etc/s6-overlay/s6-rc.d/user/contents.d/svc-app-exit b/root/etc/s6-overlay/s6-rc.d/user/contents.d/svc-app-exit new file mode 100644 index 0000000..e69de29