Skip to content

Commit 90c45bb

Browse files
committed
sigterm all children of the DE service on container shutdown
1 parent 15a7167 commit 90c45bb

5 files changed

Lines changed: 55 additions & 7 deletions

File tree

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,19 +235,18 @@ services:
235235

236236
# Development
237237

238-
This container can also be used as a rapid development environment for the Selkies Project. Simply clone the upstream repo and run the container as shown:
238+
This container and any downstream images can also be used as a rapid development environment for the Selkies Project. Simply clone the upstream repo and run the container as shown:
239239

240240
```
241241
git clone https://github.com/selkies-project/selkies.git
242242
cd selkies
243-
git checkout -f feature/websockets
244243
docker run --rm -it \
245244
--shm-size=1gb \
246245
-e DEV_MODE=selkies-dashboard \
247246
-e PUID=1000 \
248247
-e PGID=1000 \
249248
-v $(pwd):/config/src \
250-
-p 3001:3001 ghcr.io/linuxserver/baseimage-selkies:alpine322 bash
249+
-p 3001:3001 ghcr.io/linuxserver/webtop bash
251250
```
252251

253252
The application will be restarted on code changes to the src directory you mounted in and provide feedback for debugging.

readme-vars.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,19 +239,18 @@ full_custom_readme: |
239239
240240
# Development
241241
242-
This container can also be used as a rapid development environment for the Selkies Project. Simply clone the upstream repo and run the container as shown:
242+
This container and any downstream images can also be used as a rapid development environment for the Selkies Project. Simply clone the upstream repo and run the container as shown:
243243
244244
```
245245
git clone https://github.com/selkies-project/selkies.git
246246
cd selkies
247-
git checkout -f feature/websockets
248247
docker run --rm -it \
249248
--shm-size=1gb \
250249
-e DEV_MODE=selkies-dashboard \
251250
-e PUID=1000 \
252251
-e PGID=1000 \
253252
-v $(pwd):/config/src \
254-
-p 3001:3001 ghcr.io/linuxserver/baseimage-selkies:alpine322 bash
253+
-p 3001:3001 ghcr.io/linuxserver/webtop bash
255254
```
256255
257256
The application will be restarted on code changes to the src directory you mounted in and provide feedback for debugging.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/etc/s6-overlay/s6-rc.d/svc-de/finish
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/with-contenv bash
2+
3+
# exit early if no pid file
4+
PID_FILE="/de-pid"
5+
WAIT_SECONDS=5
6+
if [ ! -r "$PID_FILE" ]; then
7+
exit 0
8+
fi
9+
PARENT_PID=$(cat "$PID_FILE")
10+
if [ -z "$PARENT_PID" ]; then
11+
rm -f "$PID_FILE"
12+
exit 0
13+
fi
14+
15+
# get all descendant pids of de
16+
PIDS_TO_KILL=$(pstree -p "$PARENT_PID" | grep -o '([0-9]\+)' | grep -o '[0-9]\+' | grep -v "^${PARENT_PID}$")
17+
18+
# kill all descendant pids
19+
if [ -z "$PIDS_TO_KILL" ]; then
20+
echo "No desktop processes found to terminate."
21+
else
22+
echo "$PIDS_TO_KILL" | xargs --no-run-if-empty kill -TERM -- 2>/dev/null
23+
echo "Waiting up to ${WAIT_SECONDS} seconds for desktop processes to terminate..."
24+
for ((i=0; i < WAIT_SECONDS * 4; i++)); do
25+
all_gone=1
26+
for pid in $PIDS_TO_KILL; do
27+
if kill -0 "$pid" 2>/dev/null; then
28+
all_gone=0
29+
break
30+
fi
31+
done
32+
if [ "$all_gone" -eq 1 ]; then
33+
echo "All desktop processes terminated cleanly."
34+
break
35+
fi
36+
sleep 0.25
37+
done
38+
if [ "$all_gone" -eq 0 ]; then
39+
echo "Timeout reached. Handing off to s6 for final termination."
40+
fi
41+
fi
42+
43+
# clean up the PID file.
44+
rm -f "$PID_FILE"
45+
46+
exit 0

root/etc/s6-overlay/s6-rc.d/svc-de/run

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,7 @@ chmod 777 /tmp/selkies*
2626
# run
2727
cd $HOME
2828
exec s6-setuidgid abc \
29-
/bin/bash /defaults/startwm.sh
29+
/bin/bash /defaults/startwm.sh &
30+
PID=$!
31+
echo "$PID" > /de-pid
32+
wait "$PID"

0 commit comments

Comments
 (0)