I don’t know why there are suggestions to modify the [Install] section and other similar in those threads. Maybe if I thought longer on what those threads are trying to accomplish I’d see their reasoning.
You should be able to modify the ExecStop command…
As usual copy the Unit file to be modified to the location in /etc/systemd/, for instance the following if you’re running wicked. If you’re running NM, you’ll probably have a network.service Unit file. Copying the Unit file allows you to create a custom version which over-rides the default without altering the default. If you ever need to recover or undo your changes, just delete your custom file allowing the default to become effective again.
Modify your custom file.
Use a reference like the following to know your various options which in your case includes “wants,” “requires,” “requisite,” and possibly more depending on how hard a requirement you want your modification to be. You can point directly to a script or better is to create a Unit file which invokes your new functionality and point this Unit file to the Unit file with your functionality. http://www.freedesktop.org/software/systemd/man/systemd.unit.html
Reload your systemd configs
Any time you modify a Unit file, you’ll need to reload the system to incorporate your changes
systemctl daemon-reload
You might want to be more specific about what you’re trying to invoke before network shutdown if the above isn’t sufficient.
Well,
That may be true.
I had assumed (perhaps incorrectly) that network services would be stopped when a system is suspended but that may not necessarily be the case.
From what I’ve seen before,
suspending the system can be executed a number of different ways, so for instance various power commands executed in a command line would almost always be very different than what happens when you execute a system “sleep” or suspension from a Desktop.
So, to the OP…
You should describe how your system is being suspended and then let that be a starting point for determining your system suspension sequence.
Then, you should be able to insert a trigger somewhere in that sequence that invokes what you want to add to the sequence.
The key may be to ensure NetworkManager.service to stop (or restart) before suspending. I tested this using the approach described in the post linked to below, and that caused the dispatcher script to get executed as hoped.