Spaces:
Paused
Paused
| set -e | |
| # Detect external/public IP dynamically (you can hardcode this if needed) | |
| # EXTERNAL_IP=$(curl -s https://ifconfig.me) | |
| echo "Starting ngrok in background..." | |
| NGROK_LOG=/tmp/ngrok.log | |
| ngrok start turn_tls --config /ngrok2/ngrok.yml --log=stdout --log-level=debug > "$NGROK_LOG" 2>&1 & | |
| NGROK_PID=$! | |
| echo "Waiting for ngrok TCP tunnel..." | |
| # Retry loop to wait until the TCP URL appears | |
| for i in $(seq 1 30); do | |
| # Look for tcp:// in stdout | |
| PUBLIC_TCP=$(grep -o 'tcp://[0-9a-zA-Z\.-]*:[0-9]*' "$NGROK_LOG" | head -n 1) | |
| if [ -n "$PUBLIC_TCP" ]; then | |
| break | |
| fi | |
| sleep 1 | |
| done | |
| if [ -z "$PUBLIC_TCP" ]; then | |
| echo "Error: Could not find ngrok TCP public URL." | |
| exit 1 | |
| fi | |
| echo "Ngrok public TCP URL: $PUBLIC_TCP" | |
| # Retry loop until public TCP address is available | |
| # PUBLIC_TCP="" | |
| # while [[ -z "$PUBLIC_TCP" ]]; do | |
| # sleep 2 | |
| # # Get tunnels JSON safely | |
| # JSON=$(curl -s http://127.0.0.1:7860/api/tunnels || echo "{}") | |
| # # Try parsing TCP tunnel | |
| # PUBLIC_TCP=$(echo "$JSON" | python3 -c " | |
| # import sys, json | |
| # try: | |
| # data = json.load(sys.stdin) | |
| # tunnels = data.get('tunnels', []) | |
| # for t in tunnels: | |
| # if t.get('proto')=='tcp': | |
| # print(t.get('public_url','').replace('tcp://','')) | |
| # break | |
| # except Exception: | |
| # pass | |
| # " || echo "") | |
| # done | |
| # echo "PUBLIC ip :$PUBLIC_TCP" | |
| # # Extract host and host:port | |
| TURN_HOST="${PUBLIC_TCP%%:*}" | |
| TURN_HOST_PORT="$PUBLIC_TCP" | |
| export TURN_PUBLIC_ADDR="$TURN_HOST_PORT" | |
| export TURN_HOST="$TURN_HOST" | |
| export TURN_HOST_PORT="$TURN_HOST_PORT" | |
| echo "Server $TURN_PUBLIC_ADDR, ** $TURN_HOST ** $TURN_HOST_PORT" | |
| echo "Starting turnserver..." | |
| exec turnserver \ | |
| # -c /etc/coturn/turnserver.conf \ | |
| # --listening-ip=0.0.0.0 \ | |
| --listening-port=7860 \ | |
| --tls-listening-port=5349 \ | |
| --external-ip="$TURN_PUBLIC_ADDR" \ | |
| # --cert=/etc/turn/certs/turn_server_cert.pem \ | |
| # --pkey=/etc/turn/certs/turn_server_pkey.pem \ | |
| --user=myuser:mypassword \ | |
| # --realm="$TURN_PUBLIC_ADDR" \ | |
| --log-file=stdout \ | |
| --simple-log \ | |
| --no-cli & | |
| TURN_PID=$! | |
| # Now exec turnserver as PID 1 (so Docker will forward signals to it) | |
| #cat /ngrok2/ngrok.yml | |
| #ngrok start turn_tls --config /ngrok2/ngrok.yml --log=stdout --log-level=debug | |
| # turnserver \ | |
| # -c /etc/coturn/turnserver.conf \ | |
| # --user=myuser:mypassword \ | |
| # --no-cli & | |
| # #TURN_PID=$! | |
| # ngrok config add-authtoken "$NGROK_AUTHTOKEN" | |
| # ngrok authtoken "$NGROK_AUTHTOKEN" | |
| # ngrok tls 7860 -url heather-tressy-paxton.ngrok-free.app | |
| # ngrok tcp 7860 --log=stdout & | |
| # ngrok start cli-quickstart | |
| # ngrok config check --config ngrok2/ngrok.yml | |
| # ngrok start turn_tls --config=ngrok2/ngrok.yml | |
| # #!/bin/bash | |
| # set -e | |
| # # Optional: Print ngrok config | |
| # cat /ngrok2/ngrok.yml | |
| # # Start turnserver in background | |
| #turnserver -c /etc/coturn/turnserver.conf --no-cli & | |
| #TURN_PID=$! | |
| # ngrok start turn_tls --config /ngrok2/ngrok.yml --log=stdout --log-level=debug | |
| # # Trap termination signals to cleanly stop turnserver | |
| # trap "echo 'Stopping turnserver'; kill $TURN_PID; wait $TURN_PID; exit" SIGINT SIGTERM | |
| # # Exec the CMD (ngrok command) passed as args to this script | |
| # exec "$@" |