Skip to content

Instantly share code, notes, and snippets.

@milesfrain
Created January 3, 2025 23:49
Show Gist options
  • Save milesfrain/12bdb41ba953d4005dfc93b40725816a to your computer and use it in GitHub Desktop.
Save milesfrain/12bdb41ba953d4005dfc93b40725816a to your computer and use it in GitHub Desktop.
NAS UPS setup

Intro

We're using a UPS to ensure the NAS cleanly shuts down upon power loss, otherwise there could be data loss, corruption, and HDD damage. I recently replaced the old and broken battery in the UPS and re-configured it with some better settings. Here are the setup notes:

Setup

UPS model:

cyber power EC650LCD

The replacable battery has a 3-10 year lifespan. It's a standard 12V 5AH sealed lead acid battery. You can order online or find locally at about half the hardware stores in the city. And any hardware store will take the old battery for safe disposal.

General UPS documentation for truenas "Core" (we may want to try "Scale" later): https://www.truenas.com/docs/core/13.0/coretutorials/services/configureups/

Driver selection

Link to driver lookup (when clicking the "?" icon next to "driver" dropdown in UPS service "edit" page): https://networkupstools.org/stable-hcl.html

Closest match on that webpage is EC850LCD, which uses usbhid-ups driver

But in dropdown, none of those are available. But any usbhid-ups driver will likely work.

  • Select: CP1000AVRLCD
  • For Port, select "auto"

Leave the "shutdown command" blank. It will do the right thing by default. Some guides suggest using a custom "halt" command for compatibility with automatic boot once power is restored. I haven't given auto-boot a try yet. Seems like that would require a lot of careful coordinating of configs between ups, nas, and bios, which could be a debugging rabbt hole. For now, we're using basic behavior which just requires someone to manually push the power button to boot after an outage.

UPS shutdown

We want to turn off UPS after NAS shuts down, otherwise, UPS battery could potentially be drained unnecessarily on extended outage, and this is bad for the battery. It should ideally just be on battery backup for as long as it takes to cleanly shut down.

  • Enable "power off ups".

There's a bug with the cyberpower devices, where the default sub-60-second delays are rounded to zero, so power is cut too soon. You can fix it by changing delay to 60. It takes about 30 seconds to fully shut down. Could also be conservative and set to a higher number, like 180.

Add this to ups.conf section:

offdelay=60

Enabling the service

On the previous page, check the "Start Automatically" box.

I've found I needed to reboot for things to work, rather than just being able to toggle "Running".

Boot loop fix

TrueNAS inherrited a FreeBSD bug where machines automatically power on after powering off, so it will never remain shutdown. Instead it will continue to boot loop until power is interrupted, which leads to an unclean shutdown.

The solution is to set hw.efi.poweroff=0 for SYSCTL in "System > Tunables". See this post for where to find that setting in the web gui.

Some other earlier attempts before finding the above fix:

  • I checked the BIOS settings and confirmed "Restore AC Power Loss" is set to "Power Off", but it automatically powers on after a shutdown.
  • I disabled "Fast Startup", but that doesn't fix the problem.

Checking that UPS service is running in the web shell

dmesg | grep -i EC650

The last line of that command should show the full UPS name (EC650LCD) and that it is connected.

upsc ups

Should spit out a bunch of info about the UPS:

Testing to verify correct behavior:

  1. Plug the monitor into the wall power strip to see NAS output. Don't plug it into the UPS, as it will lose power during the test if pugged into a basic UPS outlet, or unnecessarily waste UPS battery if plugged into a backed-up outlet. The monitor should generally only be powered when necessary for troubleshooting.
  2. Remove UPS plug from wall power strip. It will beep a bit to indicate power loss, then switch to battery backup mode. There should be some output on the monitor indicating that NAS detected the UPS switched to battery mode. After about 30 seconds on battery, the NAS will start a safe shutdown. It will indicate this on the monitor and spam a bunch of output. I changed the shutdown delay from a default of 30s to 10s so we don't have to wait around so long. When the NAS starts shutting down, it will also tell the UPS to turn off after offdelay seconds. This is set to 60s. The UPS will then display a 60s countdown on its LCD. The NAS takes about 30s to finish the clean shutdown, and will power-off. It should remain off (and not have the buggy behavior where it reboots). The UPS will power off after about another 30s when its timer reaches zero.
  3. Plug the UPS back into the wall strip.
  4. Push the power button on the NAS to turn it back on.
  5. Unplug the monitor once the NAS finishes booting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment