How to send pending shutdown message to systemd services

I’m using Fedora CoreOS with the automatic updater enabled, which is great for my use case. Already, when logged in interactively, the system warns about an imminent shutdown/restart via the console, with the same mechanisms described in the answers like
Sending shutdown messages to all clients from server

However, the “actual” users of this server aren’t Linux users with SSH access but access servers like an IRC or other services. I would like to “catch” the shutdown warning message and forward it to each of the services, s.t. they can broadcast it.

The services are orchestrated using unprivileged podman/docker containers ran through systemd (podman-generate-systemd) user units.

I can (ab)use the ExecStopPre setting in the systemd unit to always sleep 5m before shutting down the unit. This isn’t precisely what I want, though, as I’d like to be able to restart/stop a service immediately, when done manually using systemctl --user stop/restart.

I currently see two paths that could enable this:

  1. some way for units to listen to wall messages and forward them
  2. some way of specifying --ignore ExecStopPre on the console.

The latter can be, albeit unergonomically, be achieved using systemctl --user edit --runtime. However, the second approach has the downtime of (ab)using ExecStopPre while it may be needed for other purposes already.

Nonetheless, I’d be glad for ideas on how to achieve (1) or to make (2) a bit more nice to work with. Or even completely different approaches to the problem.

Answer

Attribution
Source : Link , Question Author : ljrk , Answer Author : Community

Leave a Comment