[systemd-devel] Help required for configuring a blocking service during shutdown

Etienne Champetier champetier.etienne at gmail.com
Wed Aug 31 12:16:53 UTC 2022


Hi,

Le lun. 29 août 2022 à 06:31, Henning Moll <newsScott at gmx.de> a écrit :
>
> 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

My use case was to prevent firmware flashing from being killed, unit
is started via udev
~~~~~~~
[Unit]
Description=Check/update firmware on device %i
DefaultDependencies=no
After=local-fs.target dev-%i.device
Requires=local-fs.target dev-%i.device
Before=<device-user>.service

[Service]
Type=oneshot
ExecStart=/usr/lib/flash.sh /dev/%i
# Don't interrupt flashing
TimeoutStopSec=infinity
KillSignal=SIGCONT
~~~~~~~
The really important part is the last 2 lines so the process is not killed.
Adding the right After and Requires might do the trick for you
(DefaultDependencies=no / Before might not be needed)


> Can you please help me?
>
> Best regards
> Henning


More information about the systemd-devel mailing list