Add proper Cleanup script.
Chore following such addition.
This commit is contained in:
52
scripts/.cleanup.sh
Executable file
52
scripts/.cleanup.sh
Executable file
@ -0,0 +1,52 @@
|
||||
#!/bin/bash
|
||||
|
||||
stopdls() {
|
||||
if docker ps &>/dev/null | grep -q " $DLS_CTR_NAME$"; then
|
||||
pinfo "Stopping Direktil Local Server..."
|
||||
docker stop $DLS_CTR_NAME
|
||||
fi
|
||||
}
|
||||
|
||||
destroyvms() {
|
||||
for host in ${!hosts[*]}; do
|
||||
if test -f $ctxdir/data/$host/pid ; then
|
||||
pid=$(cat $ctxdir/data/$host/pid)
|
||||
pinfo "Cleaning VM $host with PID $pid..."
|
||||
kill $pid && sleep 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
cleanuppaths() {
|
||||
PATHS="data secrets kubeconfig cache dist"
|
||||
cd $ctxdir
|
||||
for path in $PATHS; do
|
||||
if test -e $path; then
|
||||
pinfo "Removing path $path ..."
|
||||
rm -rf $path
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
cleanupnetwork() {
|
||||
if iptables -L |grep -q $QEMU_BR_NAME; then
|
||||
pinfo "Cleaning iptables rules..."
|
||||
iptables -t nat -D POSTROUTING -j MASQUERADE -s $QEMU_BR_IP/$QEMU_BR_MASK \! -o $QEMU_BR_NAME
|
||||
iptables -D FORWARD -o $QEMU_BR_NAME -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
|
||||
iptables -D FORWARD -j ACCEPT -i $QEMU_BR_NAME
|
||||
fi
|
||||
if ip li show $QEMU_BR_NAME ; then
|
||||
pinfo "Cleaning existing interfaces..."
|
||||
ip li set $QEMU_BR_NAME down
|
||||
ip li del $QEMU_BR_NAME
|
||||
fi
|
||||
}
|
||||
|
||||
source $(dirname $0)/.common
|
||||
check_root
|
||||
prereqs
|
||||
stopdls
|
||||
declare -A hosts
|
||||
get_hosts
|
||||
destroyvms
|
||||
cleanuppaths
|
||||
Reference in New Issue
Block a user