Close

day six - shutdown shenanigans

A project log for laptop2pi

Frankentop (noun): A laptop created by combining parts from disparate computers, e.g. an HP 1101 combined with a Pi Zero.

mincepimincepi 01/30/2017 at 20:520 Comments

There's one problem with this setup: shutdowns.

The laptop needs to save state to the mass storage device when halted in persistent mode. After the laptop has halted the Pi Zero needs to shutdown properly. But you can't communicate with the Zero to shut it down because the laptop is halted. What to do?

I solved this with a watchdog shell script on the Zero. It first waits until the laptop responds to pings, then when the laptop no longer responds it shuts down the Zero. That way it gets a graceful shutdown after the laptop halts. I also built in a timeout: if the laptop doesn't initially respond for three minutes the Zero shuts down anyway. This handles the case of the laptop failing to boot up properly. You also shouldn't shut down the Zero from it's command line: I'll probably remove or rename the shutdown and poweroff commands to fix this.

Yes, I know a poweroff button on the Zero would be the best solution. There's even a device tree overlay to make this simple. But I'm trying to keep this a minimal project.

You also should never use the poweroff command on the laptop - it kills power to the Zero while it's still running. (That was a bit of a surprise the first time I did it - I hadn't thought things through.) That's bad for the SD card. So, I'll probably remove the poweroff binary, make a new shutdown replacement shellscript that can only do halts, and modify the shutdown command in the window manager. That should cover all cases.

I'll do the file munging later. For now I'll just have to be careful!

Discussions