From 8615047c9b0ec25e3d06cf8bf03a6a3c9692f92c Mon Sep 17 00:00:00 2001 From: WeeXnes Date: Thu, 27 Feb 2025 09:20:21 +0100 Subject: [PATCH] added force shutdown toggle --- pages/index.vue | 25 ++++++++++++++++++++----- server/api/controlVM.ts | 10 +++++----- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index 523799a..ef70cd9 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -33,6 +33,7 @@ const shutdownVm = async (vm: any) => { try { const response = await axios.post('/api/controlVM', { action: 'shutdown', + force: settings.force_shutdown, vm: vm }); console.log(response.data); @@ -53,6 +54,7 @@ const settings = reactive({ ignoreCache: false, enable_services: false, enable_qemu_controls: false, + force_shutdown: false }); const vmInfo = reactive({ @@ -274,6 +276,16 @@ onMounted(async () => {

QEMU Virtual Machines

+
+ +
{

Max Memory: {{ vm.maxMemory }} MB

Autostart: {{ vm.autostart ? 'Enabled' : 'Disabled' }}

+
- +
+

Services

{

Name: {{ service.name }}

State: {{ service.state ? "Running" : "Not Running" }}

-
- - -
diff --git a/server/api/controlVM.ts b/server/api/controlVM.ts index 5636008..83dd54f 100644 --- a/server/api/controlVM.ts +++ b/server/api/controlVM.ts @@ -3,17 +3,17 @@ import Logger from "~/core/logger"; export default defineEventHandler(async (event) => { const body = await readBody(event); - const { action, vm } = body; + const { action, force, vm } = body; try { - const command = action === 'start' - ? `virsh start ${vm.name}` - : `virsh shutdown ${vm.name}`; + const command = action === 'start' ? `virsh start ${vm.name}` : (force ? `virsh destroy ${vm.name}` : `virsh shutdown ${vm.name}`); + + console.log(command); await new Promise((resolve, reject) => { exec(command, (error, stdout, stderr) => { - if (error || stderr) {; + if (error || stderr) { Logger.error(`Error: ${stderr || error?.message}`); reject(`Error: ${stderr || error?.message}`) }