Skip to content

Instantly share code, notes, and snippets.

@hmalphettes
Created March 9, 2016 04:08
Show Gist options
  • Save hmalphettes/51eba11aadef5bbdd7cd to your computer and use it in GitHub Desktop.
Save hmalphettes/51eba11aadef5bbdd7cd to your computer and use it in GitHub Desktop.
push-to-etcd and pull-from-etcd
#!/bin/bash
# Pull from etcd the template files.
function download() {
mkdir -p "$1"
pushd "$1"
local files="$(etcdctl ls /stoic-etc/$1)"
for file in $files; do
local filename="$(basename $file)"
etcdctl get $file > $filename
done
chmod +x "*.sh" > /dev/null 2>&1 || true
popd
}
function downloads() {
for folder in $1; do
download "$folder"
done
}
downloads "bin etc/confd/conf.d etc/confd/templates"
# optional: monitoring templates
# downloads "etc/beats etc/grafana/dashboards etc/prometheus"
#!/bin/bash
# Push to etcd the template files.
function upload() {
local files=$(ls "$1")
for file in $files; do
curl http://127.0.0.1:2379/v2/keys/stoic-etc/$1/$file -XPUT --data-urlencode value@$1/$file
done
}
function uploads() {
for folder in $1; do
upload $folder
done
}
uploads "bin etc/confd/conf.d etc/confd/templates"
# optional: monitoring templates
# uploads "etc/beats etc/grafana/dashboards etc/prometheus"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment