quickemu-project / quickemu

Quickly create and run optimised Windows, macOS and Linux virtual machines
MIT License
10.56k stars 460 forks source link

feat: Please add an option to kill the VM from the command line #1195

Closed popey closed 4 months ago

popey commented 4 months ago

Expected behavior

Sometimes I would like to kill the VM I started without using extreme prejudice (killall). This is especially useful when running quickemu with a headless guest.

Actual behavior

I brutally kill things for fun using sudo killall which my mum says is a bad thing to do.

Thanks

philclifford commented 4 months ago

Non-brutes might connect to the monitor with something like socat -,echo=0,icanon=0 unix-connect:alpine-latest/alpine-latest-monitor.socket and type system_powerdown (or if feeling suddenly brutal then quit)

It should be easy enough to wrap that behaviour into a quickemu option. I'd go for something where you could chose 3 options:

Would that seem OK to you ?

philclifford commented 4 months ago

hang on - quickemu --vm alpine-latest.conf --monitor-cmd system-powerdown used to be a way to do that I think. It's an option example in the man page, but now tries to run the vm again using the same disk and fails (if the vm is up). Maybe this missing feature is a bug...

popey commented 4 months ago

Already tried this.

I spun up a VM and then just manually connected to the VM using the monitor with netcat and qemu recognises but simply ignores the system_powerdown command. I think it's broken in Qemu https://gitlab.com/qemu-project/qemu/-/issues/1410

So, quickemu knows the pid, and could implement a --kill which just kill -9's the vm

philclifford commented 4 months ago

curious: system_powerdown works fine here (I tried all three options before suggesting with expected results - on 22.04 not 24.04 though ...)

looking at Martin's PR I see what's changed and broken --monitor-cmd : the disk image check always happens so it tries to check an in-use image and fails.

popey commented 4 months ago

FWIW, I also tested with Alpine Linux, thinking this was simpler. I can't get any distro to power off using the qemu monitor command system_powerdown