I have made a
systemd service which performs some actions just before the machine shuts down. Its unit file is:
[Unit] Before=shutdown.target DefaultDependencies=no [Service] Type=simple ExecStart=/opt/demo.sh TimeoutSec=infinity [Install] WantedBy=shutdown.target
Currently, the script runs before the machine loses network connection, but after SSH connections are closed, and if I try to reconnect, it fails with “Connection refused” error. I would prefer keeping SSH connection until the script itself terminates (for instance to be able to
tail -f /var/log/syslog its execution.)
How do I force to run the script before SSH server closes?