-
Notifications
You must be signed in to change notification settings - Fork 19
/
cleanup.sh
executable file
·42 lines (37 loc) · 1.16 KB
/
cleanup.sh
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
#!/bin/bash
if [[ "$UID" != "0" ]]; then
echo "This script must be run as root!"
exit 1
fi
_dname=$(dirname "$0")
BDIR=$(cd "$_dname"; pwd -P)
# Get config-specific settings (i.e. to override GROUPNUMBER)
_settings="${BDIR}/settings"
if [ -x "$_settings" ]; then
source "$_settings"
fi
echo 'Destroying the root bridges'
# Gracefully disconnect from the bridge in the root namespace (if any)
for i in eth1\
eth2 eth3 eth4 eth5 eth6 eth7; do
# Destroy slave of "br$i" because it does not always get destroyed
slave=$(ip link | grep "\-$i" | cut -d ":" -f 2 | cut -c 2-)
if ! [ -z "${slave}" ]; then
ip link del dev "${slave}"
fi
ip link del dev "br$i" &> /dev/null
done
# Cleanup all network namespaces
for ns in $(ip netns list) ; do
echo "Killing namespace $ns"
# Kill all processes running in the namespaces
# First SIGTERM
ip netns pids "$ns" | xargs '-I{}' kill '{}'
sleep .05
# Then SIGKILL
ip netns pids "$ns" | xargs '-I{}' kill -s 9 '{}'
# Destroy the net NS --- All interfaces/bridges will be destroyed alonside
ip netns del "$ns"
done
# Destroy bird/zebra temp files
rm -f /tmp/*.{api,ctl}