privateone commited on
Commit
7f8eb3f
·
verified ·
1 Parent(s): 5a57221

Update custom-entrypoint.sh

Browse files
Files changed (1) hide show
  1. custom-entrypoint.sh +25 -14
custom-entrypoint.sh CHANGED
@@ -7,24 +7,35 @@ set -e
7
  echo "Starting ngrok in background..."
8
  ngrok start turn_tls --config /ngrok2/ngrok.yml --log=stdout --log-level=debug &
9
  NGROK_PID=$!
10
- echo "Waiting for ngrok tunnel..."
11
- for i in $(seq 1 20); do
12
- if curl -s --max-time 1 http://127.0.0.1:7860/api/tunnels >/dev/null 2>&1; then
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  break
14
  fi
15
- sleep 1
16
  done
17
 
18
- # Fetch public TCP address
19
- PUBLIC_TCP=$(curl -s http://127.0.0.1:4040/api/tunnels \
20
- | python3 -c "import sys, json; t=json.load(sys.stdin); print(t['tunnels'][0]['public_url'].replace('tcp://',''))")
21
-
22
- echo "Ngrok public TCP address: $PUBLIC_TCP"
23
-
24
- # Export it as environment variable if needed
25
- export TURN_PUBLIC_ADDR="$PUBLIC_TCP"
26
 
27
- sleep 1
 
 
28
 
29
 
30
  echo "Starting turnserver..."
@@ -36,7 +47,7 @@ exec turnserver \
36
  # --cert=/etc/turn/certs/turn_server_cert.pem \
37
  # --pkey=/etc/turn/certs/turn_server_pkey.pem \
38
  --user=myuser:mypassword \
39
- --realm="$PUBLIC_TCP" \
40
  --log-file=stdout \
41
  --simple-log \
42
  --no-cli &
 
7
  echo "Starting ngrok in background..."
8
  ngrok start turn_tls --config /ngrok2/ngrok.yml --log=stdout --log-level=debug &
9
  NGROK_PID=$!
10
+ echo "Waiting for ngrok TCP tunnel..."
11
+
12
+ # Retry loop until public TCP address is available
13
+ PUBLIC_TCP=""
14
+ while [[ -z "$PUBLIC_TCP" ]]; do
15
+ sleep 2
16
+ PUBLIC_TCP=$(curl -s http://127.0.0.1:4040/api/tunnels \
17
+ | python3 -c "
18
+ import sys, json
19
+ tunnels=json.load(sys.stdin).get('tunnels', [])
20
+ for t in tunnels:
21
+ if t.get('proto')=='tcp':
22
+ print(t.get('public_url','').replace('tcp://',''))
23
+ break
24
+ " || echo "")
25
+
26
+ if [[ -n "$PUBLIC_TCP" ]]; then
27
+ echo "Ngrok public TCP address: $PUBLIC_TCP"
28
  break
29
  fi
 
30
  done
31
 
32
+ # Extract host and host:port
33
+ TURN_HOST="${PUBLIC_TCP%%:*}"
34
+ TURN_HOST_PORT="$PUBLIC_TCP"
 
 
 
 
 
35
 
36
+ export TURN_PUBLIC_ADDR="$TURN_HOST_PORT"
37
+ export TURN_HOST="$TURN_HOST"
38
+ export TURN_HOST_PORT="$TURN_HOST_PORT"
39
 
40
 
41
  echo "Starting turnserver..."
 
47
  # --cert=/etc/turn/certs/turn_server_cert.pem \
48
  # --pkey=/etc/turn/certs/turn_server_pkey.pem \
49
  --user=myuser:mypassword \
50
+ --realm="$TURN_PUBLIC_ADDR" \
51
  --log-file=stdout \
52
  --simple-log \
53
  --no-cli &