Loading src/check.sh +2 −2 Original line number Diff line number Diff line Loading @@ -3,8 +3,8 @@ set -Eeuo pipefail : ${VM_NET_DEV:='eth0'} [ -f "/run/qemu.count" ] && echo "QEMU is shutting down.." && exit 1 [ ! -f "/run/qemu.pid" ] && echo "QEMU not running yet.." && exit 0 [ -f "/run/qemu.end" ] && echo "QEMU is shutting down.." && exit 1 [ ! -f "/run/qemu.pid" ] && echo "QEMU is not running yet.." && exit 0 file="/run/dsm.url" [ ! -f "$file" ] && echo "DSM has not enabled networking yet.." && exit 1 Loading src/config.sh +2 −0 Original line number Diff line number Diff line Loading @@ -14,6 +14,8 @@ if [[ "$GPU" == [Yy1]* ]] && [[ "$ARCH" == "amd64" ]]; then DEF_OPTS="$DEF_OPTS -device virtio-vga,id=video0,max_outputs=1,bus=pcie.0,addr=0x1" fi [[ "$CONSOLE" != [Yy]* ]] && DEF_OPTS="$DEF_OPTS -daemonize -D $QEMU_LOG" ARGS="$DEF_OPTS $CPU_OPTS $RAM_OPTS $MAC_OPTS $MON_OPTS $SERIAL_OPTS $NET_OPTS $DISK_OPTS $EXTRA_OPTS $ARGUMENTS" ARGS=$(echo "$ARGS" | sed 's/\t/ /g' | tr -s ' ') Loading src/entry.sh +3 −2 Original line number Diff line number Diff line Loading @@ -19,13 +19,14 @@ cd /run trap - ERR if [[ "$CONSOLE" == [Yy]* ]]; then exec qemu-system-x86_64 ${ARGS:+ $ARGS} && exit $? exec qemu-system-x86_64 ${ARGS:+ $ARGS} fi [[ "$DEBUG" == [Yy1]* ]] && info "$VERS" && set -x msg=$(qemu-system-x86_64 -daemonize ${ARGS:+ $ARGS}) msg=$(qemu-system-x86_64 ${ARGS:+ $ARGS}) { set +x; } 2>/dev/null && terminal "$msg" tail -fn +0 "$QEMU_LOG" 2>/dev/null & cat "$QEMU_TERM" 2>/dev/null & wait $! || true sleep 1 && finish 0 src/power.sh +17 −14 Original line number Diff line number Diff line Loading @@ -11,7 +11,8 @@ QEMU_TERM="" QEMU_PORT=7100 QEMU_TIMEOUT=50 QEMU_PID="/run/qemu.pid" QEMU_COUNT="/run/qemu.count" QEMU_LOG="/run/qemu.log" QEMU_END="/run/qemu.end" if [[ "$KVM" == [Nn]* ]]; then API_TIMEOUT=$(( API_TIMEOUT*2 )) Loading @@ -19,7 +20,9 @@ if [[ "$KVM" == [Nn]* ]]; then fi rm -f "$QEMU_PID" rm -f "$QEMU_COUNT" rm -f "$QEMU_LOG" rm -f "$QEMU_END" touch "$QEMU_LOG" _trap() { func="$1" ; shift Loading Loading @@ -87,17 +90,18 @@ terminal() { _graceful_shutdown() { local cnt=0 local code=$? local pid cnt response local pid url response set +e if [ -f "$QEMU_COUNT" ]; then echo && info "Ignored $1 signal, already shutting down..." if [ -f "$QEMU_END" ]; then echo && info "Received $1 signal while already shutting down..." return fi echo 0 > "$QEMU_COUNT" touch "$QEMU_END" echo && info "Received $1 signal, sending shutdown command..." if [ ! -f "$QEMU_PID" ]; then Loading Loading @@ -132,15 +136,12 @@ _graceful_shutdown() { fi while [ "$(cat $QEMU_COUNT)" -lt "$QEMU_TIMEOUT" ]; do while [ "$cnt" -lt "$QEMU_TIMEOUT" ]; do ! isAlive "$pid" && break sleep 1 # Increase the counter cnt=$(($(cat $QEMU_COUNT)+1)) echo $cnt > "$QEMU_COUNT" cnt=$((cnt+1)) [[ "$DEBUG" == [Yy1]* ]] && info "Shutting down, waiting... ($cnt/$QEMU_TIMEOUT)" Loading @@ -149,14 +150,16 @@ _graceful_shutdown() { done if [ "$(cat $QEMU_COUNT)" -ge "$QEMU_TIMEOUT" ]; then echo && error "Shutdown timeout reached!" if [ "$cnt" -ge "$QEMU_TIMEOUT" ]; then echo && error "Shutdown timeout reached, aborting..." fi finish "$code" && return "$code" } if [[ "$CONSOLE" != [Yy]* ]]; then _trap _graceful_shutdown SIGTERM SIGHUP SIGINT SIGABRT SIGQUIT fi MON_OPTS="\ -pidfile $QEMU_PID \ Loading src/print.sh +3 −2 Original line number Diff line number Diff line Loading @@ -8,10 +8,11 @@ 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; } file="/run/dsm.url" shutdown="/run/qemu.count" shutdown="/run/qemu.end" url="http://127.0.0.1:2210/read?command=10" resp_err="Guest returned an invalid response:" curl_err="Failed to connect to guest: curl error" jq_err="Failed to parse response from guest: jq error" while [ ! -f "$file" ] Loading @@ -29,7 +30,7 @@ do { json=$(curl -m 20 -sk "$url"); rc=$?; } || : [ -f "$shutdown" ] && exit 1 (( rc != 0 )) && error "Failed to connect to guest: curl error $rc" && continue (( rc != 0 )) && error "$curl_err $rc" && continue { result=$(echo "$json" | jq -r '.status'); rc=$?; } || : (( rc != 0 )) && error "$jq_err $rc ( $json )" && continue Loading Loading
src/check.sh +2 −2 Original line number Diff line number Diff line Loading @@ -3,8 +3,8 @@ set -Eeuo pipefail : ${VM_NET_DEV:='eth0'} [ -f "/run/qemu.count" ] && echo "QEMU is shutting down.." && exit 1 [ ! -f "/run/qemu.pid" ] && echo "QEMU not running yet.." && exit 0 [ -f "/run/qemu.end" ] && echo "QEMU is shutting down.." && exit 1 [ ! -f "/run/qemu.pid" ] && echo "QEMU is not running yet.." && exit 0 file="/run/dsm.url" [ ! -f "$file" ] && echo "DSM has not enabled networking yet.." && exit 1 Loading
src/config.sh +2 −0 Original line number Diff line number Diff line Loading @@ -14,6 +14,8 @@ if [[ "$GPU" == [Yy1]* ]] && [[ "$ARCH" == "amd64" ]]; then DEF_OPTS="$DEF_OPTS -device virtio-vga,id=video0,max_outputs=1,bus=pcie.0,addr=0x1" fi [[ "$CONSOLE" != [Yy]* ]] && DEF_OPTS="$DEF_OPTS -daemonize -D $QEMU_LOG" ARGS="$DEF_OPTS $CPU_OPTS $RAM_OPTS $MAC_OPTS $MON_OPTS $SERIAL_OPTS $NET_OPTS $DISK_OPTS $EXTRA_OPTS $ARGUMENTS" ARGS=$(echo "$ARGS" | sed 's/\t/ /g' | tr -s ' ') Loading
src/entry.sh +3 −2 Original line number Diff line number Diff line Loading @@ -19,13 +19,14 @@ cd /run trap - ERR if [[ "$CONSOLE" == [Yy]* ]]; then exec qemu-system-x86_64 ${ARGS:+ $ARGS} && exit $? exec qemu-system-x86_64 ${ARGS:+ $ARGS} fi [[ "$DEBUG" == [Yy1]* ]] && info "$VERS" && set -x msg=$(qemu-system-x86_64 -daemonize ${ARGS:+ $ARGS}) msg=$(qemu-system-x86_64 ${ARGS:+ $ARGS}) { set +x; } 2>/dev/null && terminal "$msg" tail -fn +0 "$QEMU_LOG" 2>/dev/null & cat "$QEMU_TERM" 2>/dev/null & wait $! || true sleep 1 && finish 0
src/power.sh +17 −14 Original line number Diff line number Diff line Loading @@ -11,7 +11,8 @@ QEMU_TERM="" QEMU_PORT=7100 QEMU_TIMEOUT=50 QEMU_PID="/run/qemu.pid" QEMU_COUNT="/run/qemu.count" QEMU_LOG="/run/qemu.log" QEMU_END="/run/qemu.end" if [[ "$KVM" == [Nn]* ]]; then API_TIMEOUT=$(( API_TIMEOUT*2 )) Loading @@ -19,7 +20,9 @@ if [[ "$KVM" == [Nn]* ]]; then fi rm -f "$QEMU_PID" rm -f "$QEMU_COUNT" rm -f "$QEMU_LOG" rm -f "$QEMU_END" touch "$QEMU_LOG" _trap() { func="$1" ; shift Loading Loading @@ -87,17 +90,18 @@ terminal() { _graceful_shutdown() { local cnt=0 local code=$? local pid cnt response local pid url response set +e if [ -f "$QEMU_COUNT" ]; then echo && info "Ignored $1 signal, already shutting down..." if [ -f "$QEMU_END" ]; then echo && info "Received $1 signal while already shutting down..." return fi echo 0 > "$QEMU_COUNT" touch "$QEMU_END" echo && info "Received $1 signal, sending shutdown command..." if [ ! -f "$QEMU_PID" ]; then Loading Loading @@ -132,15 +136,12 @@ _graceful_shutdown() { fi while [ "$(cat $QEMU_COUNT)" -lt "$QEMU_TIMEOUT" ]; do while [ "$cnt" -lt "$QEMU_TIMEOUT" ]; do ! isAlive "$pid" && break sleep 1 # Increase the counter cnt=$(($(cat $QEMU_COUNT)+1)) echo $cnt > "$QEMU_COUNT" cnt=$((cnt+1)) [[ "$DEBUG" == [Yy1]* ]] && info "Shutting down, waiting... ($cnt/$QEMU_TIMEOUT)" Loading @@ -149,14 +150,16 @@ _graceful_shutdown() { done if [ "$(cat $QEMU_COUNT)" -ge "$QEMU_TIMEOUT" ]; then echo && error "Shutdown timeout reached!" if [ "$cnt" -ge "$QEMU_TIMEOUT" ]; then echo && error "Shutdown timeout reached, aborting..." fi finish "$code" && return "$code" } if [[ "$CONSOLE" != [Yy]* ]]; then _trap _graceful_shutdown SIGTERM SIGHUP SIGINT SIGABRT SIGQUIT fi MON_OPTS="\ -pidfile $QEMU_PID \ Loading
src/print.sh +3 −2 Original line number Diff line number Diff line Loading @@ -8,10 +8,11 @@ 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; } file="/run/dsm.url" shutdown="/run/qemu.count" shutdown="/run/qemu.end" url="http://127.0.0.1:2210/read?command=10" resp_err="Guest returned an invalid response:" curl_err="Failed to connect to guest: curl error" jq_err="Failed to parse response from guest: jq error" while [ ! -f "$file" ] Loading @@ -29,7 +30,7 @@ do { json=$(curl -m 20 -sk "$url"); rc=$?; } || : [ -f "$shutdown" ] && exit 1 (( rc != 0 )) && error "Failed to connect to guest: curl error $rc" && continue (( rc != 0 )) && error "$curl_err $rc" && continue { result=$(echo "$json" | jq -r '.status'); rc=$?; } || : (( rc != 0 )) && error "$jq_err $rc ( $json )" && continue Loading