Skip to content

Instantly share code, notes, and snippets.

@minyk
Last active April 3, 2017 23:41
Show Gist options
  • Save minyk/90554b465a526860b701d078d7dd6138 to your computer and use it in GitHub Desktop.
Save minyk/90554b465a526860b701d078d7dd6138 to your computer and use it in GitHub Desktop.
Find ETCD host on DC/OS using shell and jq
#!/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'
$ 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