I know this is an old thread but is the only on that came up when searching how to solve this issue, after some research and testing I have successfully used the power button to start and shutdown a vm.
I discovered that /etc/acpi/acpi_handler.sh is the script that is run on a short press of the power button, so i edited that script to run another script instead of shutting down unraid.
Below is my edited acpi_handler.sh modified to run my custom script vmstartstop.sh instead of shutting down.
nano /etc/acpi/acpi_handler.sh
#!/bin/sh
# Default acpi script that takes an entry for all actions
# limetech - power off via webGui
IFS=${IFS}/
set $@
case "$1" in
button)
case "$2" in
power) /mnt/disk1/vm/vmstartstop.sh
;;
*) logger "ACPI action $2 is not defined"
;;
esac
;;
*)
logger "ACPI group $1 / action $2 is not defined"
;;
esac
vmstartstop.sh checks to see if my vm named windows10 is running and starts it if it is not running if it is running it will shut down the windows10 vm.(not my script this is part of another script i found on another forum that does exactly what is needed)
#! /bin/bash
# only start domain if it's not already running
if ! virsh list | grep -q " ${Windows10} .*running" ; then
virsh start "Windows10"
else
# optionally shutdown domain otherwise
virsh shutdown "Windows10"
fi
I hope this helps others , as stated previously in the thread you will no longer be able to shut down unraid using the power button and will need to use the web gui to stop the array then power down or restart unraid.