-
-
Save logic855/81dccbba94fe0db1616d6bc31696b8da 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 hidden or 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