BetaQuasi Posted March 30, 2013 Share Posted March 30, 2013 Thought I'd write up a quick howto on this as well - one of those things that's buried in various threads. Having recently found a much cleaner way of shutting down the VM's, I thought it was worth sharing. Note there are quite a few different ways of doing this - this is just one way that works very well for me. What you'll need: A VM running Windows/Linux, with apcupsd installed (I use a Windows VM (Server 2012 Domain Controller) as for whatever reason, Linux doesn't give full UPS stats on my APC UPS) Plink utility from the maker of Putty: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html Powerdown script 1.02 installed on unRAID: http://unraid-powercontrol.googlecode.com/files/powerdown-1.02-noarch-unRAID.tgz A UPS (duh) connected to your ESXi host and passed through via USB to the guest VM that will run apcupsd VMware Tools MUST be installed on each guest VM SSH enabled on the ESXi host (ask google) SSH enabled on unRAID - I recommend Overbyrn's SSH plugin: http://lime-technology.com/forum/index.php?topic=20848.0 Ensure your VM's are set up to start automatically, and that shutdown options are set to 'shutdown guest'. Try and ensure the VM running apcupsd is the first VM to start (last to shutdown) Download and install apcupsd on your Windows guest VM (could be linux as well, I'm concentrating on Windows for this tutorial) - http://sourceforge.net/projects/apcupsd/files/ Install the UPS driver as per the included instructions - note that if you are installing on Win8/Win2012, you'll need to enable unsigned driver installation. Ask google how to do this. Download Plink from the link above and put it somewhere - I put it in C:\Program Files\Putty (along with putty itself) to keep things neat. Grab the .zip file attached to this post and copy both files into C:\apcupsd\etc\apcupsd Edit the files in a decent editor (I recommend Notepad++ - http://notepad-plus-plus.org/) In apcupsd.conf, change the following as suited for your UPS: UPSNAME UPSCABLE (if it's attached via usb, then it'll just be usb as per the default) BATTERYLEVEL - if you want the system to shut down sooner, increase this.. if you want it to wait a bit longer, decrease it. I've got it set at 70, which gives everything enough time to gracefully shut down and still spares some battery power. MINUTES - similar to the above, if this trigger is hit (remaining runtime on battery), the shutdown will commence. I like 10 minutes as it gives all the VM's etc, and the host, plenty of time to shut down. I don't bother with any other settings as my requirements are fairly simple. In apccontrol.bat, go to line 162 and read the section labelled ***EDITED BY BetaQuasi*** - the remarks in the batch file run through the remaining steps. You can test if the shutdown will work by running the edited commands individually - first run the command to shutdown the unRAID VM and then try the 2nd command If your motherboard is capable, set it up to start automatically on return power, so the server will boot up by itself once a power outage is over. That's it - any questions, drop them on this thread and I'll do my best to assist. apcupsd-esxi.zip Quote Link to comment
dikkiedirk Posted April 18, 2013 Share Posted April 18, 2013 I hope this will also work with a UPS that is connected over LAN through a AP 9617 management card. Gonna try it anyhow, but never installed and configured apcupsd in Windows though. Quote Link to comment
znelbok Posted April 21, 2013 Share Posted April 21, 2013 This is great and exactly what I am looking for. I am going to use SNMP. I do have a serial cable but that means stuffing around with the VMsome more and its just easier to get working on Ethernet. Its appears to be working on my test machine OK so far. I have a second Windows guest on my system, This obviously needs to be shotdown before the ESXi system is shutdown. Do I just use the shutdown command between the unraid shutdown and the ESXi shutdown? If not can you please recoment where and how to shutdown the other windows guest. Thanks Mick Quote Link to comment
BetaQuasi Posted April 21, 2013 Author Share Posted April 21, 2013 "C:\path\to\plink.exe" [email protected] -pw esxipass "/sbin/shutdown.sh && /sbin/poweroff" That command will gracefully shut down each guest, and then the ESXi host itself, assuming VMware Tools is installed. Quote Link to comment
znelbok Posted April 21, 2013 Share Posted April 21, 2013 ahh, excellent. I was wondering how a guest would shutdown the host. From what I understand there are no VMTool for Unraid and that is why there is a shutdown command for unraid. Is this correct? If VMWare Tools is not installed then we need to shutdown the guests manually - correct? Quote Link to comment
BetaQuasi Posted April 21, 2013 Author Share Posted April 21, 2013 VMware tools exists for unRAID - however I'm not sure what method it uses to shut down. I wanted to be sure I was invoking the powerdown script, so I did it the way I'm doing it. If VMware tools is not installed in a particular guest, then yes, shutdown.sh on ESXi won't do anything. I've yet to see a guest OS that can't have VMware tools installed on it though. Quote Link to comment
dikkiedirk Posted April 21, 2013 Share Posted April 21, 2013 I run a simpe setup: just a unraid vm and windows 7 vm. Will the unraid vm be cleanly shutdown in any circumstance, even when in the middle of a mover running or when sabnzb is downloading? Will after the unraid vm is shutdown the ESXi box be shutdown? I couldn't get apcupsd working in my windows 7 vm. It wouldn't connect to my nmc-connected ups. turned out windows firewall was blocking it. Quote Link to comment
znelbok Posted April 22, 2013 Share Posted April 22, 2013 do you have a link to instructions on how to install the power-down script. I need step by step instructions for Linux Thanks Quote Link to comment
BetaQuasi Posted April 22, 2013 Author Share Posted April 22, 2013 You just drop it in \\tower\flash\extra and reboot.. that's it. Quote Link to comment
dbezerra Posted April 23, 2013 Share Posted April 23, 2013 So just for clarification - I do need to install the VMware Tools for the Unraid VM correct? Quote Link to comment
znelbok Posted April 23, 2013 Share Posted April 23, 2013 I get the impression that if you use the clean shutdown script then you don't The shutdown batch files calls a plink line that shuts down the UnRaid array and then the hypervisor is told to shutdown everything. If VMWare tools were installed you would not need the shutdown script and the line in the batch file Quote Link to comment
pjneder Posted April 24, 2013 Share Posted April 24, 2013 As mentioned in this thread (http://lime-technology.com/forum/index.php?topic=11449.msg237858#msg237858) I cannot get the VMTools plugin to completely agree with ESXi. I will go the script route. Still wish I could solve the other problem with VMTools though.... Quote Link to comment
sureguy Posted April 25, 2013 Share Posted April 25, 2013 As mentioned in this thread (http://lime-technology.com/forum/index.php?topic=11449.msg237858#msg237858) I cannot get the VMTools plugin to completely agree with ESXi. I will go the script route. Still wish I could solve the other problem with VMTools though.... Since unRAID has an apcupsd plugin with can communicate with whichever computer you have apcupsd installed on, you can have it start its powerdown before other machines start. I do this simply because I want to give it as much time as possible to power down if there is a failure. For me, after a power failure this is what I think happens (can't check as I'm not home) 10 seconds after a power failure - unRAID begins a power down (triggered by the apcupsd plugin) 60 seconds after a power failure, apcupsd (installed on a raspberry pi) triggers the shutdown of VMs and Host - takes about 5 minutes 7 minutes after a power failure apcupsd turns the UPS off Quote Link to comment
znelbok Posted April 25, 2013 Share Posted April 25, 2013 If the UPS turns off - what happens when the power returns - does it Auto-restart? Quote Link to comment
dbezerra Posted April 25, 2013 Share Posted April 25, 2013 Since unRAID has an apcupsd plugin with can communicate with whichever computer you have apcupsd installed on, you can have it start its powerdown before other machines start. I do this simply because I want to give it as much time as possible to power down if there is a failure. For me, after a power failure this is what I think happens (can't check as I'm not home) 10 seconds after a power failure - unRAID begins a power down (triggered by the apcupsd plugin) 60 seconds after a power failure, apcupsd (installed on a raspberry pi) triggers the shutdown of VMs and Host - takes about 5 minutes 7 minutes after a power failure apcupsd turns the UPS off I like that. I didn't know that I could use the apcupsd in client mode on the Windows VM listening to the broadcast of the Unraid one. Now, how do I send the shutdown message from the Windows VM to the Host ? Quote Link to comment
pjneder Posted April 26, 2013 Share Posted April 26, 2013 Read the first post in this thread. It has all of the instructions. Quote Link to comment
pjneder Posted April 26, 2013 Share Posted April 26, 2013 What do you guys do to start things back up when the power is restored? In particular I am thinking about the very common situation where I would be away on business and then the router, file-server, etc are all offline. I could set the BIOS to always boot when power is restored. However that does not solve the scenario where ESXi gets shutdown and power is restored before UPS is empty. Maybe don't shut down ESXi until 1% or whatever the lowest amount is that apcupsd can monitor? Or just keep ESXi up and let the host go down with the power. Have BIOS set to "restore last state" or even "power on with A/C"? What do you guys do? Quote Link to comment
overbyrn Posted June 27, 2013 Share Posted June 27, 2013 Beta, Thank you for your work on doing this. I have had an APC UPS since December last year but soon after I virtualised my UnRAID environment and have only just got around to setting this up. Followed your guide pretty much all the way, but I thought I'd post here as the only issue for me was that I don't allow root as an SSH user or password access of any kind. The only users I do have are setup with private / public keys. This caused me to have to change a few things slightly in order to still be able to use plink. I thought I'd document here in case it helps anyone else. Basically all I did different was on my Win7 VM which runs apcupsd, I first created and saved a session from Putty. In the session I made sure to point it at the private key I was using. Then my plink command for performing the shutdown looks like this; plink.exe "Tower" -l apcupsd "sudo /sbin/powerdown" In this case, "Tower" is my saved session in Putty and "apcupsd" is my SSH user (which I created in the standard way from inside the UnRAID webgui and subsequently selected in my OpenSSH plugin as a valid SSH user". You will notice that I also have sudo ahead of the powerdown command. This is the only way I could find to sucessfully call the powerdown script initially as a non-root user but eventually as sudo root in order to satisfy the permission needs of the powerdown script. This meant I needed to modify the default sudoers file on my UnRAID. I made the following two changes: # User privilege specification root ALL=(ALL) ALL apcupsd ALL=NOPASSWD: ALL # Defaults specification Defaults:apcupsd !requiretty I could be more restrictive by ensuring my user is only able to run the necessary commands, but for my purposes this is sufficient. I've added a line in my go file to copy over my custom sudoers to /etc upon reboot. Still testing, but seems to work for the moment! Kind Regards, overbyrn Quote Link to comment
BetaQuasi Posted June 28, 2013 Author Share Posted June 28, 2013 Cool mate, that makes things a bit more secure. Quote Link to comment
syntaxx Posted July 9, 2013 Share Posted July 9, 2013 I am able to make this work before but now I cant on windows 7 64bit. When i passthrough the usb the windows power management is going to run and the apc tray is showing that it cant connect any idea? Quote Link to comment
Dephcon Posted August 27, 2013 Share Posted August 27, 2013 An issue I've discovered is that the apcupsd service is starting before the usb driver is loaded so it fails and stops. I changed the service to Automatic (Delayed Start) and it fixed my issues. Delayed Start will start a service two minutes after all the normal Automatic services have loaded. FYI - I'm using a Windows 2008 R2 VM and a Back-UPS RS 1500 w/usb cable Quote Link to comment
joshpond Posted March 20, 2014 Share Posted March 20, 2014 Hi All, I'm having a little difficulty getting this going. apcupsd.conf (attached) is set to shutdown at 80% or 7 min remaining but for testing I've set the TIMEOUT to 60 seconds. After one minute it starts the shutdown as noted in the event log. It does mention a user logins prohibited which I'm not sure what that is but I'm assuming it stops people logging in as it is shutting down. I wait almost 4 minutes and nothing happens before I have to turn the UPS back on before it shuts off. (I do need to get a bigger one and I think the batteries are getting older, it does mention more time but with about 50% it suddenly drops but that shouldn't affect the scripts from running.) I've tested the individual lines from the batch file in a cmd prompt a they all work fine. This is the event log: 2014-03-20 19:46:24 +1000 Power failure. 2014-03-20 19:46:24 +1000 Power is back. UPS running on mains. 2014-03-20 19:46:24 +1000 Power failure. 2014-03-20 19:46:30 +1000 Running on UPS batteries. 2014-03-20 19:47:31 +1000 Reached run time limit on batteries. 2014-03-20 19:47:31 +1000 Initiating system shutdown! 2014-03-20 19:47:31 +1000 User logins prohibited 2014-03-20 19:51:15 +1000 Mains returned. No longer on UPS batteries. 2014-03-20 19:51:15 +1000 Power is back. UPS running on mains. 2014-03-20 19:51:15 +1000 Allowing logins These are my edits of the apccontrol batch file: rem ***EDITED BY BetaQuasi*** rem Change the below to suit your configuration. The rem fields should be set as follows: rem - Change C:\path\to\plink.exe to the path where you rem have stored plink.exe (two entries) rem - Change un.raid.ip.address to the IP address of rem your unRAID server rem - Change rootpass to the root password for your rem unraid installation rem - Change vmware.esxi.ip.address to the IP address rem of your ESXi server rem - change esxipass to the root password for your rem unraid installation rem --------------------------------------------------- rem We need to update the SSH fingerprint on the VM rem guest once, so that future plink calls can be done rem without any manual intervention. To do this, rem open a CMD prompt, and type the following two rem commands, replacing them with the appropriate IP rem addresses. rem "C:\path\to\plink.exe" un.raid.ip.address rem "C:\path\to\plink.exe" [email protected] rem Answer YES (y) to both prompts, then you can just rem CTRL-C to exit as the fingerprint is now stored rem on your guest VM "C:\plink.exe" 192.168.80.2 -l root "/sbin/powerdown" timeout /T 240 /NOBREAK "C:\plink.exe" [email protected] -pw ******* "/sbin/shutdown.sh && /sbin/poweroff" exit /b 99 GOTO :done Thanks Josh apcupsd.conf Quote Link to comment
smdion Posted June 15, 2015 Share Posted June 15, 2015 I know I'm bumping an old thread, but a request to move this to the "unRAID as a Guest" forum. 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.