Is there a way to run a script on shutdown, after the file system is remounted as read-only?I've a raspberry pi connected to a wireless socket, which I can control via a sender and a script. I want to power off that socket (powering off the raspberry) on shutdown, after the file system is mounted read-only.I've tried this:[Unit]Description=TestDefaultDependencies=noRequires=shutdown.target umount.target final.targetAfter=shutdown.target umount.target final.target[Service]Type=oneshotExecStart=/testKillMode=none[Install]WantedBy=halt.targetThe script /test does output the current mounts. When it's run on shutdown, it states read/write for the root file system and not read-only as expected.Edit:Content of /test:#!/bin/bashecho -n 'Debug-Mount: ' > /dev/tty1cat /proc/mounts | grep /dev/sda > /dev/tty1Screen output on shutdown:
systemd: running a script on shutdown after filesystems are mounted read-only
systemd;shutdown;init script;readonly;unmounting
I found a reliable solution: Just put the script in /usr/lib/systemd/system-shutdown/.See also: https://www.freedesktop.org/software/systemd/man/systemd-halt.service.htmlImmediately 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. All executables in this directory are executed in parallel, and execution of the action is not continued before all executables finished.