Delete network on shutdown
Delete network on shutdown
This commit is contained in:
commit
e4d3c3e22d
4 changed files with 37 additions and 5 deletions
|
@ -31,7 +31,10 @@ configureDHCP() {
|
|||
error "and that the NET_ADMIN capability has been added to the container config: --cap-add NET_ADMIN" && exit 16
|
||||
fi
|
||||
|
||||
ip link set "${VM_NET_TAP}" up
|
||||
while ! ip link set "${VM_NET_TAP}" up; do
|
||||
info "Waiting for address to become available..."
|
||||
sleep 2
|
||||
done
|
||||
|
||||
TAP_NR=$(</sys/class/net/"${VM_NET_TAP}"/ifindex)
|
||||
TAP_PATH="/dev/tap${TAP_NR}"
|
||||
|
@ -127,11 +130,20 @@ configureNAT () {
|
|||
fi
|
||||
|
||||
ip address add ${VM_NET_IP%.*}.1/24 broadcast ${VM_NET_IP%.*}.255 dev dockerbridge
|
||||
ip link set dockerbridge up
|
||||
|
||||
while ! ip link set dockerbridge up; do
|
||||
info "Waiting for address to become available..."
|
||||
sleep 2
|
||||
done
|
||||
|
||||
# QEMU Works with taps, set tap to the bridge created
|
||||
ip tuntap add dev "${VM_NET_TAP}" mode tap
|
||||
ip link set "${VM_NET_TAP}" up promisc on
|
||||
|
||||
while ! ip link set "${VM_NET_TAP}" up promisc on; do
|
||||
info "Waiting for tap to become available..."
|
||||
sleep 2
|
||||
done
|
||||
|
||||
ip link set dev "${VM_NET_TAP}" master dockerbridge
|
||||
|
||||
# Add internet connection to the VM
|
||||
|
@ -165,6 +177,24 @@ configureNAT () {
|
|||
return 0
|
||||
}
|
||||
|
||||
closeNetwork () {
|
||||
|
||||
if [[ "${DHCP}" == [Yy1]* ]]; then
|
||||
|
||||
ip link set "${VM_NET_TAP}" down || true
|
||||
ip link delete "${VM_NET_TAP}" || true
|
||||
|
||||
else
|
||||
|
||||
ip link set "${VM_NET_TAP}" down promisc off || true
|
||||
ip link delete "${VM_NET_TAP}" || true
|
||||
|
||||
ip link set dockerbridge down || true
|
||||
ip link delete dockerbridge || true
|
||||
|
||||
fi
|
||||
}
|
||||
|
||||
# ######################################
|
||||
# Configure Network
|
||||
# ######################################
|
||||
|
|
|
@ -50,6 +50,8 @@ _graceful_shutdown() {
|
|||
echo && echo "❯ Quitting..."
|
||||
echo 'quit' | nc -q 1 -w 1 localhost "${QEMU_MONPORT}" >/dev/null 2>&1 || true
|
||||
|
||||
closeNetwork
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ set -m
|
|||
)
|
||||
set +m
|
||||
|
||||
if (( KERNEL > 5 )) || ( (( KERNEL == 5 )) && (( MINOR > 2 )) ); then
|
||||
if (( KERNEL > 5 )) || ( (( KERNEL == 5 )) && (( MINOR > 10 )) ); then
|
||||
pidwait -F "${_QEMU_PID}" & wait $!
|
||||
else
|
||||
tail --pid "$(cat "${_QEMU_PID}")" --follow /dev/null & wait $!
|
||||
|
|
Loading…
Reference in a new issue