I want to run a script when a user shuts their computer down, but it needs networking. So I'd like it to run when the system is heading for shutdown (or restart), but it needs to run before anything is unmounted or networking is shut off.
How can I do this?
After=network.target
? – rich remer Mar 22 '19 at 19:54network.target
andnetworking.service
on your system. You'll see they are different. Here I think using a.service
is more appropriate, because a target is a like a "goal state" to boot up to. "Stopping a goal state" doesn't make as much sense as "stopping a service". In fact, either may work, but I think using a service is clearer here. – Mark Stosberg Mar 25 '19 at 14:16networking.service
did not work for me. Secondly, https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/ says that you should useAfter=network-online.target
+Wants=network-online.target
. Can you edit your answer, @MarkStosberg ? – Greg Dubicki May 22 '19 at 18:09