APCUPSD 3.14.10 Plugin for unRAID 5b11+


Recommended Posts

Yup I get my status emails from simplefeatures without issues. I wonder if it has to do with them passes thru from esxi?

 

I have seen issues with ESXi and usb pass through. My unraid test box is running on esxi which I used to develop the plugins and had all kinds of issues with APCUPSD and usb.  You could overcome it by buying a cheap usb card and using vmdirectpath to assign it to the unraid server. That should solve any issues.  

 

Something like the following: http://www.newegg.ca/Product/Product.aspx?Item=N82E16815201008

Link to comment
  • Replies 443
  • Created
  • Last Reply

Top Posters In This Topic

Yup using the latest versions.

 

I have no PCI slots on my mobo (see sig) but I do have some onboard USB ports that I could pass through.  I just got a (4) port USB PCI bracket and plugged it into the mobo.  I'm going to see if I pass those through.  It's just tough because if I pass through the channel with my ESXi key, I will never be able to boot it again. 

 

I'd like to pass-thru USB anyway to have direct access to a blu-ray drive for ripping.

Link to comment

i have has no issues passing my apc through ESXi with the same motherboard.

 

I have the APCUPSD monitor installed on my main windows rig so i can see if it drops ups connection.

 

i'll guess it is some other issue.

do emails to root get forwarded by the simple features script?

 

i know the smtp unmenu script recently stopped working with hotmail. I had to switch to gmail to keep getting alerts.

Link to comment

you can test out mail buy entering the following command in telnet/ssh

 

echo test | mail -s 'test' root

 

Okay power finally came back on.  The test message worked.  Same setup; ESXi 5.0 etc.  I was home when the power went out on Saturday and never got the email from unRAID telling me it was running on battery power.  I ended up shutting down unRAID and ESXi myself, maybe I shut it down before it could send me an email?  The unMENU package would tell me as soon as it went down (which in my area, with shady power, is really helpful).  Does this only send an email when it's about to shutdown?

Link to comment

So you're saying you get the status updates in the gui when the power goes off, however no email at all? And you can send email from SSMTP through command? Sounds very weird.

 

Is there a way to force APCUPSD to refresh the status, in an attempt to get the daemon to shoot off an email? Also, have you tried serial cable instead?

Link to comment

So you're saying you get the status updates in the gui when the power goes off, however no email at all? And you can send email from SSMTP through command? Sounds very weird.

 

Is there a way to force APCUPSD to refresh the status, in an attempt to get the daemon to shoot off an email? Also, have you tried serial cable instead?

 

I don't think it has a "power fail test". I pulled my power cord on the UPS to test my setup.

Link to comment

I did some testing with this plugin and ESXi for a Back-UPS CS 350.

 

It mailed with no problems without any other configuration changes than installing the plugin.  :) I tested simply by pulling the RJ-connector from the UPS and reconnecting it. Oddly enough, I only got a "Connection reestablished" mail. I would find a mail "Connection lost" quite useful as well...

 

Anyway, the ESXi 5 has the USB port mapped to the unRAID VM.

 

When running on ESXi, the plugin reports only a few parameters, and a wrong status on the UPS.

When running directly on the server with no ESXi, the plugin reports all paremters correctly.

 

See attached files, which is actually a copy of two of the mails sent, but the same is displayed in the status window. Between them, I did nothing else but run on either ESXi or directly booting unRAID 5.0.12b. I also attached the syslogs.

 

It would be nice if we can find a way to get this to work properly in ESXi :-)

 

Hope this can help. Please let me know If I can try something...

 

PS: The rest of the hardware is the stuff in my Pleiades build in the profile below if it's relevant.

 

[edit: Forgot the attachments...]

UPS-reports.zip

Syslogs.zip

Link to comment

So you're saying you get the status updates in the gui when the power goes off, however no email at all? And you can send email from SSMTP through command? Sounds very weird.

 

Is there a way to force APCUPSD to refresh the status, in an attempt to get the daemon to shoot off an email? Also, have you tried serial cable instead?

Not really that weird.

 

In a power failure my cable modem is not powered and I'd have no way to send an outbound e-mail even if the server tried.  Even if the cable-modem was powered, the amplifiers on the poles are not, so again, typically cable and internet are out if power is out.  It might be different if you have a DSL line, but even then it requires your router be on your UPS in addition to your server.

 

 

Link to comment

Power came back on, so I'm about to test this again manually.

 

Was reading up on JohnM's procedure to shutdown ESXi on powerloss but I'm not running any Windows VM's (yet at least).  Is there a way to do this natively in Slackware/unRAID that you know of?  I can def write a script to SSH into the ESXi box and shutdown just need the event to launch it.

Link to comment

I run ESXi and have created a small VM running ubuntu, I installed the vsphere cli and apcupsd onto it.  When it detects a power outage, it shutdowns all the vm's on the server except for itself.  Then for the last step it tells the esxi host to shutdown, which shuts down ubuntu and tells the ups to power off in 2 minutes. by time the 2 minutes has passed, esxi has completed the shutdown cleanly.

 

Here is the vm shutdown script

myHost=`vmware-cmd  --server 10.10.1.251 --username root --password yourpassword -l | grep -i $1`

if [ ! $myHost = "" ]; then

  while vmware-cmd --server 10.10.1.251 --username root --password yourpassword $myHost getstate | grep -q on
  do
    echo "$myHost is on."
    vmware-cmd --server 10.10.1.251 --username root --password yourpassword  $myHost stop soft
    sleep 5s
  done
fi

 

 

here is the script that apcupsd calls to start the shutdown my vm's. It uses the above shutdown script.

echo Shutting down MAIL.
/home/adam/shutdownvm mail
echo SHutting down FILES.
/home/adam/shutdownvm files
echo Shutting down DC01.
/home/adam/shutdownvm dc01
echo Shutdown VM Host
vicfg-hostops --operation shutdown --force --server 10.10.1.251 --username root --password yourpassword

 

just change to your ip and add a line for each vm you have running to shut it down

Link to comment

I wonder if I have the VMware tools pkg installed on my unRAID if it will gracefully shutdown if ESXi shuts it down

it is supposed to. in my testing it did just fine. when it came back up, it reported clean shutdown on last shutdown..

 

I also set my unRAID to shut itself down if it never gets the shutdown command.

I should look into cleaning up my script. i had issues when i built mine with the windows client as the master. since it worked (I have has 2 power failures since then), I never looked backed.

 

I also have my scrip do a full server shutdown. shutting the  guests down in order based on the order in the autostart. I did that since I did not know what VM's I would have at the time. an i might have test VM's open that only exist for a day or two.  It has worked for me in that mode.

 

in theory, APCUPSD calls a script when it gets a power fail status, you should be able to get unRAID to call that script with a little tweaking.

Link to comment

I know that you can call scripts on events and I'm sure there's a way to call it directly from unRAID.  I know you can do it over SSH but I'm wondering how to auto login (maybe key pairs?).  I also see that VMware has an ESXiCLI for Linux but it currently only works on Red Hat or Ubuntu.  Wonder how we could get that to work on Slackware.  I tried to install it over the weekend but it was a no go.  Even with PERL installed, the install didn't work.

Link to comment

I think I have it figured out, I just can't get the ssh key login working on ESXi.  It seems it used to have dropbear and 5.0 no longer does.

 

Here are some interesting links:

 

http://communities.vmware.com/message/1299634#1299634

 

http://communities.vmware.com/servlet/JiveServlet/previewBody/9308-102-10-6757/ESXi%20and%20APC%20UPS%20VIOPS.pdf;jsessionid=1CFB153A8DFF97DC9E6FF1BD7392517D

 

http://www.yellow-bricks.com/2008/08/10/howto-esxi-and-ssh/

 

I've tried creating the keys on my Mac and transferring them to the ESXi server then cat'ing them out to authorized_hosts.  Still no go. 

Link to comment

1.) Enable SSH login on ESXi 5.0 if you haven't already

 

2.) Install my (attached) modified opensshd plugin (thx to brun0, I merely updated his plugin - http://lime-technology.com/forum/index.php?topic=14998.0)

 

installplg /boot/plugins/opensshd-5.9-i486-savestheday.plg

 

The opensshd that unMENU installs is an older version that has a bug in it preventing key logins. This is the most up to date version I could find on pkgs.org

 

3.) Make a directory to store the keys.  I had to make one on my cache drive, anything on the USB stick had its permissions reset to 777.

 

mkdir /mnt/cache/.keys

 

4.) Generate your keys

 

ssh-keygen -t rsa

Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):   (I guess you could put /mnt/cache/.keys here but I let it generate in the default location)

Choose empty passphrases (just press enter)

Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.

 

5.) Now copy your keys to the correct directory and set permissions

cp /root/.ssh/id_rsa /mnt/cache/.keys
cp /root/.ssh/id_rsa.pub /mnt/cache/.keys
chmod 600 /mnt/cache/.keys/id_rsa
chmod 600 /mnt/cache/.keys/id_rsa.pub

 

6.) SCP the pub key over

scp /root/.ssh/id_rsa.pub root@<ESXI_IP>:/etc/ssh/keys-root/authorized_keys

 

(may want to make sure the permissions carried over)

 

7.) From your unRAID server, test to see you can login using the key

 

ssh -i /mnt/cache/.keys/id_rsa root@<ESXI_IP>

 

type 'yes' to add the location to known hosts

 

exit your ssh session after this

 

 

8.) Now you need to copy your known_hosts to your usb stick and symlink /root/.ssh to that location

mkdir /boot/config/ssh
cp /root/.ssh/known_hosts /boot/config/ssh
rmdir /root/.ssh
ln -s /boot/config/ssh /root/.ssh

 

(btw, you'll need to add the symlink to your GO file)

 

9.) Save the following as ups_shutdown.sh

 

#!/bin/bash
VMID=$(/usr/bin/vim-cmd vmsvc/getallvms | grep -v Vmid | awk '{print $1}')

for i in $VMID
do
  STATE=$(/usr/bin/vim-cmd vmsvc/power.getstate $i | tail -1 | awk '{print $2}')

  if [ $STATE == on ]
  then
  
    /usr/bin/vim-cmd vmsvc/power.shutdown $i

  fi

done

sleep 10

/sbin/shutdown.sh
/sbin/poweroff

 

 

 

Save that on your ESXi server on /

 

9.) Now for the tricky part.  I am sure there's a way to modify the apcupsd package to edit this file, but I haven't figured it out yet.  I'm sure someone more knowledgeable than me knows how to do this.  Here's what needs to be done....

 

 

We need to edit the apccontrol file to change what is done when the UPS

issues a shutdown command.  I use nano on unRAID (separate package) or Transmit on the Mac

 

nano /etc/apcupsd/apccontrol

edit the doshutdown section like so, change the IP address to the ESXi host:

   

doshutdown)
        echo "UPS ${2} initiated Shutdown Sequence" | ${WALL}
        ssh -i /mnt/cache/.keys/id_rsa root@<ESXI_IP> "/ups_shutdown.sh"
        ${SHUTDOWN} -h now "apcupsd UPS ${2} initiated shutdown"
    ;;

 

 

10.) You can test this line out manually by running:

 

ssh -i /mnt/cache/.keys/id_rsa root@<ESXI_IP> "/ups_shutdown.sh"

 

See if your ESXi server shuts down.  This should also take down your unRAID gracefully if you've got the VMware tools installed but I haven't tested that yet.

opensshd-5.9-i486-savestheday.plg.txt

Link to comment

I just read JohnM's method of shutting down ESXi and it's nearly identical to mine cept for the fact that it's done with Putty and not ssh.  Didn't mean to do that John...

 

Can you possibly add a doshutdown action add to the plug-in page?  it seems like you're already adding the mail action:

 

sed -i -e "/^WALL=wall/c\WALL=\"mail -s 'unRAID_Server_UPS_Alert' root\"/" /etc/apcupsd/apccontrol

 

I'll research the "sed" command and see if I can add it myself too but this would be super sweet for us virtualized guys.

 

Btw, power went out again on Sunday and no email :(  I tried running the command

 

mail -s 'unRAID_Server_UPS_Alert' root

 

and it doesn't work for me.  The previous command you had me run DOES work tho.  I'll try it without ESXi in the mix but with the above command not working, I'm not sure that's the problem.

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.