Skip to content

Instantly share code, notes, and snippets.

@ankurcha
Created June 9, 2015 22:00
Show Gist options
  • Save ankurcha/83649818b6dd40de033c to your computer and use it in GitHub Desktop.
Save ankurcha/83649818b6dd40de033c to your computer and use it in GitHub Desktop.
#!/bin/bash
# This script emits the task host:port for the DEPENDENCY_URI relative to the
# MARATHON_APP_ID. This is useful when getting the mongodb host:port in the
# current application pod which is located at '../../database/mongo/tasks'.
## MARATHON_HOSTS
## MARATHON_APP_ID
## DEPENDENCY_URI
if [ -z "$MARATHON_HOSTS" ]; then
exit -1
fi
if [ -z "$MARATHON_APP_ID" ]; then
exit -2
fi
if [ -z "$DEPENDENCY_URI" ]; then
DEPENDENCY_URI="../../database/mongo/tasks"
fi
# get the host:port that serves the mongodb host
for MARATHON_HOST in $MARATHON_HOSTS; do
DATABASE_TASKS_URL="http://${MARATHON_HOST}/v2/apps${MARATHON_APP_ID}/${DEPENDENCY_URI}"
TASKS=$(curl -sSfLk -m 10 ${DATABASE_TASKS_URL})
if [ $? -eq 0 ]; then
# split by space and echo the task host:port
echo $TASKS | cut -d ' ' -f 3
break
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment