Shell
Read from file and set into consul
$ cat consulate_set.sh
#!/bin/sh
value=`cat /opt/ms/worker/ca.crt`
#echo $value
cmd=$(consulate kv set ms/policy/worker/ca/ca-crt "$value")
$cmd
Read IP address and set into consul
$ cat test.sh
ip_address=`ifconfig eth0 2>/dev/null|awk '/inet addr:/ {print $2}'|sed 's/addr://'`
echo $ip_address
consul kv put ms/worker/"$ip_address"/a b
Migrate from one consul kv to another
#!/bin/bash
migrate(){
src_path=$1
dst_path=$2
cmd="consulate kv get -r $src_path"
echo $cmd
OUTPUT="$($cmd)"
# echo "${OUTPUT}"
# echo "$OUTPUT"
echo "$OUTPUT" | while read line;
do
# echo $line;
new_kv=${line//$src_path/$dst_path}
new_cmd="consulate kv set $new_kv"
echo $new_cmd
ret="$($new_cmd)"
# echo $ret
done
}
echo "****** calling health KV *******"
migrate "worker/cred" "myproject/policy/worker/cred"