feat: Dynamic tunnel IP from cloud heartbeat for multi-bumblebee support

vpn-tunnel reads IP from /etc/parahub/tunnel_ip instead of hardcoded
172.16.0.2. On first boot, calls heartbeat synchronously to get assignment.
Heartbeat parses tunnel_ip from response and restarts vpn-tunnel on change.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-10 20:28:26 +00:00
parent f9c2e97ec6
commit f96a455dc8
2 changed files with 43 additions and 6 deletions

View File

@@ -37,9 +37,12 @@ PAYLOAD="{\"mac\":\"${MAC}\",\"hostname\":\"${HOSTNAME}\",\"yggdrasil_address\":
RESPONSE=""
# Use longer timeout if called from vpn-tunnel init (first boot)
CURL_TIMEOUT="${HEARTBEAT_CURL_TIMEOUT:-10}"
if [ "$ROLE" = "bee" ]; then
# Bee: no yggdrasil, use public URL only
RESPONSE=$(curl -s -m 10 -X POST \
RESPONSE=$(curl -s -m "$CURL_TIMEOUT" -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${HEARTBEAT_KEY}" \
-d "$PAYLOAD" \
@@ -47,13 +50,13 @@ if [ "$ROLE" = "bee" ]; then
else
# Bumblebee: try yggdrasil first, fallback to public
if ping6 -c 1 -W 3 200:abb9:5810:37d3:8a4c:98a6:b82b:969a >/dev/null 2>&1; then
RESPONSE=$(curl -s -m 10 -X POST \
RESPONSE=$(curl -s -m "$CURL_TIMEOUT" -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${HEARTBEAT_KEY}" \
-d "$PAYLOAD" \
"${PARAHUB_API_YGG}" 2>/dev/null)
else
RESPONSE=$(curl -s -m 10 -X POST \
RESPONSE=$(curl -s -m "$CURL_TIMEOUT" -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${HEARTBEAT_KEY}" \
-d "$PAYLOAD" \
@@ -61,6 +64,22 @@ else
fi
fi
# Parse tunnel_ip from response and update local config (Bumblebee only)
if [ "$ROLE" != "bee" ] && [ -n "$RESPONSE" ]; then
NEW_TUNNEL_IP=$(echo "$RESPONSE" | jsonfilter -e '$.tunnel_ip' 2>/dev/null)
if [ -n "$NEW_TUNNEL_IP" ]; then
OLD_TUNNEL_IP=$(cat /etc/parahub/tunnel_ip 2>/dev/null)
if [ "$OLD_TUNNEL_IP" != "$NEW_TUNNEL_IP" ]; then
echo "$NEW_TUNNEL_IP" > /etc/parahub/tunnel_ip
logger -t parahub-heartbeat "Tunnel IP updated: ${OLD_TUNNEL_IP:-none} → $NEW_TUNNEL_IP"
# Restart vpn-tunnel if it's running (IP changed)
if [ -n "$OLD_TUNNEL_IP" ]; then
/etc/init.d/parahub-vpn-tunnel restart 2>/dev/null &
fi
fi
fi
fi
# Sync paid_clients to speed control (Bumblebee only)
if [ "$ROLE" != "bee" ] && [ -x /usr/bin/parahub-speed-control ] && [ -n "$RESPONSE" ]; then
PAID_IPS=$(echo "$RESPONSE" | jsonfilter -e '$.paid_clients[*]' 2>/dev/null)