|
| 1 | +#!/bin/bash |
| 2 | +set -ex |
| 3 | + |
| 4 | +FILE_PATH="/pod-data/listen_port" |
| 5 | +while [ ! -s "$FILE_PATH" ]; do |
| 6 | + echo "wait for $FILE_PATH ..." |
| 7 | + sleep 1 |
| 8 | +done |
| 9 | +WORKER_LISTEN_PORT=$(cat "$FILE_PATH") |
| 10 | + |
| 11 | +echo "# Forwards all traffic to nginx controller |
| 12 | +server { |
| 13 | + listen 32102 http2; |
| 14 | +
|
| 15 | + # No limits |
| 16 | + client_max_body_size 0; |
| 17 | + grpc_read_timeout 3600s; |
| 18 | + grpc_send_timeout 3600s; |
| 19 | + client_body_timeout 3600s; |
| 20 | + # grpc_socket_keepalive is recommended but not required |
| 21 | + # grpc_socket_keepalive is supported after nginx 1.15.6 |
| 22 | + grpc_socket_keepalive on; |
| 23 | +
|
| 24 | + grpc_set_header Authority ${EGRESS_HOST}; |
| 25 | + grpc_set_header Host ${EGRESS_HOST}; |
| 26 | + grpc_set_header X-Host ${SERVICE_ID}.${EGRESS_DOMAIN}; |
| 27 | +
|
| 28 | + location / { |
| 29 | + # Redirects to nginx controller |
| 30 | + grpc_pass grpc://fedlearner-stack-ingress-nginx-controller.default.svc:80; |
| 31 | + } |
| 32 | +} |
| 33 | +" > nginx/sidecar.conf |
| 34 | + |
| 35 | +if [ -z "$PORT0" ]; then |
| 36 | + PORT0=32001 |
| 37 | +fi |
| 38 | + |
| 39 | +if [ -z "$PORT2" ]; then |
| 40 | + PORT2=32102 |
| 41 | +fi |
| 42 | + |
| 43 | +sed -i "s/listen [0-9]* http2;/listen $PORT2 http2;/" nginx/sidecar.conf |
| 44 | + |
| 45 | +cp nginx/sidecar.conf /etc/nginx/conf.d/ |
| 46 | +service nginx restart |
| 47 | + |
| 48 | +# Server sidecar: grpc to tcp, 5001 is the server port of main container |
| 49 | +echo "Starting server sidecar" |
| 50 | +./grpc2tcp --grpc_server_port=$PORT0 \ |
| 51 | + --target_tcp_address="localhost:$WORKER_LISTEN_PORT" & |
| 52 | + |
| 53 | +echo "Starting client sidecar" |
| 54 | +./tcp2grpc --tcp_server_port="$PROXY_LOCAL_PORT" \ |
| 55 | + --target_grpc_address="localhost:$PORT2" & |
| 56 | + |
| 57 | +echo "===========Sidecar started!!=============" |
| 58 | + |
| 59 | +while true |
| 60 | +do |
| 61 | + if [[ -f "/pod-data/main-terminated" ]] |
| 62 | + then |
| 63 | + exit 0 |
| 64 | + fi |
| 65 | + sleep 5 |
| 66 | +done |
0 commit comments