If you know who Varys is, you’ll know he’s nothing without his “little birds.” They’re the ones who listen to the whispers of power and then tell him all about it.
Well, my varys needs some listeners too.
For years I’ve protected my office server from the harsh indignities of sudden power failures by shielding it behind a traditional UPS battery backup. For more than a decade, this arrangement has kept my pixels glowing through half a dozen actual power outages, and any number of brown-outs and glitches. Over that same period, the internal battery has eventually died and been replaced twice. I don’t begrudge the battery for failing - it’s an ancient battery tech that has more in common with the battery in your car than the one in your cell phone - but the replacements are expensive.
So when the battery failed again this week, I decided it was time to re-evaluate.
◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇
When I first bought the UPS, I was sitting at my main computer every day, rendering animations, editing videos, running long-term research algorithms. In short, back then, a power failure risked significant loss of invested time and effort, not to mention the chances of hard drive damage and file system corruption.
My computing today still happens on that computer, but I don’t run many high-stakes jobs anymore, so my needs for power security have changed. I no longer need the system to be capable of running at full power for an hour or two - I just want to ride out short-term power losses and be able to shut things down gracefully during extended outages. Say, anything over 20 minutes. And to be honest, having to swap out the old battery every 3 years has felt wasteful every time.
So with those issues in mind, I started looking into modern alternatives, and I’ve been seduced by the idea of using a portable power station instead. These days, when I’m not actively working, that server is often shut down completely, so if I want to go work in the park for the afternoon, it would be awesome to be able to take extra power with me.
Many of these modern battery systems switch fast enough to provide power continuity to the server, but they don’t have any built-in way to tell the computer that it has gone onto borrowed time, or to shut it down when the battery gets low. So if an outage were to last a full hour, I would still face the possibility of a sudden, unmanaged shutdown.
But I think I’ve come up with an interesting way to handle that.
The power station I settled on is the Anker Solix C300. It’s small, highly portable, and has more than enough oomph to keep my server going for a while. But Anker has not yet opened up its internal API, so there’s no way for my server to monitor the Anker’s status directly.
At first, I wondered about building a little Arduino circuit that could live in a wall-charger near the computer and send regular “I’m still alive” messages to the server over USB. I would have to write a simple service daemon to watch for that message and trigger a shutdown whenever the signal goes dark, but I worried that might be a bit risky. If the Arduino ever got unplugged (either from the computer or from the wall) it would trigger a false shutdown. So I started looking for additional ways to verify the power loss, which led me to a few other signals I could check.
The display monitors are plugged in too - both to main power and to the computer - so I can watch those as well as watching the Arduino. If the monitors both go dark at the same time the Arduino goes out, that’s a more reliable sign of trouble in power-land. But realistically, I can also see myself forgetting the plan and turning those screens off automatically when I leave my office, which would put us back to relying solely on the Arduino again. So the screens alone are not quite enough.
Then I realized there was another device on mains power that I could monitor - the Ethernet connection to my router. What are the odds that my router, the Arduino, and both monitors are all going to go down at the same time? It’s not zero, but now we’re getting close enough to zero that I don’t really care.
But wait a minute - do I still need the Arduino at all? Hell no! Because I’ve also got a 3D printer connected. And a document scanner. And a powered USB hub. All of those devices will go dark if mains power fails, so if they’re all gone, and the server is still running, there’s a damned good chance the power is out and we’re running from the Anker.
So what do we call a sneaky little servant who hides in the background and keeps an eye on pulses of power throughout the realm? Someone who is constantly working to protect the king, and will move quickly to defend him as soon as he senses a shift in the currents of power?
The public repository for the code lives here.
If you know who Varys is, you’ll know he’s nothing without his “little birds.” They’re the ones who listen to the whispers of power and then tell him all about it.
Well, my varys needs some listeners too.
The plan is to deploy this site to a robust HTML-only server, which will keep costs down and security high, since there won’t be any programmatic interfaces on the site itself that can be hacked. My deployment engine of choice is simple: I’ll be using git push
. But before I sign up for a hosting account and start pushing my brains out the door on an automated basis, I wanted to test that procedure on a smaller scale, here in the lab.