-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsshWrapper.sh
More file actions
43 lines (34 loc) · 1015 Bytes
/
Copy pathsshWrapper.sh
File metadata and controls
43 lines (34 loc) · 1015 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
set -euo pipefail
# sshWrapper.sh — Entrypoint for the SSH-based API container.
# Manages the sshd process lifecycle with signal handling for graceful
# restart (USR1) and shutdown (SIGINT/SIGTERM).
SSHD_KILL_GRACE_TIME=3
RUNNING_SSHD=""
restart_sshd() {
echo "USR1 signal received. Restarting SSH server"
if [ -n "${RUNNING_SSHD}" ]; then
kill "${RUNNING_SSHD}" 2>/dev/null || true
sleep "${SSHD_KILL_GRACE_TIME}"
kill -9 "${RUNNING_SSHD}" 2>/dev/null || true
fi
/usr/sbin/sshd -D -e &
RUNNING_SSHD=$!
}
exit_wrapper() {
echo "Quit signal received. Exiting"
if [ -n "${RUNNING_SSHD}" ]; then
kill "${RUNNING_SSHD}" 2>/dev/null || true
sleep "${SSHD_KILL_GRACE_TIME}"
kill -9 "${RUNNING_SSHD}" 2>/dev/null || true
fi
exit 0
}
trap "restart_sshd" USR1
trap "exit_wrapper" SIGINT SIGTERM
/usr/sbin/sshd -D -e &
RUNNING_SSHD=$!
# Keep the wrapper alive so signals can be caught.
while true; do
sleep 5
done