Skip to content

Instantly share code, notes, and snippets.

@dadoonet
Forked from grantr/8823-demo.sh
Last active August 29, 2015 14:11
Show Gist options
  • Save dadoonet/dbec8b17f2858edf030d to your computer and use it in GitHub Desktop.
Save dadoonet/dbec8b17f2858edf030d to your computer and use it in GitHub Desktop.
#!/bin/bash
pkill -f 'elasticsearch.*cluster.name=8823'
rm -rf data/8823
bin/elasticsearch -Des.node.master=true -Des.cluster.name=8823 -Des.node.name=master 2>&1 >/dev/null &
sleep 1
bin/elasticsearch -Des.node.master=false -Des.cluster.name=8823 -Des.node.name=data1 2>&1 >/dev/null &
sleep 1
bin/elasticsearch -Des.node.master=false -Des.cluster.name=8823 -Des.node.name=data2 2>&1 >/dev/null &
until curl -s localhost:9200/; do echo "--- waiting for master node start..."; sleep 1; done
until curl -s localhost:9201/; do echo "--- waiting for data1 node start..."; sleep 1; done
until curl -s localhost:9202/; do echo "--- waiting for data2 node start..."; sleep 1; done
curl localhost:9200/_cluster/health\?wait_for_status=green
echo; echo; echo " --- healthy cluster, no indices ---"
sleep 5
curl -XPUT localhost:9200/test/test/1 -d '{"foo":"bar"}'
curl localhost:9200/_cluster/health\?wait_for_status=green
echo; echo; echo " --- healthy cluster, one index ---"
find data/8823 -name _state
echo; echo; echo " --- index state directories ---"
sleep 5
echo "--- killing master..."
pkill -f 'elasticsearch.*master=true.*cluster.name=8823'
while pgrep -fq 'elasticsearch.*master=true.*cluster.name=8823'; do echo "waiting for node stop..."; sleep 1; done
rm -rvf data/8823/nodes/0
echo; echo "--- deleted master data directory"
find data/8823 -name _state
echo "--- data1 and data2 index state remains"
echo "--- waiting for master node start..."
bin/elasticsearch -Des.node.master=true -Des.cluster.name=8823 -Des.node.name=master 2>&1 >/dev/null &
curl localhost:9201/_cluster/health\?wait_for_status=green
echo; echo; echo "--- healthy cluster, no indices ---"
sleep 3
find data/8823 -name _state
echo "--- data1 and data2 index state deleted ---"
pkill -f 'elasticsearch.*cluster.name=8823'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment