Skip to content

Instantly share code, notes, and snippets.

@martinbaillie
Created February 6, 2016 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinbaillie/fbd41bc390b9bc01d919 to your computer and use it in GitHub Desktop.
Save martinbaillie/fbd41bc390b9bc01d919 to your computer and use it in GitHub Desktop.
Bootstrap App with Rancher Metadata
#!/bin/bash -e
metadata() {
curl -s http://rancher-metadata/latest/self/service/metadata/"$1"
}
metadata_as_java_props() {
for md_key in $(metadata "$1"); do
md_value="$(metadata "$1"/"$md_key")"
if [ "$md_value" != "Not found" ]; then
local ret="$ret-D$md_key=$md_value "
fi
done
echo "$ret"
}
metadata_as_shell_vars() {
for md_key in $(metadata "$1"); do
md_value="$(metadata "$1"/"$md_key")"
if [ "$md_value" != "Not found" ]; then
export "$md_key=$md_value"
fi
done
}
wait_for_rancher_metadata() {
counter=0
printf 'Waiting for Rancher networking to use metadata service'
until curl --output /dev/null --silent --head --fail http://rancher-metadata; do
printf '.'
sleep 1
counter=$((counter + 1))
if [ "$counter" -gt 10 ]; then
echo
echo "Could not reach Rancher metadata service" >&2
exit 1
fi
done
echo
}
wait_for_rancher_metadata
metadata_as_shell_vars overrides
metadata_as_java_props overrides
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment