On Fri, 24.06.16 18:41, Xin Long (lucien....@gmail.com) wrote: > On Fri, Jun 24, 2016 at 6:23 PM, Andrei Borzenkov <arvidj...@gmail.com> wrote: > > On Fri, Jun 24, 2016 at 1:11 PM, Xin Long <lucien....@gmail.com> wrote: > >> 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? > >> > > > > No. That is why systemd was forced to introduce additional > > network-pre.target to make it possible to explicitly order things > > before networking is started (or stop after networking has been > > stopped - assuming of course that all services that implement > > networking correct order themselves After network-pre.target). > > So you mean "Before=network-pre.target" can work on my case, right ?
Yes, that's what it is for. Also make sure to actually pull in the target from your service too. Hence you want: Before=network-pre.target Wants=network-pre.target n-p.t is a target that is "passive", it needs to be pulled in by the implementor of such a service, not by the consumer of it. This has the benefit that as long as no service wants to hook into this nothing is added to the transactions for bootup and shutdown and thus more can be parallelized as one synchronization points less is in the queue. See systemd.special(7) about it as well as https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/ > >> I have a service, and want it to be stopped only after network is > >> stopped when system shutdown > > and since which version "network-pre.target" was introduced ? > cause I didn't find it in "man systemd.special" in my system. This has been addedin systemd 214. Lennart -- Lennart Poettering, Red Hat _______________________________________________ systemd-devel mailing list systemd-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/systemd-devel