Gracefully stop VMs on UPS power


Recommended Posts

I have a NiceHash OS vm that I like to run in the background when I'm not using my gpu or on vacation. I often lose power for several seconds or minutes at a time where I live, and since the GPU draws so much power when mining the UPS can only run for 1-2 minutes on UPS power alone, which is also about the amount of time unraid needs to power down. Thus UPS daemon immediately will shutdown unRaid upon power loss, and If I'm away for several days I have no way to restart unraid once power is regained (I know you can use ACPI, but it won't work if it's a clean shutdown).

 

I don't know how many other miners are using unraid, but I think it could be beneficial to be able to shutdown VMs or Docker containers upon power loss in order to maximize time on UPS, and then start them back up once power is back. It could be defined as a low-power mode where you can define critical containers or vms.

  • Like 2
Link to comment

It would be nice to have a full suite of options related to the UPS already built into Unraid in a pretty GUI.  But I imagine that it would be a good amount of work to create such a utility for all the available options, or even to get to a basic starting point of a couple options..

 

Until then, you can create your own scripts to do what you want..  https://www.systutorials.com/docs/linux/man/8-apccontrol/

 

apcupsd already creates the relevant status updates for power events, you'd just have to configure those events to trigger a script that did something like virsh shutdown <name of vm> or even virsh suspend to pause the VM without fully shutting it down if the power outage is only a couple seconds you may not want to shut it down and restart it

 

https://libvirt.org/manpages/virsh.html

Link to comment

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.