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

Igor Bukanov igor at mir2.org
Wed Jan 28 01:04:27 PST 2015

Just for references. With the the following script placed in
/etc/NetworkManager/dispatcher.d/90-online-monitor everything works.
As the service is started explicitly the unit file needs no Install

status="$(nmcli -f STATE -t g)"
if [ "_$status" = _connected -o "_$status" = "_connected (site only)" ]; then
    systemctl start my-service
    systemctl stop my-service

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