Skip to content

Instantly share code, notes, and snippets.

@spektom
Last active September 11, 2017 18:45
Show Gist options
  • Save spektom/92c4d30d882a0540836fa5c04904ec20 to your computer and use it in GitHub Desktop.
Save spektom/92c4d30d882a0540836fa5c04904ec20 to your computer and use it in GitHub Desktop.
Ephemeral nodes in Consul
#!/bin/bash -x
if [ -z "$1" ]; then
echo "USAGE: $0 <session ID>"
exit 1
fi
read -d '' data <<EOF
{
}
EOF
curl -sS --request PUT --data "${data}" "http://localhost:8500/v1/kv/my-key?acquire=$1"
#!/bin/bash -x
read -d '' data <<EOF
{
"LockDelay": "15s",
"Name": "my-service",
"Checks": [],
"Behavior": "delete",
"TTL": "10s"
}
EOF
session_id=$(curl -sS --request PUT --data "${data}" http://localhost:8500/v1/session/create | jq .ID -r)
while true; do
sleep 5
curl -sS --request PUT http://localhost:8500/v1/session/renew/${session_id}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment