NUT on OSX 10.6 [Sharing a UPS with ReadyNAS and Computers]

Please post any helpful and useful tips to maximize your fellow ReadyNAS users' experience.

NUT on OSX 10.6 [Sharing a UPS with ReadyNAS and Computers]

Postby Infinite » Sun Nov 15, 2009 12:08 am

First off: I can not take much credit for this post, the majority of this write up was done by Egg in this post "NUT on OS X (10.5.7)" which was priceless in my effort to get this matter solved. It looks Egg was pulling a lot of data from other members. I have made some edits to hopefully simplify the setup for you and have updated some information for 10.6. I also wanted to clarify what NUT is and why you might want it some day.

Background
NUT, is the Network UPS Tool: http://www.networkupstools.org/. When you plug a compatible UPS into ReadyNAS it's NUT that collects the data about the UPS status.

Native OSX Support
OSX 10.5 or later has some UPS feature built in when connecting a UPS to your Mac, but it doesn't have any built in support for shared UPS. You are up a creek if you have 2 Macs on a single UPS.

APC UPS Software and 3rd Party Mac Software
In addition, if you have an APC UPS you will notice that there is no software support post 10.4.x. APC is just letting OSX handled the effort. 3rd party tools like "APC Tracker" is rather expensive, does NOT seem to work on OSX 10.6, and might not be compatible with the ReadyNAS... I don't know. And as Egg pointed out in his post the Legacy APC solution (ACPUSPd) isn't compatible with the ReadyNAS. Other network cards for your APC UPS will cost you over $250 and from what I have read they aren't supported by the ReadyNAS either.

Solution
For the best Mac and ReadyNAS support you will want to setup NUT on your Macs. From my own research it's also seem like the only solution at present, but it's also the cheapest solution (free).

The Goal
Sharing a UPS with multiple Computer and ReadyNAS devices
In this setup we are letting a ReadyNAS be the NUT server and the rest of the ReadyNAS's and Mac will be client of that ReadyNAS. The UPS will have a USB connection with the Server. All of the devices will get their power from the UPS.

Lets start.

Setup:
2x ReadyNAS NV+ 4.1.6, ReadyNAS Duo 4.1.6, MacMini (Core2 Duo) OSX Server (10.6.2), MacMini (Core Duo) OSX Server (10.5.8) all on a one UPS (APC Smart-UPS 1500 SUA1500RM2U )

ReadyNAS Duo acts as the NUT server, the 2 NV+ and 2 MacMini's are NUT client.

Installing NUT
In order to get NUT on the MacMini installed you will need to follow the following Steps:

Download Fink (http://www.finkproject.org)
At present ( Nov 14, 2009 there is no Fink binary for OSX. So you will need to download the source and build and install it. It's very easy and it's clearly defined on the site. Go to this URL for the directions to install Fink. http://www.finkproject.org/download/srcdist.php You can use all the default values, the only value that wasn't the default for me was I decided to build everything as 64bit. If you have a 32bit cpu you won't get the prompt. One of my MacMini's is a Core Duo cpu's is 32bit install while the other MacMini is Core2 Duo and is using the 64bit version, both are working just fine.

The only thing that I should point out is after you run the shell installer ( /sw/bin/pathsetup.sh ) you need to quit Terminal and the reopen it for the changes to take.

Download and Install "Fink Commander" ( http://finkcommander.sourceforge.net/ )
At present 0.5.5 is the most recent version and I would recommend just using the Universal Binary which is Snow Leopard friendly.

Download and install Nut via "Fink Commander"
At present there does not seem to be binary's for Nut for 10.6. I decided to let Fink compile the source for both Machines just because Fink Commander does all the work for your. Compiling the source just take a little more time.

Setting up the upsmon.config by Egg
[Updated by Infinite]
In order to run only the NUT client (which is what I wanted) one needs to create the upsmon.config file in the /sw/etc/nut directory.

Open Terminal:
Note: if you prefer vi or mate (TextMate) as your text editor then feel free to use them instead nano
Code: Select all
cd /sw/etc/nut
sudo cp upsmon.conf.sample upsom.conf
sudo nano upsmon.conf


Change the values according to dbott67s advice for WinNut and quit vi by writing first the changed content to the new file 'upsmon.conf'.

Using the ReadyNAS to create a Network UPS for PCs

In order to test that the NUT client actually works, use Terminal again and start upsmon manually:
Code: Select all
sudo upsmon


The following is slightly altered advise based on http://boxster.ghz.cc/projects/nut/wiki/NutOnMacOSX.

Now you should be able to see two upsmon processes in the Activity Monitor or use the following line in Terminal. Remember to ignore the 3rd reference to "grep".
Code: Select all
ps aux | grep upsmon


In Terminal enter the following to test the connection from your Mac via your ReadyNAS to the UPS:
Code: Select all
sudo upsc UPS@[Your_ReadyNAS_IP]


In the Terminal window you should get a response back based on the type of your UPS device.

Automatic Startup
[Updated for OSX 10.6 and general cleaner scripts - Infinite]
For OS X it is necessary to navigate to /System/Library/StartupItems. I started by copying another directory tree (I used 'IPFailover') as a template for 'UPS' directory. To comply with the Apple standards all user Startup items should be located in /Library/StartupItems, we'll copy the item from the System folder to there user location. Then I changed to the 'UPS' directory and renamed the 'IPFailover' file to 'UPS' using the mv command. And last I edited the files in the 'UPS' directory.

These are the terminal commands:
Code: Select all
cd /System/Library/StartupItems
sudo cp -R IPFailover /Library/StartupItems/UPS
cd /Library/StartupItems/UPS
sudo mv IPFailover UPS
sudo nano UPS



Hint: If you don't have IPFailover then use one of the other folders from StartupItems

Edit /Library/StartupItems/UPS with a text editor:
Code: Select all
cd /Library/StartupItems/UPS
sudo nano UPS


Now replace the the contents of /Library/StartupItems/UPS with the code:
Code: Select all
#!/bin/sh

##
# UPS Monitor script
# Using Network UPS Tools executables
##

. /etc/rc.common

FINK_BIN="/sw/sbin"

StartService ()
{
   ConsoleMessage "Starting NUT (UPS Service)"
   if [ -n "`ps acxw | grep -i "upsmon" | awk {'print $1'}`" ]; then
        ConsoleMessage -f "NUT (UPS Service)"
        echo "Failed to start NUT (UPS Service): It is already running."
        exit 0
    fi
   ${FINK_BIN}/upsmon &
   if [ -n "`ps acxw | grep -i "upsmon" | awk {'print $1'}`" ]; then
        ConsoleMessage -s "NUT (UPS Service)"
        echo "NUT (UPS Service) successfully started."
        exit 0
    else
        ConsoleMessage -f "NUT (UPS Service)"
        echo "Failed to start NUT (UPS Service): Either the application has been deleted or it has no execution right."
        exit 0
    fi
}

StopService ()
{
   ConsoleMessage "Stopping NUT (UPS Service)"
    if [ -z "`ps acxw | grep -i "upsmon" | awk {'print $1'}`" ]; then
        ConsoleMessage -s "NUT (UPS Service)"
        echo "Failed to stop NUT (UPS Service): It is not running."
        exit 0
    fi
   ${FINK_BIN}/upsmon -c stop
   if [ -n "`ps acxw | grep -i "upsmon" | awk {'print $1'}`" ]; then
        ConsoleMessage -s "NUT (UPS Service)"
        echo "Failed to stop NUT (UPS Service) out of unknown reason."
        exit 0
    else
        ConsoleMessage -s "NUT (UPS Service)"
        echo "NUT (UPS Service) successfully stopped."
        exit 0
    fi
}

StopServiceForcefully()
{
   ConsoleMessage "Stopping NUT (UPS Service)"
    if [ -z "`ps acx | grep -i "upsmon" | awk {'print $1'}`" ]; then
        echo "Failed to stop NUT (UPS Service): It is not running."
    else
      kill -kill `ps acxw | grep -i "upsmon" | awk {'print $1'}`
        if [ -n "`ps acxw | grep -i "upsmon" | awk {'print $1'}`" ]; then
            echo "Failed to stop NUT (UPS Service) out of unknown reason."
        else
             echo "NUT (UPS Service) successfully stopped."
        fi
    fi
}

RestartService()
{
   ConsoleMessage "Trying to restart NUT (UPS Service)."
   StopService
   StartService
   exit 0
}

RunService "$1"


Now edit the StartupParamerters.plist via:
Code: Select all
cd /Library/StartupItems/StartupParamerters.plist
sudo nano UPS


Replace it's contents with the following code.

Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Description</key>
        <string>UPS Monitor client (NUT)</string>
        <key>Messages</key>
        <dict>
                <key>start</key>
                <string>Starting UPS Monitor client (NUT)</string>
                <key>stop</key>
                <string>Stopping UPS Monitor client (NUT)</string>
        </dict>
        <key>OrderPreference</key>
        <string>None</string>
        <key>Provides</key>
        <array>
                <string>UPS</string>
        </array>
        <key>Requires</key>
        <array>
                <string>Resolver</string>
        </array>
</dict>
</plist>


That's it! Now the automatic start-up should work.

Conclusion
At this point I have the two ReadyNAS NV+ and the two MacMini's communicating via NUT to the ReadyNAS Duo which is connected to the UPS via USB. I have restarted my MacMini's verified that the startup scripts are running. All is left is to simulate a power failure.

Here is the output I get from one of my MacMini's that's pulling this data from the ReadyNAS Duo:

bash$ sudo uspc UPS@192.168.1.108
sudo: uspc: command not found
miniserver:UPS admin$ sudo upsc UPS@192.168.1.108
battery.charge: 100
battery.chemistry: PbAc
battery.runtime: 20340
battery.voltage: 27.7
driver.name: hidups
driver.parameter.lowbatt_pct: 10
driver.version: 2.0.5
ups.mfr: APC
ups.model: Smart-UPS 1500 RM
ups.serial: [The Device S/N]
ups.status: OL


Enjoy!

Resources
Last edited by Infinite on Sun Nov 15, 2009 11:50 pm, edited 1 time in total.
ReadyNas Pro, NV+, Duo
User avatar
Infinite
ReadyNAS User
 
Posts: 78
Joined: Thu Jan 04, 2007 10:25 pm
Location: Seattle, WA
ReadyNAS: Pro


Re: NUT on OSX 10.6 [Sharing a UPS with ReadyNAS and Computers]

Postby Pian » Sat Jan 16, 2010 3:44 am

One thing to note from the FinkCommander FAQ ( http://finkcommander.sourceforge.net/help/faq.php Q2 ) is that under Snow Leopard you have to change the path of perl:

"You are on Snow Leopard (OS 10.6) and haven't set FinkCommander to use Perl 5.8.9. You can easily do so in FinkCommander:Preferences:Path:Path to Perl by entering the value /usr/bin/perl5.8.9"

Also, the mac being used as a client must have XCode installed.

Otherwise, thanks for the great guide.
Pian
ReadyNAS Newbie
 
Posts: 26
Joined: Fri Dec 18, 2009 7:51 am
ReadyNAS: NVX

Re: NUT on OSX 10.6 [Sharing a UPS with ReadyNAS and Compute

Postby mchards » Thu Nov 04, 2010 8:20 pm

I've got everything working except the Startup Item.

I've tried the approach on this thread and the one for 10.5.7 (http://www.readynas.com/forum/viewtopic.php?f=28&t=29452).

The plist files in these don't work for me, I get Console messages about Malformatted parameters file: /Library/StartupItems/UPS/StartupParameters.plist, so I used the one from http://boxster.ghz.cc/projects/nut/wiki/NutOnMacOSX

At that point, I get syntax errors in the UPS file. Using the 10.5.7 one the specific message is:

Code: Select all
com.apple.SystemStarter[33]: /Library/StartupItems/UPS/UPS: line 15: syntax error near unexpected token ` '
com.apple.SystemStarter[33]: /Library/StartupItems/UPS/UPS: line 15: `                start  )'


Anybody have any ideas as to what may be wrong?
mchards
ReadyNAS Newbie
 
Posts: 17
Joined: Tue Apr 28, 2009 9:26 pm
Location: Centennial, CO
ReadyNAS: Duo

Re: NUT on OSX 10.6 [Sharing a UPS with ReadyNAS and Compute

Postby Pian » Fri Nov 05, 2010 1:47 am

Here's mine (Snow Leopard):



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Description</key>
<string>UPS Monitor client (NUT)</string>
<key>Messages</key>
<dict>
<key>start</key>
<string>Starting UPS Monitor client (NUT)</string>
<key>stop</key>
<string>Stopping UPS Monitor client (NUT)</string>
</dict>
<key>OrderPreference</key>
<string>None</string>
<key>Provides</key>
<array>
<string>UPS</string>
</array>
<key>Requires</key>
<array>
<string>Resolver</string>
</array>
</dict>
</plist>
Pian
ReadyNAS Newbie
 
Posts: 26
Joined: Fri Dec 18, 2009 7:51 am
ReadyNAS: NVX

Re: NUT on OSX 10.6 [Sharing a UPS with ReadyNAS and Compute

Postby Pian » Fri Nov 05, 2010 8:27 am

And (perhaps slightly more usefully!) here is my UPS:

#!/bin/sh


##
# UPS Monitor script
# Using Network UPS Tools executables
##

. /etc/rc.common

FINK_BIN="/sw/sbin"

StartService ()
{
ConsoleMessage "Starting NUT (UPS Service)"
if [ -n "`ps acxw | grep -i "upsmon" | awk {'print $1'}`" ]; then
ConsoleMessage -f "NUT (UPS Service)"
echo "Failed to start NUT (UPS Service): It is already running."
exit 0
fi
${FINK_BIN}/upsmon &
if [ -n "`ps acxw | grep -i "upsmon" | awk {'print $1'}`" ]; then
ConsoleMessage -s "NUT (UPS Service)"
echo "NUT (UPS Service) successfully started."
exit 0
else
ConsoleMessage -f "NUT (UPS Service)"
echo "Failed to start NUT (UPS Service): Either the application has been deleted or it has no execution right."
exit 0
fi
}

StopService ()
{
ConsoleMessage "Stopping NUT (UPS Service)"
if [ -z "`ps acxw | grep -i "upsmon" | awk {'print $1'}`" ]; then
ConsoleMessage -s "NUT (UPS Service)"
echo "Failed to stop NUT (UPS Service): It is not running."
exit 0
fi
${FINK_BIN}/upsmon -c stop
if [ -n "`ps acxw | grep -i "upsmon" | awk {'print $1'}`" ]; then
ConsoleMessage -s "NUT (UPS Service)"
echo "Failed to stop NUT (UPS Service) out of unknown reason."
exit 0
else
ConsoleMessage -s "NUT (UPS Service)"
echo "NUT (UPS Service) successfully stopped."
exit 0
fi
}

StopServiceForcefully()
{
ConsoleMessage "Stopping NUT (UPS Service)"
if [ -z "`ps acx | grep -i "upsmon" | awk {'print $1'}`" ]; then
echo "Failed to stop NUT (UPS Service): It is not running."
else
kill -kill `ps acxw | grep -i "upsmon" | awk {'print $1'}`
if [ -n "`ps acxw | grep -i "upsmon" | awk {'print $1'}`" ]; then
echo "Failed to stop NUT (UPS Service) out of unknown reason."
else
echo "NUT (UPS Service) successfully stopped."
fi
fi
}

RestartService()
{
ConsoleMessage "Trying to restart NUT (UPS Service)."
StopService
StartService
exit 0
}

RunService "$1"
Pian
ReadyNAS Newbie
 
Posts: 26
Joined: Fri Dec 18, 2009 7:51 am
ReadyNAS: NVX

Re: NUT on OSX 10.6 [Sharing a UPS with ReadyNAS and Compute

Postby mchards » Fri Nov 05, 2010 6:28 pm

Working now using your UPS and the plist from http://boxster.ghz.cc/projects/nut/wiki/NutOnMacOSX

I guess I didn't try that combination before. I'm running 10.6.4 for what it's worth. Happy Console messages below, thanks for the help.

com.apple.SystemStarter[33]: Starting NUT (UPS Service)
com.apple.SystemStarter[33]: -s NUT (UPS Service)
com.apple.SystemStarter[33]: NUT (UPS Service) successfully started.
com.apple.SystemStarter[33]: UPS: UPS@192.168.0.41 (slave) (power value 1)
com.apple.SystemStarter[33]: Using power down flag file /etc/killpower
mchards
ReadyNAS Newbie
 
Posts: 17
Joined: Tue Apr 28, 2009 9:26 pm
Location: Centennial, CO
ReadyNAS: Duo

Re: NUT on OSX 10.6 [Sharing a UPS with ReadyNAS and Compute

Postby gothick » Fri Feb 24, 2012 2:28 am

Thanks for this, it's working well for me. If it's helpful anyone who's already using macports rather than fink, I found that the macports version of nut works just fine out of the box on Lion, so all I needed to do to get the basic install working was "sudo port install nut". After that, just follow the directions, after finding the nut install in /opt/local.
gothick
ReadyNAS Newbie
 
Posts: 1
Joined: Fri Feb 24, 2012 2:24 am
ReadyNAS: Duo

Re: NUT on OSX 10.6 [Sharing a UPS with ReadyNAS and Compute

Postby ig-88 » Mon Oct 01, 2012 8:06 pm

I wanted to chime in and say that I seem to be all set with my NV as the NUT server, and a 10.8.2 NUT client installed through MacPorts. I haven't actually cut the power and done a real test yet, but upsmon is running fine and I'm able to confirm connectivity with upsc. Here are some updated instructions if you're using MacPorts to install:

[*]For any MacPorts install, make sure you're using a supported version of Xcode and that you have additionally installed the command-line tools
[*]Upsmon.conf should go in /opt/local/etc. Start from the sample file in there or use DBott's upsmon.conf, which basically takes the defaults except for the most important line:

MONITOR UPS@ReadyNAS_IP 1 monuser pass slave

[*]Do a sudo mkdir /Library/StartupItems/UPS. Create and save the XML file in this post as StartupParameters.plist, and save it in that UPS directory
[*]Create the script in this port in the UPS directory, and you can save that file as UPS. The FINK_BIN path in the script should be "/opt/local/sbin" because MacPorts doesn't use Fink's install directory. Don't forget to make this script executable with a chmod +x UPS. The script should kick off upsmon on boot. You can test connectivity to the NUT server on the ReadyNAS with sudo /opt/local/bin/./upsc UPS@ReadyNAS_IP, which should display similar results to the beginning of this post. HTH.....
Last edited by ig-88 on Sat Feb 23, 2013 11:55 pm, edited 1 time in total.
User avatar
ig-88
ReadyNAS Newbie
 
Posts: 18
Joined: Thu Aug 24, 2006 5:38 am
ReadyNAS: NV

Re: NUT on OSX 10.6 [Sharing a UPS with ReadyNAS and Compute

Postby kitus » Sun Feb 03, 2013 12:57 pm

Hello,

I think I've configured all as the OP indicated (I'm on Mountain Lion and the StartupItems was empty in both /Library/StartupItems/ and /System/Library/StartupItems/ , is this normal???).

I too installed NUT through MacPorts but before I also attempted to do it using Fink. Man, Fink takes ages to install and in the end there was no way I could install NUT. My advice is to go with MacPorts should any newbe attepted to do this. It's clear and simple, pretty straightforward.

I followed all the directions given by ig-88 but I have a problem with the second [*] as /opt/local/bin does not contain an "etc" folder. My upsmon.conf.sample (and now upsmon.conf file too) were located in /opt/local/etc after installing NUT using MacPorts. ig-88, could you please check your setup and get back to me?

I assume I have everything more or less ok (lets see what ig-88 says regarding my previous comment), so on with my questions:

1. I've unplugged my UPS (wanted to test the setup) and I can see messages poping up in Terminal on my Mac. Is there any GUI or anyway to make my Mac show an alert when the UPS kicks in? What happens if the user is not on Terminal?
2. My Mac did not quite shutdown when I simulated a shutdown on the NAS by issuing "upsmon -c fsd", and neither when I really unplugged the UPS from the wall plug.
3. I've also noticed that when my Mac is asleep, it won't hear the messages sent from the NAS. What about the rest of the people here? does it work ok for you?

I would appreciate your responses and help. Congratulations on the clear explanation Infinite and the rest.

Thanks in advance,

Thanks
kitus
ReadyNAS Newbie
 
Posts: 2
Joined: Sun Feb 03, 2013 12:23 pm

Re: NUT on OSX 10.6 [Sharing a UPS with ReadyNAS and Compute

Postby ig-88 » Sun Feb 24, 2013 12:23 am

I corrected the path above. I believe that /opt/local/* is for all the stuff you install with MacPorts. The bin directory would then be for all your binaries, and the etc directory would be for your config files. I wouldn't be surprised if the Mac doesn't see any UPS notifications while it's asleep, but you would think it would wake up once the power load shifts to the battery. It might be necessary to do some fine-tuning of upsmon.conf to make sure the NUT client can/will actually shut the system down when it needs to. I'd be interested in seeing what works for you on that score - I haven't had the opportunity to play with this much. Also, try modifying the upsmon.conf to experiment with notifications - specifically look at NOTIFYFLAG and NOTIFYCMD. By default it does write to all connected users in Terminal but it looks like it writes to syslog too. You may be able to find these messages in Console. Perhaps you can tie these into Growl or some other similar program? I don't typically use Growl but I know some people get a lot of use out of it. You could also get creative and write a script that uses NOTIFYCMD to send out an e-mail, which is probably what I should do one of these days if I have the time...
User avatar
ig-88
ReadyNAS Newbie
 
Posts: 18
Joined: Thu Aug 24, 2006 5:38 am
ReadyNAS: NV

Re: NUT on OSX 10.6 [Sharing a UPS with ReadyNAS and Compute

Postby kitus » Sun Mar 03, 2013 2:36 pm

ig-88 wrote:I corrected the path above. I believe that /opt/local/* is for all the stuff you install with MacPorts. The bin directory would then be for all your binaries, and the etc directory would be for your config files. I wouldn't be surprised if the Mac doesn't see any UPS notifications while it's asleep, but you would think it would wake up once the power load shifts to the battery.

I think it actually notices that event. You seem to be pretty busy. I don't really need to figure out this whole thing just yet. I would appreciate it if you simply log back when you have more time. I think I would be cool to work together on this.
It might be necessary to do some fine-tuning of upsmon.conf to make sure the NUT client can/will actually shut the system down when it needs to. I'd be interested in seeing what works for you on that score - I haven't had the opportunity to play with this much.

In that file there certainly is a "shutdown" statement but I can't seem to be able to replicate a shutdown event, or I do but the Mac simply ignores the whole thing. That's why I'm suggesting we work together on this if you ever get around to it.
Also, try modifying the upsmon.conf to experiment with notifications - specifically look at NOTIFYFLAG and NOTIFYCMD. By default it does write to all connected users in Terminal but it looks like it writes to syslog too

There must be a GUI somewhere. You are right indeed, but it sounds like to much fiddling, right? I'm not a command line guru and I don't feel comfortable... need some guidance I guess.
You may be able to find these messages in Console. Perhaps you can tie these into Growl or some other similar program? I don't typically use Growl but I know some people get a lot of use out of it. You could also get creative and write a script that uses NOTIFYCMD to send out an e-mail, which is probably what I should do one of these days if I have the time...

Again, I just ask you to revisit this thread if you ever decide to tackle this. I don't feel I can do this on my own.

Thanks for responding to my request :)
kitus
ReadyNAS Newbie
 
Posts: 2
Joined: Sun Feb 03, 2013 12:23 pm


Return to User Submitted Tips



Who is online

Users browsing this forum: No registered users and 1 guest