View unanswered posts    View active topics

All times are UTC - 6 hours





Post new topic Reply to topic  [ 19 posts ] 
Go to page 1, 2  Next

Print view Previous topic   Next topic  
Author Message
Search for:
PostPosted: Sat Sep 01, 2007 12:32 pm 
Offline
Joined: Thu Mar 25, 2004 11:00 am
Posts: 9551
Location: Arlington, MA
1) Save the following code in a file (trim it so that the first line is the one that says "#!/bin/bash") called "setup_apcupsd.sh".
2) Make sure there are no trailing blanks after the \ characters at the end of lines 25 through 30.
3) Make sure you've connected the USB cable from your UPS to your computer.
4) Make the script executable by running the command: "chmod +x setup_apcupsd.sh"
5) Run your new script.

Code:
root@black2:~/setup# cat setup_apcupsd.sh
#!/bin/bash

if [ $(id -u) -ne 0 ] ; then
    echo "You must run this script as root!"
    exit 1
fi
echo
echo "Checking for an APC UPS (only recognizes USB connected units)..."
echo
if ! dmesg | egrep -i 'USB .*Device \[(APC|American Power Conversion)' >/dev/null 2>&1 ; then
    echo "No USB connected APC UPS detected."
    exit 1
fi
if [ "$1" != "no_apt_get_update" ] ; then
    echo
    echo "Updating apt-get info..."
    echo
    apt-get update
fi
echo
echo "Making sure the apcupsd software is up to date..."
echo
apt-get install apcupsd libsnmp-base libsnmp9
echo "Fixing up the config files..."
sed -si.orig -e '/^\(UPSCABLE\) .*/s//\1 usb/' \
             -e '/^\(UPSTYPE\) .*/s//\1 usb/' \
             -e '/^\(DEVICE\) .*/s//\1 /' \
             -e '/^\(STATTIME\) .*/s//\1 300/' \
             /etc/apcupsd/apcupsd.conf
sed -si.orig -e '/^\(ISCONFIGURED=\).*/s//\1yes/' \
             /etc/default/apcupsd
echo
echo "Restarting the apcupsd daemon process..."
echo
/etc/init.d/apcupsd restart
echo
echo "Making sure the apcupsd daemon is started at boot..."
echo
update-rc.d apcupsd defaults
echo
echo "APC UPS setup complete!"
echo


Edit #1 - Corrected the problem Mike spotted.
Edit #2 - Incorporated Jack's fix from below.
Edit #3 - Fixed an editing fumble.


Last edited by tjc on Sat Sep 15, 2007 3:09 pm, edited 3 times in total.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 02, 2007 1:09 pm 
Offline
Joined: Fri Oct 20, 2006 12:04 pm
Posts: 905
Location: LA, CA
This came just in time for me. Just purchased an UPS (on sale of course) and was going to monkey with getting the usb setup working. Saw this, worked like a charm! Thanks a bunch! But now I'm afraid to test it...


Top
 Profile  
 
PostPosted: Sun Sep 02, 2007 3:04 pm 
Offline
Joined: Sun Sep 25, 2005 3:50 pm
Posts: 1013
Location: Los Angeles
tjc wrote:
Code:
echo
update-rc.d webmin defaults
echo
echo "APC UPS setup complete!"
echo


Shouldn't this be

Quote:
echo
update-rc.d apcupsd defaults
echo
echo "APC UPS setup complete!"
echo


:?:

_________________
Mike
My Hardware Profile


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 02, 2007 3:55 pm 
Offline
Joined: Thu Mar 25, 2004 11:00 am
Posts: 9551
Location: Arlington, MA
First test, check the information in the /var/log/apcupsd.status file to make sure you're getting status. After that you can wait for the automatic self test to fire (this may take several days). You should see a little (5%) dip in the battery charge level which comes back up to 100% within a few minutes and a note about self test in the /var/log/apcupsd.events log. Here's the report from the last one my UPS did.
Code:
Sat Sep 01 13:20:16 EDT 2007  UPS Self Test switch to battery.
Sat Sep 01 13:20:25 EDT 2007  UPS Self Test completed: Not supported


Top
 Profile  
 
PostPosted: Sun Sep 02, 2007 4:00 pm 
Offline
Joined: Thu Mar 25, 2004 11:00 am
Posts: 9551
Location: Arlington, MA
mihanson wrote:
Shouldn't this be

Quote:
echo
update-rc.d apcupsd defaults
echo
echo "APC UPS setup complete!"
echo


:?:

Yes it should. :oops: Fixed now. Sigh... :oops:


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 02, 2007 5:51 pm 
Offline
Joined: Fri Oct 20, 2006 12:04 pm
Posts: 905
Location: LA, CA
Thanks again tjc, I ran the "update-rc.d apcupsd defaults" as root, so I'm thinking I should be good for the next reboot. I'm getting info in my log file. I'm assuming that the software will safely shut down the box when power goes and stay down. Just wondering how long it waits? I see MINTIMEL as 3 minutes and MBATTCHG as 5%, are these the times it waits to start shutdown?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 02, 2007 6:24 pm 
Offline
Joined: Thu Mar 25, 2004 11:00 am
Posts: 9551
Location: Arlington, MA
Yeah. If it gets below either 5% battery charge or 3 minutes of runtime left it should shut down.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 03, 2007 6:28 am 
Offline
Joined: Tue Apr 13, 2004 6:51 pm
Posts: 890
Location: Groton, MA
you can test by putting a fake shutdown script inplace....maybe w/ some log output.

_________________
R5F1 - Dell P4 2.4Ghz 500MB - PVR250 x 2 - GeForce FX 5200 - Onboard sound/NIC 80GB ATA/250GB ATA/400GB SATA


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 03, 2007 7:12 am 
Offline
Joined: Thu Mar 25, 2004 11:00 am
Posts: 9551
Location: Arlington, MA
The apcupsd site has an online manual with a whole chapter on ways of testing it. http://www.apcupsd.com/manual/Testing_Apcupsd.html

I never opted for anything that elaborate. I installed it, made sure the system was talking to the UPS (the status log is enough proof on that count), made sure nothing else was running to generate disk activity, pulled the plug, and let it shutdown the box.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 03, 2007 5:52 pm 
Offline
Joined: Tue Oct 25, 2005 7:04 am
Posts: 58
Location: Victoria, BC
One very cool thing about apcupsd is that it additional linux systems can point to the controlling apcupsd system and run like "slaves".

I have my linux firewall controlling the APC UPS - then my MythTV box (which is also connected to the APC) runs its own instance of apcupsd and points to the firewall IP address rather than directly to the APC.

When the firewall starts shutting down - the MythTV box is also told to shutdown...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 14, 2007 10:27 pm 
Offline
Joined: Fri Oct 20, 2006 12:04 pm
Posts: 905
Location: LA, CA
Did this script make it into F27? I can't locate, will recreate according to above.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 14, 2007 10:46 pm 
Offline
Joined: Thu Mar 25, 2004 11:00 am
Posts: 9551
Location: Arlington, MA
It's there on my machine, and I even used it before the restore: /usr/local/bin/setup_apcupsd.sh


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 14, 2007 10:52 pm 
Offline
Joined: Fri Oct 20, 2006 12:04 pm
Posts: 905
Location: LA, CA
tjc wrote:
It's there on my machine, and I even used it before the restore: /usr/local/bin/setup_apcupsd.sh


OK found it, right where it should have been. but it didn't show up with a locate. I must need some sleep.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 15, 2007 2:53 pm 
Offline
Joined: Sat Sep 02, 2006 9:17 am
Posts: 359
tjc,
APC apparently made some changes that fool the detection, so the script fails for me. On My system:
Code:
root@joesmyth:/usr/local/bin#  dmesg | egrep -i 'UPS'
hiddev96: USB HID v1.10 Device [American Power Conversion Back-UPS XS  900 FW:830.E6 .D USB FW:E6 ] on usb-0000:00:02.0-2

It looks like "APC" is changing to "American Power Conversion"
I changed the script to:
Code:
if ! dmesg | egrep -i 'USB .*Device \[(APC|American Power Conversion)' >/dev/null 2>&1 ; then

Notice, besides the obvious, the change from grep to egrep. it works for me now.

Now, can someone verify that this does not break "APC" UPS's? I hope this can be of help.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 15, 2007 3:04 pm 
Offline
Joined: Thu Mar 25, 2004 11:00 am
Posts: 9551
Location: Arlington, MA
Looks like a good fix on inspection and works for me when tested.

Thanks!

BTW - Does the RRD script to monitor a UPS work with the status output of your unit?


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ] 
Go to page 1, 2  Next



All times are UTC - 6 hours




Who is online

Users browsing this forum: No registered users and 15 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group

Theme Created By ceyhansuyu