Would the systemd inhibit interface be an option? https://www.freedesktop.org/wiki/Software/systemd/inhibit/
It was designed for that use case after all. Am Mo., 29. Aug. 2022 um 14:01 Uhr schrieb Mantas Mikulėnas <graw...@gmail.com>: > > On Mon, Aug 29, 2022 at 1:31 PM Henning Moll <newssc...@gmx.de> wrote: >> >> Hi, >> >> back in the rcX days I configured a backup system which blocks a system >> shutdown in a certain state (network and mounts still active) if a backup is >> still running. The init script looks like this: >> >> ... >> case "$1" in >> ... >> stop) >> plymouth --ping >> if [ $? -ne 0 ]; then >> log_daemon_msg "waiting for running backup" "backup" >> else >> plymouth message --text="waiting for running backup" >> fi >> sleep 10 >> logger -t backup "rcS: trying to get lock..." >> exec {FD}<>"$LOCKFILE" >> { >> logger -t backup "locked rsync_wrapper: waiting for lock" >> flock ${FD} >> } >> logger -t backup "rcS: continue shutdown..." >> plymouth message --text="" >> >> ... >> esac >> ... >> >> The strategy is to wait for a successful lock on a shared LOCKFILE. >> >> Now, I want to solve this with systemd. I've read tons of documentation but >> I don't get it, all my experiments failed. I am using Linux Mint 21 >> "Vanessa", which is based on Ubunut 22.04. >> >> I am looking for a solution which >> >> * "pauses" a shutdown or reboot attempt as long as the LOCK cannot be >> obtained (which means the backup is still running) >> * while the network connection (ethernet) is still active >> * and all mounts (local, usb and cifs) are still active >> * openssh-server still running >> * The logging functionality (plymouth / log_daemon) would be nice. so the >> system should be allowed to shutdown to a stage where plymouth is already >> visible >> >> Can you please help me? >> >> Best regards >> Henning > > > Probably similar to what you already have – create a service that starts on > boot (doing nothing) and delays the *stop* action. (You'll probably need to > start with [Service] Type=oneshot, RemainAfterExit=yes, TimeoutStopSec=1d.) > If you list After=ssh.service as a dependency, then your service will be > started after OpenSSH and *stopped before OpenSSH*, same with NetworkManager. > (I'm not sure if there's a dependency that can be used to target manually > done SMB mounts, although remote-fs.target might work for the ones in fstab?) > > Not sure how it works with Plymouth, but in its default console output, > systemd itself will already show which services are waiting to be stopped. > Syslog (journald) should be available the entire time. > > The backup system should also run under `systemd-inhibit --what=shutdown` as > an additional layer of precaution – that way the user will know that > something is still running *before* they initiate the actual shutdown. > > -- > Mantas Mikulėnas