Last active
April 3, 2017 23:41
-
-
Save minyk/90554b465a526860b701d078d7dd6138 to your computer and use it in GitHub Desktop.
Find ETCD host on DC/OS using shell and jq
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 | |
ETCD_SERVICE_NAME=$1 | |
SRV_RECORDS=`curl -s http://leader.mesos:8123/v1/services/_etcd-server._client.${ETCD_SERVICE_NAME}.mesos` | |
ETCD_INSTANCES=`echo $SRV_RECORDS | jq '.|length'` | |
SELECTED_INSTANCE=$(($RANDOM % ${ETCD_INSTANCES} )) | |
echo ${SRV_RECORDS} | jq --argjson index ${SELECTED_INSTANCE} '[.[$index].host[:40], ":", .[$index].port]|add' |
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
$ sh find-etcd.sh etcd-cluster | |
"etcd-server-c861s-s11.etcd-cluster.mesos:1026" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment