Created
July 20, 2015 10:40
-
-
Save seeder/021eac1ac8d4e5102161 to your computer and use it in GitHub Desktop.
Used for fetching templates from consul for use in consul-template as plugin
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/sh | |
TMPL=$1 | |
DESTINATION=/config/consultemplate/template/$TMPL | |
TMPDESTINATION=/tmp/$DESTINATION | |
LOGS=/logs/$HOSTNAME | |
mkdir -p $LOGS | |
mkdir -p "`dirname $DESTINATION`" | |
mkdir -p "`dirname $TMPDESTINATION`" | |
if curl -f -sS "$CONSUL_HTTP_ADDR/v1/kv/$TMPL?raw&token=$CONSUL_TOKEN" -o $TMPDESTINATION --stderr $LOGS/fetch.log | |
then | |
if ! grep -s "rpc error" $TMPDESTINATION | |
then | |
mv $TMPDESTINATION $DESTINATION | |
else | |
echo "$TMPDESTINATION rpc error, not overwriting files" >> $LOGS/fetch.log | |
fi | |
else | |
echo "$TMPDESTINATION curl failed, not overwriting files" >> $LOGS/fetch.log | |
fi | |
sha256sum $DESTINATION | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment