mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-02-24 13:30:02 +08:00
parent
ff9fd9b377
commit
ce6d60c611
59
src/check.sh
59
src/check.sh
@ -9,53 +9,40 @@ file="/run/dsm.url"
|
|||||||
if [ ! -f "$file" ]; then
|
if [ ! -f "$file" ]; then
|
||||||
|
|
||||||
# Retrieve IP from guest VM for Docker healthcheck
|
# Retrieve IP from guest VM for Docker healthcheck
|
||||||
RESPONSE=$(curl -s -m 30 -S http://127.0.0.1:2210/read?command=10 2>&1)
|
|
||||||
|
|
||||||
if [[ ! "${RESPONSE}" =~ "\"success\"" ]] ; then
|
{ json=$(curl -m 30 -sk http://127.0.0.1:2210/read?command=10); rc=$?; } || :
|
||||||
echo "Failed to connect to guest: $RESPONSE" && exit 1
|
(( rc != 0 )) && echo "Failed to connect to guest: curl error $rc" && exit 1
|
||||||
|
|
||||||
|
{ result=$(echo "$json" | jq -r '.status'); rc=$?; } || :
|
||||||
|
(( rc != 0 )) && echo "Failed to parse response from guest: jq error $rc ( $json )" && exit 1
|
||||||
|
[[ "$result" == "null" ]] && echo "Guest returned invalid response: $json" && exit 1
|
||||||
|
|
||||||
|
if [[ "$result" != "success" ]] ; then
|
||||||
|
{ msg=$(echo "$json" | jq -r '.message'); rc=$?; } || :
|
||||||
|
echo "Guest replied ${result}: $msg" && exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Retrieve the HTTP port number
|
{ port=$(echo "$json" | jq -r '.data.data.dsm_setting.data.http_port'); rc=$?; } || :
|
||||||
if [[ ! "${RESPONSE}" =~ "\"http_port\"" ]] ; then
|
(( rc != 0 )) && echo "Failed to parse response from guest: jq error $rc ( $json )" && exit 1
|
||||||
echo "Failed to parse response from guest: $RESPONSE" && exit 1
|
[[ "$port" == "null" ]] && echo "Guest has not set a portnumber yet.." && exit 1
|
||||||
fi
|
[ -z "${port}" ] && echo "Guest has not set a portnumber yet.." && exit 1
|
||||||
|
|
||||||
rest=${RESPONSE#*http_port}
|
{ ip=$(echo "$json" | jq -r '.data.data.ip.data[] | select((.name=="eth0") and has("ip")).ip'); rc=$?; } || :
|
||||||
rest=${rest#*:}
|
(( rc != 0 )) && echo "Failed to parse response from guest: jq error $rc ( $json )" && exit 1
|
||||||
rest=${rest%%,*}
|
[[ "$ip" == "null" ]] && echo "Guest returned invalid response: $json" && exit 1
|
||||||
PORT=${rest%%\"*}
|
[ -z "${ip}" ] && echo "Guest has not received an IP yet.." && exit 1
|
||||||
|
|
||||||
[ -z "${PORT}" ] && echo "Guest has not set a portnumber yet.." && exit 1
|
echo "${ip}:${port}" > $file
|
||||||
|
|
||||||
# Retrieve the IP address
|
|
||||||
if [[ ! "${RESPONSE}" =~ "eth0" ]] ; then
|
|
||||||
echo "Failed to parse response from guest: $RESPONSE" && exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
rest=${RESPONSE#*eth0}
|
|
||||||
rest=${rest#*ip}
|
|
||||||
rest=${rest#*:}
|
|
||||||
rest=${rest#*\"}
|
|
||||||
IP=${rest%%\"*}
|
|
||||||
|
|
||||||
[ -z "${IP}" ] && echo "Guest has not received an IP yet.." && exit 1
|
|
||||||
|
|
||||||
echo "${IP}:${PORT}" > $file
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
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
|
||||||
rm -f $file
|
rm -f $file
|
||||||
echo "Failed to reach http://${LOCATION}"
|
echo "Failed to reach http://${location}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$LOCATION" == "20.20"* ]]; then
|
echo "Healthcheck OK"
|
||||||
echo "Healthcheck OK"
|
|
||||||
else
|
|
||||||
echo "Healthcheck OK ( ${LOCATION%:*} )"
|
|
||||||
fi
|
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
72
src/print.sh
72
src/print.sh
@ -1,8 +1,8 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
info () { echo -e >&2 "\E[1;34m❯\E[1;36m $1\E[0m" ; }
|
info () { printf "%b%s%b" "\E[1;34m❯ \E[1;36m" "$1" "\E[0m\n" >&2; }
|
||||||
error () { echo -e >&2 "\E[1;31m❯ ERROR: $1\E[0m" ; }
|
error () { printf "%b%s%b" "\E[1;31m❯ " "ERROR: $1" "\E[0m\n" >&2; }
|
||||||
|
|
||||||
file="/run/dsm.url"
|
file="/run/dsm.url"
|
||||||
|
|
||||||
@ -14,53 +14,53 @@ do
|
|||||||
|
|
||||||
# Retrieve IP from guest VM
|
# Retrieve IP from guest VM
|
||||||
|
|
||||||
set +e
|
{ json=$(curl -m 30 -sk http://127.0.0.1:2210/read?command=10); rc=$?; } || :
|
||||||
RESPONSE=$(curl -s -m 30 -S http://127.0.0.1:2210/read?command=10 2>&1)
|
(( rc != 0 )) && error "Failed to connect to guest: curl error $rc" && continue
|
||||||
set -e
|
|
||||||
|
|
||||||
if [[ ! "${RESPONSE}" =~ "\"success\"" ]] ; then
|
{ result=$(echo "$json" | jq -r '.status'); rc=$?; } || :
|
||||||
error "Failed to connect to guest: $RESPONSE" && continue
|
(( rc != 0 )) && error "Failed to parse response from guest: jq error $rc ( $json )" && continue
|
||||||
|
[[ "$result" == "null" ]] && error "Guest returned invalid response: $json" && continue
|
||||||
|
|
||||||
|
if [[ "$result" != "success" ]] ; then
|
||||||
|
{ msg=$(echo "$json" | jq -r '.message'); rc=$?; } || :
|
||||||
|
error "Guest replied ${result}: $msg" && continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Retrieve the HTTP port number
|
{ port=$(echo "$json" | jq -r '.data.data.dsm_setting.data.http_port'); rc=$?; } || :
|
||||||
if [[ ! "${RESPONSE}" =~ "\"http_port\"" ]] ; then
|
(( rc != 0 )) && error "Failed to parse response from guest: jq error $rc ( $json )" && continue
|
||||||
error "Failed to parse response from guest: $RESPONSE" && continue
|
[[ "$port" == "null" ]] && error "Guest returned invalid response: $json" && continue
|
||||||
fi
|
[ -z "${port}" ] && continue
|
||||||
|
|
||||||
rest=${RESPONSE#*http_port}
|
{ ip=$(echo "$json" | jq -r '.data.data.ip.data[] | select((.name=="eth0") and has("ip")).ip'); rc=$?; } || :
|
||||||
rest=${rest#*:}
|
(( rc != 0 )) && error "Failed to parse response from guest: jq error $rc ( $json )" && continue
|
||||||
rest=${rest%%,*}
|
[[ "$ip" == "null" ]] && error "Guest returned invalid response: $json" && continue
|
||||||
PORT=${rest%%\"*}
|
[ -z "${ip}" ] && continue
|
||||||
|
|
||||||
[ -z "${PORT}" ] && continue
|
echo "${ip}:${port}" > $file
|
||||||
|
|
||||||
# Retrieve the IP address
|
|
||||||
if [[ ! "${RESPONSE}" =~ "eth0" ]] ; then
|
|
||||||
error "Failed to parse response from guest: $RESPONSE" && continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
rest=${RESPONSE#*eth0}
|
|
||||||
rest=${rest#*ip}
|
|
||||||
rest=${rest#*:}
|
|
||||||
rest=${rest#*\"}
|
|
||||||
IP=${rest%%\"*}
|
|
||||||
|
|
||||||
[ -z "${IP}" ] && continue
|
|
||||||
|
|
||||||
echo "${IP}:${PORT}" > $file
|
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
LOCATION=$(cat "$file")
|
location=$(cat "$file")
|
||||||
|
|
||||||
|
if [[ "$location" != "20.20"* ]]; then
|
||||||
|
|
||||||
|
msg="http://${location}"
|
||||||
|
|
||||||
if [[ "$LOCATION" == "20.20"* ]]; then
|
|
||||||
MSG="port ${LOCATION##*:}"
|
|
||||||
else
|
else
|
||||||
MSG="http://${LOCATION}"
|
|
||||||
|
ip=$(ip address show dev eth0 | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/)
|
||||||
|
port="${location##*:}"
|
||||||
|
|
||||||
|
if [[ "$ip" == "172."* ]]; then
|
||||||
|
msg="port ${port}"
|
||||||
|
else
|
||||||
|
msg="http://${ip}:${port}"
|
||||||
|
fi
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "" >&2
|
echo "" >&2
|
||||||
info "--------------------------------------------------------"
|
info "--------------------------------------------------------"
|
||||||
info " You can now login to DSM at ${MSG}"
|
info " You can now login to DSM at ${msg}"
|
||||||
info "--------------------------------------------------------"
|
info "--------------------------------------------------------"
|
||||||
echo "" >&2
|
echo "" >&2
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
info () { echo -e "\E[1;34m❯ \E[1;36m$1\E[0m" ; }
|
info () { printf "%b%s%b" "\E[1;34m❯ \E[1;36m" "$1" "\E[0m\n"; }
|
||||||
error () { echo -e >&2 "\E[1;31m❯ ERROR: $1\E[0m" ; }
|
error () { printf "%b%s%b" "\E[1;31m❯ " "ERROR: $1" "\E[0m\n" >&2; }
|
||||||
|
|
||||||
trap 'error "Status $? while: ${BASH_COMMAND} (line $LINENO/$BASH_LINENO)"' ERR
|
trap 'error "Status $? while: ${BASH_COMMAND} (line $LINENO/$BASH_LINENO)"' ERR
|
||||||
|
|
||||||
[ ! -f "/run/entry.sh" ] && error "Script must run inside Docker container!" && exit 11
|
[ ! -f "/run/entry.sh" ] && error "Script must run inside Docker container!" && exit 11
|
||||||
|
Loading…
x
Reference in New Issue
Block a user