Skip to content

Commit 9d3bd4f

Browse files
committed
refactor: change vpn script
separate wait_for_vpn and wait_for_gluetun
1 parent b1a9870 commit 9d3bd4f

File tree

2 files changed

+29
-25
lines changed

2 files changed

+29
-25
lines changed
Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
#!/usr/bin/env bash
22

3-
if [ -z "$WAIT_FOR_VPN" ]; then
4-
echo "WAIT_FOR_VPN is empty or not set. Proceeding immediately..."
5-
else
3+
TIMEOUT_SECONDS=2
4+
SLEEP_SECONDS=2
65

7-
if [[ "${WAIT_FOR_VPN:-"false"}" == "true" ]]; then
8-
echo "Waiting for VPN to be connected..."
6+
if [[ "${WAIT_FOR_VPN:-false}" == "true" ]]; then
7+
echo "🔒 Waiting for VPN to be connected..."
98
while ! grep -s -q "connected" /shared/vpnstatus; do
10-
# Also account for gluetun-style http controller - undocumented feature from https://github.com/qdm12/gluetun/issues/2277#issuecomment-2115964521
11-
if (timeout 2s curl -s http://localhost:8000/v1/vpn/status | grep -q running); then
12-
break
13-
fi
14-
echo "VPN not connected"
15-
sleep 2
9+
echo "VPN not connected yet..."
10+
sleep "$SLEEP_SECONDS"
1611
done
17-
echo "VPN Connected, starting application..."
12+
echo "VPN Connected. Starting application..."
1813
fi
1914

20-
fi
15+
if [[ "${WAIT_FOR_GLUETUN:-false}" == "true" ]]; then
16+
echo "🌐 Waiting for Gluetun to be ready..."
17+
until timeout "${TIMEOUT_SECONDS}s" bash -c 'curl -s http://localhost:8000/v1/vpn/status | grep -q running'; do
18+
echo "Gluetun not ready yet..."
19+
sleep "$SLEEP_SECONDS"
20+
done
21+
echo "✅ Gluetun is ready. Starting application..."
22+
fi
Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
#!/usr/bin/env bash
22

3-
if [ -z "$WAIT_FOR_VPN" ]; then
4-
echo "WAIT_FOR_VPN is empty or not set. Proceeding immediately..."
5-
else
3+
TIMEOUT_SECONDS=2
4+
SLEEP_SECONDS=2
65

7-
if [[ "${WAIT_FOR_VPN:-"false"}" == "true" ]]; then
8-
echo "Waiting for VPN to be connected..."
6+
if [[ "${WAIT_FOR_VPN:-false}" == "true" ]]; then
7+
echo "🔒 Waiting for VPN to be connected..."
98
while ! grep -s -q "connected" /shared/vpnstatus; do
10-
# Also account for gluetun-style http controller - undocumented feature from https://github.com/qdm12/gluetun/issues/2277#issuecomment-2115964521
11-
if (timeout 2s curl -s http://localhost:8000/v1/vpn/status | grep -q running); then
12-
break
13-
fi
14-
echo "VPN not connected"
15-
sleep 2
9+
echo "VPN not connected yet..."
10+
sleep "$SLEEP_SECONDS"
1611
done
17-
echo "VPN Connected, starting application..."
12+
echo "VPN Connected. Starting application..."
1813
fi
1914

15+
if [[ "${WAIT_FOR_GLUETUN:-false}" == "true" ]]; then
16+
echo "🌐 Waiting for Gluetun to be ready..."
17+
until timeout "${TIMEOUT_SECONDS}s" bash -c 'curl -s http://localhost:8000/v1/vpn/status | grep -q running'; do
18+
echo "Gluetun not ready yet..."
19+
sleep "$SLEEP_SECONDS"
20+
done
21+
echo "✅ Gluetun is ready. Starting application..."
2022
fi

0 commit comments

Comments
 (0)