Skip to content

Instantly share code, notes, and snippets.

@russparsloe russparsloe/.Consul B-Sides Secret
Last active Feb 27, 2019

Embed
What would you like to do?
Consul B-Sides demo
Recording of this webinar can be found here - https://www.hashicorp.com/resources/consul-b-sides-exploring-powerful-features
#!/bin/bash
consul-template -template "index.ctmpl:index.html:echo New webpage generated" -log-level=err
#!/bin/bash
consul agent -dev -config-file=./consul.json
#!/bin/bash
consul kv put service/http/port 80
consul kv put service/http/log_dir "/var/log/httpd/access_log"
consul kv put website/title "Dynamic configuration with Consul"
consul kv put website/content "Consul-Template is great!"
#!/bin/bash
echo "HTTP port"
curl -s http://localhost:8500/v1/kv/service/http/port | jq
echo
index=$(curl -s http://localhost:8500/v1/kv/service/http/port | jq -r ".[].ModifyIndex")
echo "Waiting for changes"
curl -s http://localhost:8500/v1/kv/service/http/port?index=$index | jq
#!/bin/bash
echo "Watching for changes to log_dir"
consul watch -type=key -key=service/http/log_dir "jq -r .Value | base64 -D && echo"
#!/bin/bash
echo "Creating event"
consul event -name broadcast "Sample Payload"
sleep 3
consul watch -type=event -name=broadcast jq
#!/bin/bash
for i in {1..5}
do
consul lock service/http/lock "echo Process $i has the lock && sleep 10 && echo Process $i has released the lock" &
done
wait
#!/bin/bash
for i in {1..5}
do
consul lock -n=2 service/http/lock "echo Process $i has the lock && sleep 10 && echo Process $i has released the lock" &
done
wait
#!/bin/bash
echo "Checking uptime"
consul exec uptime
echo
sleep 5
echo "Pinging Google DNS"
consul exec ping -c 5 8.8.8.8
echo
sleep 5
echo "Storing uptimes in K/V store"
consul exec 'consul kv put machines/$(hostname)/uptime "$(uptime)"'
#!/bin/bash
consul-template -template "index.ctmpl:index.html:echo New webpage generated" -log-level=err -once
{
"disable_remote_exec": false
}
<h1>{{ key "website/title" }}</h1>
<p>We have a great webpage for you!</p>
<p>{{ key "website/content" }}</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.