m4f1050 Posted July 23, 2015 Share Posted July 23, 2015 Is there a way to map the power button (i.e. powerdown app that runs when you press power button) to start a KVM? Quote Link to comment
mik Posted October 9, 2016 Share Posted October 9, 2016 I am no expert on Unriad, but linux has a config file that lets you choose a command to send if the power-button is pressed. So if you can find a way to start a VM from command line you can I theory start a VM with the power-button. Quote Link to comment
JonathanM Posted October 11, 2016 Share Posted October 11, 2016 I am no expert on Unriad, but linux has a config file that lets you choose a command to send if the power-button is pressed. So if you can find a way to start a VM from command line you can I theory start a VM with the power-button. Unfortunately that is going to clash with the power down system of unraid. When unraid receives a power button signal, it starts the shutdown process. Remapping that to start a VM is probably not a good idea. Quote Link to comment
chrisaus87 Posted January 18, 2017 Share Posted January 18, 2017 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. 1 1 1 Quote Link to comment
Alby24 Posted August 14, 2021 Share Posted August 14, 2021 Do any of you know if this method still works? I know it's been a while, but I'm trying to replicate it and I cannot get my script to run. The server doesn't shutdown anymore tho, so I might be in the right direction. Quote Link to comment
Iron_Eagl Posted April 9, 2022 Share Posted April 9, 2022 Well, it has been yet a while again, but I similarly ran into the issue of the script not running, even though the server would no longer shut down. I did some more troubleshooting, and it appears there is some kind of issue calling the second script from the first. I do not care about being able to shut down the vm with the button, only starting it, and since virsh has its own error handling I was able to use this modification of the acpi script: #!/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) virsh start "your_vm_name_here_in_quotes" &> /dev/null ;; *) logger "ACPI action $2 is not defined" ;; esac ;; *) logger "ACPI group $1 / action $2 is not defined" ;; esac Quote Link to comment
Iron_Eagl Posted April 23, 2022 Share Posted April 23, 2022 (edited) And also, if you want your changes to persist reboot (as Unraid holds /etc in RAM), you should create a user script that runs at the startup of array, with the command: sed -i -e 's/\/sbin\/init 0/virsh start "your_vm_name_here_in_quotes" \&> \/dev\/null/g' /etc/acpi/acpi_handler.sh This way it will replace the normal shutdown command in the file with your "start vm" command on every boot. EDIT: Beginning with Unraid 6.10, there are now additional modifications that need to be made, per this thread: I therefore added the following lines to my script: /etc/rc.d/rc.acpid restart sed -i -e 's/#HandlePowerKey=poweroff/HandlePowerKey=ignore/g' /etc/elogind/logind.conf sed -i -e 's/#HandleSuspendKey=suspend/HandleSuspendKey=ignore/g' /etc/elogind/logind.conf sed -i -e 's/#HandleHibernateKey=hibernate/HandleHibernateKey=ignore/g' /etc/elogind/logind.conf /etc/rc.d/rc.elogind restart Edited January 1, 2023 by Iron_Eagl Changes to Unraid Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.