mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-10-12 13:45:02 +08:00
feat: Improve healthcheck (#1047)
This commit is contained in:
parent
fd5ec52226
commit
21d18fd439
12
src/check.sh
12
src/check.sh
@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
|
: "${DHCP:="N"}"
|
||||||
: "${NETWORK:="Y"}"
|
: "${NETWORK:="Y"}"
|
||||||
|
|
||||||
[ -f "/run/shm/qemu.end" ] && echo "QEMU is shutting down.." && exit 1
|
[ -f "/run/shm/qemu.end" ] && echo "QEMU is shutting down.." && exit 1
|
||||||
@ -9,6 +10,7 @@ set -Eeuo pipefail
|
|||||||
|
|
||||||
file="/run/shm/dsm.url"
|
file="/run/shm/dsm.url"
|
||||||
address="/run/shm/qemu.ip"
|
address="/run/shm/qemu.ip"
|
||||||
|
gateway="/run/shm/qemu.gw"
|
||||||
|
|
||||||
[ ! -s "$file" ] && echo "DSM has not enabled networking yet.." && exit 1
|
[ ! -s "$file" ] && echo "DSM has not enabled networking yet.." && exit 1
|
||||||
|
|
||||||
@ -16,13 +18,13 @@ location=$(<"$file")
|
|||||||
|
|
||||||
if ! curl -m 20 -ILfSs "http://$location/" > /dev/null; then
|
if ! curl -m 20 -ILfSs "http://$location/" > /dev/null; then
|
||||||
|
|
||||||
if [[ "$location" == "20.20"* ]]; then
|
if [[ "$DHCP" == [Yy1]* ]]; then
|
||||||
ip="20.20.20.1"
|
ip=$(<"$address")
|
||||||
|
echo "Failed to reach DSM at http://$location"
|
||||||
|
else
|
||||||
|
ip=$(<"$gateway")
|
||||||
port="${location##*:}"
|
port="${location##*:}"
|
||||||
echo "Failed to reach DSM at port $port"
|
echo "Failed to reach DSM at port $port"
|
||||||
else
|
|
||||||
echo "Failed to reach DSM at http://$location"
|
|
||||||
ip=$(<"$address")
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "You might need to whitelist IP $ip in the DSM firewall." && exit 1
|
echo "You might need to whitelist IP $ip in the DSM firewall." && exit 1
|
||||||
|
@ -121,6 +121,8 @@ configureDNS() {
|
|||||||
local mask="$5"
|
local mask="$5"
|
||||||
local gateway="$6"
|
local gateway="$6"
|
||||||
|
|
||||||
|
echo "$gateway" > /run/shm/qemu.gw
|
||||||
|
|
||||||
[[ "${DNSMASQ_DISABLE:-}" == [Yy1]* ]] && return 0
|
[[ "${DNSMASQ_DISABLE:-}" == [Yy1]* ]] && return 0
|
||||||
[[ "$DEBUG" == [Yy1]* ]] && echo "Starting dnsmasq daemon..."
|
[[ "$DEBUG" == [Yy1]* ]] && echo "Starting dnsmasq daemon..."
|
||||||
|
|
||||||
@ -258,9 +260,10 @@ configureSlirp() {
|
|||||||
if [[ "${DNSMASQ_DISABLE:-}" != [Yy1]* ]]; then
|
if [[ "${DNSMASQ_DISABLE:-}" != [Yy1]* ]]; then
|
||||||
cp /etc/resolv.conf /etc/resolv.dnsmasq
|
cp /etc/resolv.conf /etc/resolv.dnsmasq
|
||||||
echo -e "nameserver 127.0.0.1\nsearch .\noptions ndots:0" >/etc/resolv.conf
|
echo -e "nameserver 127.0.0.1\nsearch .\noptions ndots:0" >/etc/resolv.conf
|
||||||
configureDNS "lo" "$ip" "$VM_NET_MAC" "$VM_NET_HOST" "$VM_NET_MASK" "$gateway" || return 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
configureDNS "lo" "$ip" "$VM_NET_MAC" "$VM_NET_HOST" "$VM_NET_MASK" "$gateway" || return 1
|
||||||
|
|
||||||
VM_NET_IP="$ip"
|
VM_NET_IP="$ip"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@ -368,7 +371,14 @@ configureNAT() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local ip="172.30.0.2"
|
local ip base
|
||||||
|
base=$(echo "$IP" | sed -r 's/([^.]*.){2}//')
|
||||||
|
if [[ "$IP" != "172.30."* ]]; then
|
||||||
|
ip="172.30.$base"
|
||||||
|
else
|
||||||
|
ip="172.31.$base"
|
||||||
|
fi
|
||||||
|
|
||||||
[ -n "$VM_NET_IP" ] && ip="$VM_NET_IP"
|
[ -n "$VM_NET_IP" ] && ip="$VM_NET_IP"
|
||||||
|
|
||||||
local gateway=""
|
local gateway=""
|
||||||
@ -683,6 +693,8 @@ getInfo() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo "$IP" > /run/shm/qemu.ip
|
echo "$IP" > /run/shm/qemu.ip
|
||||||
|
echo "$nic" > /run/shm/qemu.nic
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
14
src/print.sh
14
src/print.sh
@ -11,11 +11,12 @@ error () { printf "%b%s%b" "\E[1;31m❯ " "ERROR: $1" "\E[0m\n" >&2; }
|
|||||||
|
|
||||||
file="/run/shm/dsm.url"
|
file="/run/shm/dsm.url"
|
||||||
info="/run/shm/msg.html"
|
info="/run/shm/msg.html"
|
||||||
|
driver="/run/shm/qemu.nic"
|
||||||
page="/run/shm/index.html"
|
page="/run/shm/index.html"
|
||||||
address="/run/shm/qemu.ip"
|
address="/run/shm/qemu.ip"
|
||||||
shutdown="/run/shm/qemu.end"
|
shutdown="/run/shm/qemu.end"
|
||||||
template="/var/www/index.html"
|
template="/var/www/index.html"
|
||||||
url="http://127.0.0.1:$COM_PORT/read?command=10"
|
url="http://127.0.0.1:2210/read?command=10"
|
||||||
|
|
||||||
resp_err="Guest returned an invalid response:"
|
resp_err="Guest returned an invalid response:"
|
||||||
curl_err="Failed to connect to guest: curl error"
|
curl_err="Failed to connect to guest: curl error"
|
||||||
@ -56,11 +57,7 @@ do
|
|||||||
(( rc != 0 )) && error "$jq_err $rc ( $json )" && continue
|
(( rc != 0 )) && error "$jq_err $rc ( $json )" && continue
|
||||||
[[ "$ip" == "null" ]] && error "$resp_err $json" && continue
|
[[ "$ip" == "null" ]] && error "$resp_err $json" && continue
|
||||||
|
|
||||||
if [ -z "$ip" ]; then
|
[ -z "$ip" ] && continue
|
||||||
[[ "$DHCP" == [Yy1]* ]] && continue
|
|
||||||
ip="20.20.20.21"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "$ip:$port" > $file
|
echo "$ip:$port" > $file
|
||||||
|
|
||||||
done
|
done
|
||||||
@ -69,7 +66,7 @@ done
|
|||||||
|
|
||||||
location=$(<"$file")
|
location=$(<"$file")
|
||||||
|
|
||||||
if [[ "$location" != "20.20"* ]]; then
|
if [[ "$DHCP" == [Yy1]* ]]; then
|
||||||
|
|
||||||
msg="http://$location"
|
msg="http://$location"
|
||||||
title="<title>Virtual DSM</title>"
|
title="<title>Virtual DSM</title>"
|
||||||
@ -88,10 +85,11 @@ if [[ "$location" != "20.20"* ]]; then
|
|||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
|
nic=$(<"$driver")
|
||||||
ip=$(<"$address")
|
ip=$(<"$address")
|
||||||
port="${location##*:}"
|
port="${location##*:}"
|
||||||
|
|
||||||
if [[ "$ip" == "172."* ]]; then
|
if [[ "${nic,,}" != "macvlan" ]]; then
|
||||||
msg="port $port"
|
msg="port $port"
|
||||||
else
|
else
|
||||||
msg="http://$ip:$port"
|
msg="http://$ip:$port"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user