Is it possible to run a script on shutdown after filesystems are unmounted?

Finally I found a solution :heart_eyes:

I just had to put my script in /lib/systemd/system-shutdown/.

From the systemd manual:

Immediately before executing the actual system halt/poweroff/reboot/kexec systemd-shutdown will run all executables in /usr/lib/systemd/system-shutdown/ and pass one arguments to them: either “halt”, “poweroff”, “reboot” or “kexec”, depending on the chosen action.

If anyone else is doing similar stuff, here is the script I use:

#!/bin/bash

# only on power-off, not on reboot etc.
if [ "$1" == "poweroff" ]; then
        mount | grep mmcblk0p2 | grep -q ro &&                                          # poor check, if / is really mounted read-only
        /home/funksteckdose/raspberry-remote/send 00000 2 0 > /dev/tty1 2>&1 &&         # turn off socket 2
        /home/funksteckdose/raspberry-remote/send 00000 1 0 > /dev/tty1 2>&1 || {       # turn off socket 1 (raspberry)
                echo "Error: / is NOT read-only or other error occurred!" > /dev/tty1
                echo -en "\n>> " > /dev/tty1
                mount | grep mmcblk0p2 > /dev/tty1
                echo -e "\nNot powering-off. Sleeping 1min.." > /dev/tty1
                sleep 1m
        }
fi