← Blogs· 2 min read

The Chicken-and-Egg Problem of a Virtual Router, and How I Solved It

How I start and safely shut down an OPNsense router VM on Proxmox during power outages, using a custom Go CLI called router-ha.

Earlier this year, I wrote about how I used an ESP32 to safely shut down and start my homelab server. Since then, my setup has changed. I now use OPNsense as my firewall and router software, because my home Wi-Fi keeps growing and I have APs spread across several rooms.

I run OPNsense as a Proxmox VM, because I don’t want to spend money on dedicated hardware for it. That creates a chicken-and-egg problem. The other VMs depend on OPNsense, but OPNsense lives on the same Proxmox host. How do I start it so the other VMs don’t break? And how do I power it off safely so none of my connected devices break?

The video below shows how I solved it. The trick is the same as before. I use an outside device (the ESP32) as the reference for the current power state.

Breakdown

Why OPNsense? Why not use the ISP router?

My ISP (Indihome) has very limited features, and I need more to organize the network at home. Also, some domains are blocked in Indonesia, and I need a way to get around that.

Why not keep OPNsense running during a power outage?

A UPS has a limited battery, and running Proxmox uses a lot of power. I want to save that battery so I still have Wi-Fi during the outage. While the power is out, my ISP router turns on a backup Wi-Fi.

What is router-ha?

It’s my custom Go CLI that manages the whole lifecycle. The source code is in my homelab-utils repository.

Why does only one AP stay on the UPS?

When the setup moves between normal mode and outage mode, I need one AP that stays alive long enough to keep the Wi-Fi up. The other APs have no UPS, so they power off. The code that turns the relay for that AP on and off is in my homelab-iot repository.

Why is that AP on UPS 1, not UPS 2?

My Proxmox host is plugged into UPS 2, and UPS 1 has a lot more capacity than UPS 2. If UPS 2 dies, Proxmox dies instantly and the power outage process never finishes. Plugging the AP into UPS 2 as well would drain it faster, because two devices use more power than one. So the AP stays on UPS 1.

Is it overkill?

Yeah yeah, definitely. But now my Wi-Fi survives power cuts without me touching anything, and I had a lot of fun learning how to build it :D

esc