I’ve created an automation using Home Assistant to shut down parts of my network when we’re sleeping or when we’re away from home. With today’s energy costs and my tinkering hobby I’ve decided that all small things help. Currently it saves me about 0,7kWh each night, yearly that is about 250kWh. That is a lot.
Now, part of this automation are 2 of my 3 Raspberry Pi’s. Both are running DietPi. Before I cut power by disabling PoE on their respective ports I thought it would be wise to run a poweroff command so they have a clean shutdown before I cut power.
Currently Home Assistant runs a shell_command to the Pi’s “sudo poweroff”. The Pi’s then shutdown and after 30 seconds I give the command to my switch to cut power.
Question: How can I verify that the Pi’s are actually shutdown correctly> I want to make sure they’re not in the middle of the poweroff command when cutting power. Is there a log somewhere I can read when they’re online again to check if the previous shutdown was finished correctly?
Simply check if they are reacting on
I could use that to check if it’s actually down before turning off PoE.
Is the Pi actually done shutting down when network goes offline? Is that instant, or are other processes on the Pi itself still shutting down?
Perhaps I’m making this more difficult then it is. I’m just interested if a log can tell me more about the poweroff process.
If the network is down, how you like to get logs or anything else from the system?
In my question I stated that I wanted to take a look at a log when I turn the Pi on again. To see if all processes where actually properly shut down before power was cut.
In this case you need to make the log persistent because of on a default setup logs are just temporary
persistent system logs:
dietpi-software uninstall 103 # uninstalls DIetPi-RAMlog
mkdir /var/log/journal # triggers systemd-journald logs to disk
reboot # required to finalise the RAMlog uninstall
Then you can check system logs via:
which will then show as well logs from previous boot sessions. To limit the size, you can additionally e.g. apply the following:
mkdir -p /etc/systemd/journald.conf.d
cat << '_EOF_' > /etc/systemd/journald.conf.d/99-custom.conf
This will limit logs to 14 days split across two journal files, so that with rotation you will always have between 7 and 14 days of logs available.
And once I confirmed this I could reverse the process by using:
dietpi-software install 103
Yes should work the other way around as well.