[systemd-devel] does "Before=network.target" really work

Xin Long lucien.xin at gmail.com
Fri Jun 24 10:53:49 UTC 2016


On Fri, Jun 24, 2016 at 6:22 PM, Michael Hirmke <mh at mike.franken.de> wrote:
> Hi Xin,
>
>>Hi,
>
>>I have a service, and want it to be stopped only after network is
>>stopped when system shutdown.
>
>>I checked "man systemd.special ", network is a special internal
>>service for systemd, , and I found "network.target":
>>"at shutdown, a unit that is ordered after network.target will be
>>stopped before the network -- to whatever  level it might be set up
>>then -- is shut down".
>>That means "After=network.target" can work well.
>
>>But my situation is opposite to that, I need "a unit that is ordered
>>before network.target will be stopped *after* the network so
>>shutdown".
>
>>So I added "Before=network.target" to .service file. can it really
>>work as I expect?
>
> it depends on what you're trying to do with this information.
> AFAIK network.target is related to the network stack as such. It does
> not apply to a certain interface is up, down, activated or deactivated.
> If you need the information for the network stack being up or down,
> the use of network.target is ok - and works for me.
>
my case only cares about shutdown time.
I do not know "Before=network.target" can make my service stop
after which phase of network is stopped.
and I also cannot find anything in man doc.

but I can find some services are truly using it now:
$ grep "Before=network.target" . -R
./wpa_supplicant.service:Before=network.target
./NetworkManager.service:Before=network.target
./NetworkManager-wait-online.service:Before=network.target network-online.target
./arp-ethers.service:Before=network.target
./firewalld.service:Before=network.target

what I need is just make sure my service will stop after we just can't
communicate with other host. (no need to after device down, or stack
is removed)


More information about the systemd-devel mailing list