-
Notifications
You must be signed in to change notification settings - Fork 1
/
nomad_reset
executable file
·44 lines (38 loc) · 959 Bytes
/
nomad_reset
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env bash
DATA_DIR="/opt/nomad/data/"
CONSUL_ADDR="http://127.0.0.1:8500"
function nomad_running {
systemctl is-active --quiet nomad
}
if nomad_running
then
echo "*** Nomad is currently running... Aborting. ***"
exit 1
fi
Mounts=`mount | grep ${DATA_DIR} | awk '{print $3}'`
if [[ `echo ${Mounts} | wc -l` -gt 0 ]]
then
echo " * Unmounting orphaned allocation mounts..."
for Mount in ${Mounts}
do
echo " - Unmounting ${Mount}..."
umount ${Mount}
done
else
echo " * Nothing to unmount."
fi
echo "Clearing out Data Directory"
rm -rf ${DATA_DIR}/*
Checks=`curl -s http://127.0.0.1:8500/v1/agent/checks | jq -r '.[] | .CheckID'`
if [[ `echo ${Checks} | wc -l` -gt 0 ]]
then
echo " * Removing stale Consul checks..."
for Check in ${Checks}
do
echo " - removing ${Check}..."
curl -XPUT http://127.0.0.1:8500/v1/agent/check/deregister/${Check}
done
else
echo "* No Consul checks to remove."
fi
echo "Done."