Last active
May 8, 2019 22:30
-
-
Save sl1pm4t/b74a43033226148b1aa6fb08a0afa1b2 to your computer and use it in GitHub Desktop.
Start multiple Consul sidecars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eu | |
readonly ADMIN_PORT_START=19000 | |
# Start sidecars | |
function start_consul_envoy_sidecar { | |
local -r sidecar_for="$1" | |
local -r admin_bind_port="$2" | |
echo "Start consul sidecar for $sidecar_for" | |
/usr/local/bin/consul connect envoy \ | |
-sidecar-for ${sidecar_for} \ | |
-admin-bind=127.0.0.1:${admin_bind_port} \ | |
-- -l info | |
pids[${i}]=$! | |
} | |
ADMIN_PORT=$ADMIN_PORT_START | |
# Get list of sidecars | |
for SVC in $(consul catalog services -node=$HOSTNAME | grep sidecar-proxy) | |
do | |
echo $SVC | |
ADMIN_PORT=$[$ADMIN_PORT +1] | |
svcname="${SVC/-sidecar-proxy/}" | |
start_consul_envoy_sidecar "$svcname" "$ADMIN_PORT" & | |
done | |
# Wait for subprocesses | |
for job in `jobs -p` | |
do | |
echo $job | |
wait $job | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment