News for hackers. Stuff that matters.
Re:Writing systemd units that stop gracefully before shutdown by CGamesPlay on Wednesday October 26, 2022 @05:37PM (#33349855)
You unit races with the network being brought down, since it isn't listed as a "Before" target, FYI.
Re:Writing systemd units that stop gracefully before shutdown by boring_twenties on Wednesday October 26, 2022 @05:53PM (#33350067)
I could be mistaken, but I don't think even that would be sufficient? Before would make your command execute before the network is brought down, but it wouldn't have the latter wait for your command to actually complete.
Re:Writing systemd units that stop gracefully before shutdown by dghubble on Wednesday October 26, 2022 @05:59PM (#33350147)
The post shows long-running stop scripts / containers and demonstrates them delaying shutdown (not with KillMode none though)

@CGamesPlay network.target's "primary purpose is for ordering things properly at shutdown: since the shutdown ordering of units in systemd is the reverse of the startup ordering, any unit that is order After=network.target can be sure that it is stopped before the network is shut down if the system is powered off."

https://www.freedesktop.org/wiki/Software/systemd/NetworkTar...

Re:Writing systemd units that stop gracefully before shutdown by AnssiH on Wednesday October 26, 2022 @06:59PM (#33350760)
They need After=network.target, not Before=network.target.

The shutdown order is the reverse of startup order, and they execute the payload on shutdown (ExecStop).