We had a power cut this afternoon and the UPS kicked in and did its thing for the GeekLab and VMs shut down gracefully with no data loss thanks to apcupsd sharing battery status with all the VMs. Since the power came back before the battery was exhausted the server didn't do a full restart and this uncovered an interesting exception which left two of the survivors telling restarting VMs to shut down as soon as they'd started as there was a power problem. Not helpful.

This was an interesting little dive into GRUB recovery mode and getting into a Linux server via the console when it was not behaving as expected, but was doing exactly what it was told.

Since the first GeekLab I've had a small UPS connected to the server to allow for a graceful shutdown in the event of a power failure. When we moved to our current home we were living in the middle of building site for a couple of years and for several months one of the three grid power lines into the village was shut down to make way for a row of houses and powercuts became a regular occurance untill the replacement underground cable was finally connected.

The current incarnation of GeekLab has a slightly chunkier CyberPower 900VA UPS as it took an instant dislike to the APC unit I was using. Nice fancy workgroup server and it can't live off the grotty output your standard APC BackUPS unit - and if you ever look at the output of a Back-UPS inverter it is horrible - "stepped sine" is their discription, in the same way that walking though buckets of broken glass in bare feet could be described as being a bit tickly. The other big advantage of the CyberPower is it fully supported by the venerable apcupsd appliction which allows VMs to be told there's a problem and shut themselves down gracefully.

And as proved earlier today that was sufficient to keep the essentials going for 10 minutes until the lights came back on. Most of the VMs had landed safely this point - I'd rather they stop with plenty of time and ideally stop the server completely to reserve the last dregs of battery for keeping the broadband up -  and I'm happy to say there was no data loss. If the server itself had shut down then ESXi autostart would have brought everything back online for me too once power returned - there's no way for an offline VM to restart itself once but it was only a few minutes to bring them back up again. This is a known gap in my DR plan and not one I can do much about given the restrictions of the ESXi licence.

My configuration has one VM that provides some network services as the apcupsd master that connects via a USB device in ESXi to the UPS via the signalling cable that's plugged into a USB port on the back of the server. All the other VMs have apcupsd installed as an online slave and poll the master every minute to confiirm the UPS is good. So within a minute of a power failure all the VMs are aware there's an issue and after a delay start shutting themselves down with the most important VMs waiting until last.

I also have some VMs in lab subnets that connect to an internal router VM so I can control what they get up to. They get UPS updates from that router VM so they don't need direct access to the master. The apcupsd application can be configured as a daisy-chain or tree - it's very flexible.

I left restaring the labs untill this evening and starting with the Samba DCs as they also provide DHCP and DNS services so need to be the first ones up, neither of them would start. Or at least, they would start, but after 26 seconds shut themselves down. Having one VM go weird after a power failure is not good, but having two started to look odd. I tried with the test subnet and same issue, neither of the DCs would start. At this point I'm starting to get concerned as this is sign that something is seriously wonky. 4 Samba DCs all doing the same thing is not a co-incience. Thankfully both DCs on the live network were fine, so that suggested the recent round of patching probably wasn't to blame, until I realised that the two live DCs had slightly later versions of everything. At this point I'm thinking rebuild and restore and rude words started to form in my mind.

I even took to recording the console screen during startup my phone to see if I could spot any error messages. Ubuntu helpfully did a clear screen when it went into shutdown mode so I didn't spot anything odd. The last message was:

[ OK ] Finished grub-initrd-fallback.service - GRUB failed boot detection.

This made me think that it was potentially a corrupted filesystem - odd that 4 or 6 would be affected but not something to rule out. With a bit of keyboard sharpshooting I managed to hit ESC at just the right point during the boot process to get Ubuntu to show the boot menu (this is server, not desktop so it's not shown by default) and go into Advanced and then start in to recovery mode. 

This give root access to the VM and there were no obvious issues, root filesystem was mounted and only 40% used so plenty of space to spare, which ruled out another potential cause. This also gave me access to the logs and one of my love-to-hate commands journalctl. So unbelievably slow. Such a pain to find what you want as messages can be under system, unit or other categories. But it does have ability to say "show me the logs for the last x minutes" as one combined output. After a bit of searching and going back in time, there it was:

systemd[1]: apcupsd.service: Can't open PID file /run/apcupsd.pid (yet?) after start: No such file o>
apcupsd[928]: apcupsd 3.14.14 (31 may 2016) debian startup succeeded
apcupad[928]: NIS server startup succeeded
systemd[1]: Started apcupsd.service - UPS pwoer management daemon.
systemd[1]: grub-common.service: Deactivated successfully.
systemd[1]: Finished grub-common.service - Record successful boot for GRUB.
systemd[1]: Starting grub-initrd-fallback.service - GRUB falied boot detection...
apcupsd[928]: Shutdown because NIS server master is shutting down.
apcupsd[928]: Remote shutdown requested.
apcupsd[928]: Initiating system shutdown!
apcupsd[928]: Shutdown because NIS master is shutting down.
sbkeysync[911]: Filesytem keystore: ...

So nothing to do wth grub afterall. Apcupsd is having a fit.

My first thougth was to try and disable apcupsd on the Samba DC hosts, but then that bit about NIS server master suggesting it was doing what it was supposed to do and only 4 out of 16 VMs were doing this so it probably wasn't a config issue. Doing an apcaccess on the VM with the master node showed no problems, the UPS was online and charging. I restarted apcupsd on there anyway but no difference, they still kept shutting down.

Then the thought hit me (which was bit unfair as I'd not done anything mean towards that particular thought). The apcupsd daemon on the lab Samba DCs was configured to connect to their subnet router VMs. Both of which had survived the outage, but perhaps they'd already started shutdown? I restarted the router VMs and then rebooted the Samba DC and success! It started and completed boot wih no issues. Repeat for the other router and all remaining lab DCs came back to life.

Checking the apcupsd event log at /var/log/apcupsd.events revealed what had happened. There's nothing like finding the evidence to support a reboot decsion after it's been done, but this isn't a strict ITIL operation and I'm judge and jury on this so that's a justified example of experience over process. 

2026-03-12 11:05:57 +0000 Power failure.
2026-03-12 11:06:03 +0000 Running on UPS batteries.
2026-03-12 11:12:44 +0000 Reached remaining time percentage limit on batteries.
2026-03-12 11:12:44 +0000 Initiating system shutdown!
2026-03-12 11:16:17 +0000 Mains returned. No longer on UPS batteries.
2026-03-12 11:16:17 +0000 Power is back. UPS running on mains.

The routers had indeed started their shutdown process and while this was in progress the power came back on. My guess is apcupsd then stopped the shutdown, but the NIS was still reporting shutdown in progress so anything that then connected to it would get old data. My master server had not yet started the shutdown process so VMs that connected to it directly were not affected.

Aftermath

  1. So it looks as though there's an issue in apcupsd where it doesn't fully recover from an abandoned shutdown. Based on this it would be more sensible that once the shutdown has started it would be safer to switch to a reboot rather than simply stopping with the VM in a potentially half-stopped state.
  2. I'll also update my notes to check all VMs and reboot any that started the shutdown process. If I remember to read notes next time something like this happens...
  3. It might also be more helpful if Ubuntu didn't do a clear screen the moment it went into shutdown mode. Probably not much chance of that being changed though.
  4. I'll also look at enabling the GRUB screen for a few seconds during boot to make it easier to seize control shouid I have boot problems in the future. One for the 26.04 templates.
  5. I also want to understand why the router VMs were still up 3.5 minutes after the shutdown was started. When I do a shutdown command they're dead within ten seconds.