0
0

control-vm.sh: Prefix functions

This commit is contained in:
Nils Freydank 2024-06-23 21:46:44 +02:00
parent bceb9a9710
commit daf8975e71
Signed by: nfr
GPG Key ID: 0F1DEAB2D36AD112

View File

@ -67,7 +67,7 @@
__VERSION__="0.0.0"
set_params(){
function set_params(){
# === Define default values ===
CLIPBOARD="${CLIPBOARD:-}"
CPU_CORES="${CPU_CORES:-8}"
@ -193,7 +193,7 @@ set_params(){
fi
}
# === Define functions for the actual QEMU controlling. ===
start_qemu(){
function start_qemu(){
if [[ ! -f "${PID_FILE}" ]]; then
echo "Starting VM ${GUEST_NAME}."
# Define the default architecture.
@ -211,7 +211,7 @@ start_qemu(){
echo "See ${PID_FILE} for the process ID."
fi
}
shutdown_qemu(){
function shutdown_qemu(){
if [[ -f "${PID_FILE}" ]]; then
echo "Requesting shutdown for VM ${GUEST_NAME}."
echo "system_powerdown" | socat - unix-connect:"${MONITOR_SOCKET}"
@ -219,7 +219,7 @@ shutdown_qemu(){
echo "Looks as VM ${GUEST_NAME} is already stopped."
fi
}
stop_qemu(){
function stop_qemu(){
if [[ -f "${PID_FILE}" ]]; then
echo "Forcing shutdown of VM ${GUEST_NAME}."
echo "quit" | socat - unix-connect:"${MONITOR_SOCKET}"
@ -227,7 +227,7 @@ stop_qemu(){
echo "Looks as VM ${GUEST_NAME} is already stopped."
fi
}
connect_to_vm(){
function connect_to_vm(){
if [[ -f "${PID_FILE}" ]]; then
echo "Opening a GUI for ${GUEST_NAME}."
local REMOTE_VIEWER_OPTS=(
@ -247,7 +247,7 @@ connect_to_vm(){
echo "Looks as VM ${GUEST_NAME} is not running."
fi
}
save_qemu(){
function save_qemu(){
if [[ -f "${PID_FILE}" ]]; then
SNAPSHOT_NAME="snap$(date --utc +%s)"
echo "Saving state of VM ${GUEST_NAME}."
@ -257,7 +257,7 @@ save_qemu(){
echo "Guest ${GUEST_NAME} is not running."
fi
}
pause_qemu(){
function pause_qemu(){
if [[ -f "${PID_FILE}" ]]; then
echo "Pausing the VM ${GUEST_NAME}."
echo "stop" | socat - unix-connect:"${MONITOR_SOCKET}"
@ -265,7 +265,7 @@ pause_qemu(){
echo "Guest ${GUEST_NAME} not running, nothing to pause."
fi
}
restore_qemu(){
function restore_qemu(){
if [[ -f "${PID_FILE}" ]]; then
SNAPSHOT_NAME="$(cat "${SNAPSHOT_INFO_FILE}")"
echo "Restore state of VM ${GUEST_NAME}."
@ -276,7 +276,7 @@ restore_qemu(){
echo "Guest ${GUEST_NAME} is not running, nothing to restore."
fi
}
resume_qemu(){
function resume_qemu(){
if [[ -f "${PID_FILE}" ]]; then
echo "Resuming the VM ${GUEST_NAME}."
echo "cont" | socat - unix-connect:"${MONITOR_SOCKET}"
@ -284,7 +284,7 @@ resume_qemu(){
echo "Guest ${GUEST_NAME} is not running, nothing to resume."
fi
}
print_help(){
function print_help(){
echo " ======================================================================="
echo " control-vm.sh - simple QEMU/KVM vm manager"
echo " version: ${__VERSION__}"