mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-02-24 13:30:02 +08:00
Delete network on shutdown
Delete network on shutdown
This commit is contained in:
commit
f0e5a61e73
@ -47,7 +47,7 @@ if [ -f "${DATA}" ]; then
|
||||
|
||||
REQ=$((DATA_SIZE-OLD_SIZE))
|
||||
|
||||
# Check free diskspace
|
||||
# Check free diskspace
|
||||
SPACE=$(df --output=avail -B 1 "${STORAGE}" | tail -n 1)
|
||||
|
||||
if (( REQ > SPACE )); then
|
||||
|
@ -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
|
||||
# ######################################
|
||||
|
@ -81,6 +81,8 @@ _graceful_shutdown() {
|
||||
echo && echo "❯ Quitting..."
|
||||
echo 'quit' | nc -q 1 -w 1 localhost "${QEMU_MONPORT}" >/dev/null 2>&1 || true
|
||||
|
||||
closeNetwork
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,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…
x
Reference in New Issue
Block a user