mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-11-06 18:13:43 +08:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
007d20c315 | ||
|
|
26d6fa9fcc | ||
|
|
b9f3e52ba4 |
@@ -20,4 +20,4 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- /opt/dsm:/storage
|
- /opt/dsm:/storage
|
||||||
restart: on-failure
|
restart: on-failure
|
||||||
stop_grace_period: 1m
|
stop_grace_period: 2m
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- /opt/dsm:/storage
|
- /opt/dsm:/storage
|
||||||
restart: on-failure
|
restart: on-failure
|
||||||
stop_grace_period: 1m
|
stop_grace_period: 2m
|
||||||
```
|
```
|
||||||
|
|
||||||
Via `docker run`
|
Via `docker run`
|
||||||
|
|||||||
35
src/check.sh
35
src/check.sh
@@ -1,21 +1,30 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
[ ! -f "/run/qemu.pid" ] && echo "QEMU not running yet.." && exit 0
|
|
||||||
[ -f "/run/qemu.count" ] && echo "QEMU is shutting down.." && exit 1
|
|
||||||
|
|
||||||
file="/run/dsm.url"
|
file="/run/dsm.url"
|
||||||
|
active="/run/qemu.pid"
|
||||||
|
shutdown="/run/qemu.count"
|
||||||
|
url="http://127.0.0.1:2210/read?command=10"
|
||||||
|
|
||||||
|
active_msg="QEMU not running yet.."
|
||||||
|
shutdown_msg="QEMU is shutting down.."
|
||||||
|
resp_err="Guest returned an invalid response:"
|
||||||
|
jq_err="Failed to parse response from guest: jq error"
|
||||||
|
|
||||||
|
[ ! -f "$active" ] && echo "$active_msg" && exit 0
|
||||||
|
[ -f "$shutdown" ] && echo "$shutdown_msg" && exit 1
|
||||||
|
|
||||||
if [ ! -f "$file" ]; then
|
if [ ! -f "$file" ]; then
|
||||||
|
|
||||||
# Retrieve IP from guest VM for Docker healthcheck
|
# Retrieve IP from guest VM for Docker healthcheck
|
||||||
|
{ json=$(curl -m 20 -sk "$url"); rc=$?; } || :
|
||||||
|
|
||||||
{ json=$(curl -m 30 -sk http://127.0.0.1:2210/read?command=10); rc=$?; } || :
|
[ -f "$shutdown" ] && echo "$shutdown_msg" && exit 1
|
||||||
(( rc != 0 )) && echo "Failed to connect to guest: curl error $rc" && exit 1
|
(( rc != 0 )) && echo "Failed to connect to guest: curl error $rc" && exit 1
|
||||||
|
|
||||||
{ result=$(echo "$json" | jq -r '.status'); rc=$?; } || :
|
{ result=$(echo "$json" | jq -r '.status'); rc=$?; } || :
|
||||||
(( rc != 0 )) && echo "Failed to parse response from guest: jq error $rc ( $json )" && exit 1
|
(( rc != 0 )) && echo "$jq_err $rc ( $json )" && exit 1
|
||||||
[[ "$result" == "null" ]] && echo "Guest returned invalid response: $json" && exit 1
|
[[ "$result" == "null" ]] && echo "$resp_err $json" && exit 1
|
||||||
|
|
||||||
if [[ "$result" != "success" ]] ; then
|
if [[ "$result" != "success" ]] ; then
|
||||||
{ msg=$(echo "$json" | jq -r '.message'); rc=$?; } || :
|
{ msg=$(echo "$json" | jq -r '.message'); rc=$?; } || :
|
||||||
@@ -23,24 +32,26 @@ if [ ! -f "$file" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
{ port=$(echo "$json" | jq -r '.data.data.dsm_setting.data.http_port'); rc=$?; } || :
|
{ port=$(echo "$json" | jq -r '.data.data.dsm_setting.data.http_port'); rc=$?; } || :
|
||||||
(( rc != 0 )) && echo "Failed to parse response from guest: jq error $rc ( $json )" && exit 1
|
(( rc != 0 )) && echo "$jq_err $rc ( $json )" && exit 1
|
||||||
[[ "$port" == "null" ]] && echo "Guest has not set a portnumber yet.." && exit 1
|
[[ "$port" == "null" ]] && echo "$resp_err $json" && exit 1
|
||||||
[ -z "$port" ] && echo "Guest has not set a portnumber yet.." && exit 1
|
[ -z "$port" ] && echo "Guest has not set a portnumber yet.." && exit 1
|
||||||
|
|
||||||
{ ip=$(echo "$json" | jq -r '.data.data.ip.data[] | select((.name=="eth0") and has("ip")).ip'); rc=$?; } || :
|
{ ip=$(echo "$json" | jq -r '.data.data.ip.data[] | select((.name=="eth0") and has("ip")).ip'); rc=$?; } || :
|
||||||
(( rc != 0 )) && echo "Failed to parse response from guest: jq error $rc ( $json )" && exit 1
|
(( rc != 0 )) && echo "$jq_err $rc ( $json )" && exit 1
|
||||||
[[ "$ip" == "null" ]] && echo "Guest returned invalid response: $json" && exit 1
|
[[ "$ip" == "null" ]] && echo "$resp_err $json" && exit 1
|
||||||
[ -z "$ip" ] && echo "Guest has not received an IP yet.." && exit 1
|
[ -z "$ip" ] && echo "Guest has not received an IP yet.." && exit 1
|
||||||
|
|
||||||
echo "$ip:$port" > $file
|
echo "$ip:$port" > $file
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
[ -f "$shutdown" ] && echo "$shutdown_msg" && exit 1
|
||||||
|
|
||||||
location=$(cat "$file")
|
location=$(cat "$file")
|
||||||
|
|
||||||
if ! curl -m 20 -ILfSs "http://$location/" > /dev/null; then
|
if ! curl -m 20 -ILfSs "http://$location/" > /dev/null; then
|
||||||
echo "Failed to reach http://$location"
|
[ -f "$shutdown" ] && echo "$shutdown_msg" && exit 1
|
||||||
exit 1
|
echo "Failed to reach page at http://$location" && exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Healthcheck OK"
|
echo "Healthcheck OK"
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ DL_GLOBAL="https://global.synologydownload.com/download/DSM"
|
|||||||
|
|
||||||
if [ -z "$DL" ]; then
|
if [ -z "$DL" ]; then
|
||||||
[ -z "$COUNTRY" ] && setCountry
|
[ -z "$COUNTRY" ] && setCountry
|
||||||
|
[ -z "$COUNTRY" ] && info "Warning: could not detect country to select mirror!"
|
||||||
[[ "${COUNTRY^^}" == "CN" ]] && DL="$DL_CHINA" || DL="$DL_GLOBAL"
|
[[ "${COUNTRY^^}" == "CN" ]] && DL="$DL_CHINA" || DL="$DL_GLOBAL"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -156,11 +156,15 @@ closeNetwork () {
|
|||||||
|
|
||||||
if [[ "$DHCP" == [Yy1]* ]]; then
|
if [[ "$DHCP" == [Yy1]* ]]; then
|
||||||
|
|
||||||
|
{ pkill -f server.sh || true; } 2>/dev/null
|
||||||
|
|
||||||
ip link set "$VM_NET_TAP" down || true
|
ip link set "$VM_NET_TAP" down || true
|
||||||
ip link delete "$VM_NET_TAP" || true
|
ip link delete "$VM_NET_TAP" || true
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
|
{ pkill -f dnsmasq || true; } 2>/dev/null
|
||||||
|
|
||||||
ip link set "$VM_NET_TAP" down promisc off || true
|
ip link set "$VM_NET_TAP" down promisc off || true
|
||||||
ip link delete "$VM_NET_TAP" || true
|
ip link delete "$VM_NET_TAP" || true
|
||||||
|
|
||||||
|
|||||||
18
src/power.sh
18
src/power.sh
@@ -27,17 +27,23 @@ _graceful_shutdown() {
|
|||||||
[ -f "$QEMU_COUNT" ] && return
|
[ -f "$QEMU_COUNT" ] && return
|
||||||
|
|
||||||
echo 0 > "$QEMU_COUNT"
|
echo 0 > "$QEMU_COUNT"
|
||||||
echo && info "Received $1 signal, shutting down..."
|
echo && info "Received $1 signal, sending shutdown command..."
|
||||||
|
|
||||||
# Don't send the powerdown signal because vDSM ignores ACPI signals
|
# Don't send the powerdown signal because vDSM ignores ACPI signals
|
||||||
# echo 'system_powerdown' | nc -q 1 -w 1 localhost "${QEMU_PORT}" > /dev/null
|
# echo 'system_powerdown' | nc -q 1 -w 1 localhost "${QEMU_PORT}" > /dev/null
|
||||||
|
|
||||||
# Send shutdown command to guest agent via serial port
|
# Send shutdown command to guest agent via serial port
|
||||||
response=$(curl -sk -m 30 -S http://127.0.0.1:2210/read?command=6 2>&1)
|
url="http://127.0.0.1:2210/read?command=6&timeout=50"
|
||||||
|
response=$(curl -sk -m 52 -S "$url" 2>&1)
|
||||||
|
|
||||||
if [[ ! "$response" =~ "\"success\"" ]]; then
|
if [[ "$response" =~ "\"success\"" ]]; then
|
||||||
|
|
||||||
echo && error "Failed to send shutdown command ( $response )."
|
echo && info "Virtual DSM is now ready to shutdown..."
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
response="${response#*message\"\: \"}"
|
||||||
|
echo && error "Failed to send shutdown command: ${response%%\"*}"
|
||||||
|
|
||||||
kill -15 "$(cat "$QEMU_PID")"
|
kill -15 "$(cat "$QEMU_PID")"
|
||||||
pkill -f qemu-system-x86_64 || true
|
pkill -f qemu-system-x86_64 || true
|
||||||
@@ -64,7 +70,11 @@ _graceful_shutdown() {
|
|||||||
echo && echo "❯ Quitting..."
|
echo && echo "❯ Quitting..."
|
||||||
echo 'quit' | nc -q 1 -w 1 localhost "$QEMU_PORT" >/dev/null 2>&1 || true
|
echo 'quit' | nc -q 1 -w 1 localhost "$QEMU_PORT" >/dev/null 2>&1 || true
|
||||||
|
|
||||||
|
{ pkill -f print.sh || true; } 2>/dev/null
|
||||||
|
{ pkill -f host.bin || true; } 2>/dev/null
|
||||||
|
|
||||||
closeNetwork
|
closeNetwork
|
||||||
|
sleep 1
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
30
src/print.sh
30
src/print.sh
@@ -5,21 +5,33 @@ info () { printf "%b%s%b" "\E[1;34m❯ \E[1;36m" "$1" "\E[0m\n" >&2; }
|
|||||||
error () { printf "%b%s%b" "\E[1;31m❯ " "ERROR: $1" "\E[0m\n" >&2; }
|
error () { printf "%b%s%b" "\E[1;31m❯ " "ERROR: $1" "\E[0m\n" >&2; }
|
||||||
|
|
||||||
file="/run/dsm.url"
|
file="/run/dsm.url"
|
||||||
|
shutdown="/run/qemu.count"
|
||||||
|
url="http://127.0.0.1:2210/read?command=10"
|
||||||
|
resp_err="Guest returned an invalid response:"
|
||||||
|
jq_err="Failed to parse response from guest: jq error"
|
||||||
|
|
||||||
while [ ! -f "$file" ]
|
while [ ! -f "$file" ]
|
||||||
do
|
do
|
||||||
|
|
||||||
|
# Check if not shutting down
|
||||||
|
[ -f "$shutdown" ] && exit 1
|
||||||
|
|
||||||
sleep 3
|
sleep 3
|
||||||
[ -f "$file" ] && continue
|
|
||||||
|
[ -f "$shutdown" ] && exit 1
|
||||||
|
|
||||||
|
# Healthcheck may have intervened
|
||||||
|
[ -f "$file" ] && break
|
||||||
|
|
||||||
# Retrieve IP from guest VM
|
# Retrieve IP from guest VM
|
||||||
|
{ json=$(curl -m 20 -sk "$url"); rc=$?; } || :
|
||||||
|
|
||||||
{ json=$(curl -m 30 -sk http://127.0.0.1:2210/read?command=10); rc=$?; } || :
|
[ -f "$shutdown" ] && exit 1
|
||||||
(( rc != 0 )) && error "Failed to connect to guest: curl error $rc" && continue
|
(( rc != 0 )) && error "Failed to connect to guest: curl error $rc" && continue
|
||||||
|
|
||||||
{ result=$(echo "$json" | jq -r '.status'); rc=$?; } || :
|
{ result=$(echo "$json" | jq -r '.status'); rc=$?; } || :
|
||||||
(( rc != 0 )) && error "Failed to parse response from guest: jq error $rc ( $json )" && continue
|
(( rc != 0 )) && error "$jq_err $rc ( $json )" && continue
|
||||||
[[ "$result" == "null" ]] && error "Guest returned invalid response: $json" && continue
|
[[ "$result" == "null" ]] && error "$resp_err $json" && continue
|
||||||
|
|
||||||
if [[ "$result" != "success" ]] ; then
|
if [[ "$result" != "success" ]] ; then
|
||||||
{ msg=$(echo "$json" | jq -r '.message'); rc=$?; } || :
|
{ msg=$(echo "$json" | jq -r '.message'); rc=$?; } || :
|
||||||
@@ -27,19 +39,21 @@ do
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
{ port=$(echo "$json" | jq -r '.data.data.dsm_setting.data.http_port'); rc=$?; } || :
|
{ port=$(echo "$json" | jq -r '.data.data.dsm_setting.data.http_port'); rc=$?; } || :
|
||||||
(( rc != 0 )) && error "Failed to parse response from guest: jq error $rc ( $json )" && continue
|
(( rc != 0 )) && error "$jq_err $rc ( $json )" && continue
|
||||||
[[ "$port" == "null" ]] && error "Guest returned invalid response: $json" && continue
|
[[ "$port" == "null" ]] && error "$resp_err $json" && continue
|
||||||
[ -z "$port" ] && continue
|
[ -z "$port" ] && continue
|
||||||
|
|
||||||
{ ip=$(echo "$json" | jq -r '.data.data.ip.data[] | select((.name=="eth0") and has("ip")).ip'); rc=$?; } || :
|
{ ip=$(echo "$json" | jq -r '.data.data.ip.data[] | select((.name=="eth0") and has("ip")).ip'); rc=$?; } || :
|
||||||
(( rc != 0 )) && error "Failed to parse response from guest: jq error $rc ( $json )" && continue
|
(( rc != 0 )) && error "$jq_err $rc ( $json )" && continue
|
||||||
[[ "$ip" == "null" ]] && error "Guest returned invalid response: $json" && continue
|
[[ "$ip" == "null" ]] && error "$resp_err $json" && continue
|
||||||
[ -z "$ip" ] && continue
|
[ -z "$ip" ] && continue
|
||||||
|
|
||||||
echo "$ip:$port" > $file
|
echo "$ip:$port" > $file
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
[ -f "$shutdown" ] && exit 1
|
||||||
|
|
||||||
location=$(cat "$file")
|
location=$(cat "$file")
|
||||||
|
|
||||||
if [[ "$location" != "20.20"* ]]; then
|
if [[ "$location" != "20.20"* ]]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user