-
Notifications
You must be signed in to change notification settings - Fork 0
/
post_start.sh
40 lines (32 loc) · 1.17 KB
/
post_start.sh
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
#!/bin/bash
if [[ -z "${RUNPOD_PROJECT_ID}" ]]; then
echo "RUNPOD_PROJECT_ID environment variable is not set. Exiting."
exit 0
fi
check_interval=60
countdown_time=${POD_INACTIVITY_TIMEOUT:-300}
# Function to monitor the number of active SSH connections
monitor_ssh() {
echo "Monitoring SSH connections every $check_interval seconds, with a countdown of $countdown_time seconds."
countdown=$countdown_time
while true; do
sleep $check_interval
connections=$(ss -tn | grep ':22' | grep -v 'LISTEN' | wc -l)
if [[ "$connections" -eq 0 ]]; then
((countdown-=$check_interval))
echo "No SSH connections found. Countdown: $countdown seconds remaining."
if [[ "$countdown" -le 0 ]]; then
echo "Countdown reached zero. Removing pod: $RUNPOD_POD_ID"
runpodctl remove pod $RUNPOD_POD_ID
exit 0
fi
else
if [[ "$countdown" -ne $countdown_time ]]; then
echo "SSH connection detected. Countdown aborted."
fi
countdown=$countdown_time
fi
done
}
monitor_ssh &
filebrowser -a 0.0.0.0 -p 4040 -r / &