Skip to content
View in the app

A better way to browse. Learn more.

Unraid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

map power button to be used by KVM virtual machine?

Featured Replies

Is there a way to map the power button (i.e. powerdown app that runs when you press power button) to start a KVM?

  • Author

BUMP!  Anybody?

  • 1 year later...

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.

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.
  • 3 months later...

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.

 

  • 4 years later...

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.

  • 7 months later...

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
  • 2 weeks later...

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 by Iron_Eagl
Changes to Unraid

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.

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.