[systemd-devel] network-online.target is not down when a physical network is down

Igor Bukanov igor at mir2.org
Thu Jan 22 12:17:52 PST 2015

Hm, checking nmcli -f STATE -t g does not work from a Networkmanager
dispatcher script. If I disable WiFi, that gives in the dispatcher
script "connected (local only)". If I enable WiFi, then in the
dispatcher I have "connected (site only)". Only some moments later the
state becomes "connected", but on that transition from "connected
(site only)" to "connected" the dispatcher script is not called.

What is exactly connected (site only) ?

On 22 January 2015 at 19:42, Dan Williams <dcbw at redhat.com> wrote:
> On Thu, 2015-01-22 at 19:51 +0300, Andrei Borzenkov wrote:
>> В Thu, 22 Jan 2015 16:44:52 +0100
>> Igor Bukanov <igor at mir2.org> пишет:
>> > For a service that should be shutdown when network is not available, I
>> > tried to use Requires=network-online.target . However, on Fedora 21
>> > with NetworkManager that does not work. When I switch off WiFi, the
>> > only connection on my laptop that can configure default IP route and
>> > setup /etc/resolv.conf, network-online.target still stays active and
>> > my service continues to run. Is it a bug in Fedora? If not, what is a
>> > canonical way to implement such dependency?
>> No, it is not a bug. network-online was never intended to be used this
>> way. It was intended to be used only during startup; when initial
>> startup is finished, state of this service is largely irrelevant.
>> network-online.target itself does absolutely nothing. It is provided as
>> well known name for other services to order itself after; and you need
>> to provide implementation that orders itself before.
>> For NM implementation would be NetworkManager-wait-online.service that
>> basically does nothing more than calling nm-online.
>> Note that "network down" does not cause any change state in systemd.
>> NetworkManager still runs. systemd itself does not watch or manages
>> network, so it cannot initiate any actions here. I suppose you really
>> want to hook systemctl stop/systemctl start in NetworkManager
>> dispatcher framework.
> Yeah, a dispatcher script ("man NetworkManager" has more info) will be
> executed whenever any network interface is deconfigured by
> NetworkManager.  You could use this, in combination with 'nmcli -f STATE
> -t g' (which reports the NM state as a single word, eg "connected" or
> "disconnected" or "connecting"), to determine when no network
> connections are active, and then run 'systemctl stop your-service".
> See also
> http://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/examples/dispatcher
> Dan

More information about the systemd-devel mailing list