apcupsd - ESXi/unRAID configuration


Recommended Posts

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:

 

 

  • 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

Link to comment
  • 3 weeks later...

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

Link to comment

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?

Link to comment

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.

Link to comment

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.

Link to comment

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

Link to comment

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

 

 

 

Link to comment

 

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 ?

Link to comment

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?

Link to comment
  • 2 months later...

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

 

Link to comment
  • 2 weeks later...
  • 1 month later...

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

Link to comment
  • 6 months later...

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

Link to comment
  • 1 year later...

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.