Skip to content

Instantly share code, notes, and snippets.

@jawi
Created December 17, 2014 12:47
Show Gist options
  • Save jawi/098673f2c2e864f152d9 to your computer and use it in GitHub Desktop.
Save jawi/098673f2c2e864f152d9 to your computer and use it in GitHub Desktop.
Shell script using jshon to purge the state information of an existing Etcd discovery service.
#!/bin/sh
#
# Usage: ./purge_etcd_discovery.sh <TOKEN>
#
# needs both `curl` and `jshon` (http://kmkeen.com/jshon/) in order to work.
#
# (C) 2014 - jawi - licensed under Apache Public License v2.
# check whether our preconditions are met...
curl --version 1>/dev/null 2>&1 || { echo "No curl binary found?!"; exit 1; }
jshon --version 1>/dev/null 2>&1 || { echo "No jshon binary found?!"; exit 1; }
ARG=$1
if [ "$ARG" == "" ]; then
echo "Usage: $0 <TOKEN>"
exit 1
fi
baseUrl="https://discovery.etcd.io"
url="$baseUrl/$ARG"
echo "Cleaning discovered nodes for $ARG..."
# Select all "key" values from "node/nodes" and unescape them; then we cut the key-value and remove the /_etcd/registry/ parts
nodes=$(curl -s $url | jshon -Q -e node -e nodes -a -e key -u | cut -d\/ -f4-)
for node in $nodes; do
echo "Deleting node '$node'..."
curl -s -XDELETE "$baseUrl/$node"
done
echo "Deleting '_state'..."
curl -s -XDELETE "$url/_state" -o /dev/null
###EOF###
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment