[systemd-devel] Handling on network-connections and networkmanager
dcbw at redhat.com
Mon Jun 19 15:55:04 UTC 2017
On Sun, 2017-06-18 at 01:47 +0200, Jakob Schürz wrote:
> Hi there!
> I didn't found anything about the following problem:
> There is network.target and network-online.target. In combination
> NetworkManager network-online.target get started, when
> NetworkManager-wait-online.service exits successfull.
> This is all ok, if i have a computer with permanent LAN/WLAN-
> But it doesn't fit the needs for laptops moved in different networks.
> I need NetworkManager, because i use LAN, WLAN, Modem-Connections as
> well as USB-Thetering. So a setup with networkd is not the best way
> my case.
> I have some ftp-mountpoints, which i have configured with automount
> auto-unmounting after idle-time.
> When the automount is activated on boot, a simple ls on this
> can block the whole system, when there is no network. So i bound the
> automount-unit to network-online.target with
> "BindsTo=network-online.target". This works fine. ls gives me an
> directory, when no network-connection is active, and gives me back
> content of the mounted dir, when the network-connection is active.
> When i stop the network-connection from the gnome-nm-applet, or when
> sitting in a train and there is no network-connection possible (in
> of a tunnel), the automount-unit should be stopped. But in normal
> configuration this never will happen.
NetworkManager has a "pre-down" capability via dispatcher scripts (see
man NetworkManager) that calls out to scripts in
/etc/NetworkManager/dispatcher.d when a network connection is
disconnected explicitly by the user. You could use this to unmount
cleanly when using NM. NM will block the actual network disconnection
until your script completes (subject to reasonable times of course).
Obviously, if the network connection drops unexpectedly this is not
possible, and the connection is already gone when your script runs. So
the best possible way to solve all this is to ensure that your
filesystem driver can handle unexpected network dropouts cleanly.
> Do you have any suggestions, how to solve this problem?
> I tried a solution:
> i created a simple script, which checks the connection every minute.
> there a connection, and is this connection working (realized with a
> to a server in the internet), then network-online.target gets
> If there is no connection, or the connection is not working (think
> WLAN in a train in a tunnel, WLAN is working, but no connection to
> internet is possible), network-online.target gets stopped.
> Also a simple script in NetworkManager/dispatcher.d/, wich starts
> network-online.target, when a connection changes its state zu up, and
> stop this target, when a connection changes to down.
> All services, which should stop on closing the network-connection
> the dependency BindsTo=network-online.target
> But i'm not sure, if this is a good solution to change the behaviour
> network-online.target. Should i create a own target? Or is there
> another, better solution?
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
More information about the systemd-devel