GNOME Bugzilla – Bug 686047
RFE: Overall network status environment variable in dispatcher scripts
Last modified: 2013-05-06 16:46:01 UTC
It would be nice if there was a variable that dispatcher scripts could check to determine overall network status - whether or not network access is expected or not. I'm assuming that a message like that is available over dbus - having the equivalent in the dispatcher scripts would be very useful.
Technically, it would be possible. But not sure if we want that. At present we expose stuff like DHCP, IP and the like in dispatcher scripts. These variables are relevant to specific connections which is what most actions (up, down, vpn-up, ...), except 'hostname' action, deal with. You can always use e.g. nmcli in the dispatcher script to query any information about NM. For getting overall status use: LC_ALL=C nmcli -t -f state nm Or, do you suggest introducing a new action "state-changed" that would call scripts when the state changes?
There are times when you need to do things (start/stop services) depending on whether or not a machine is on any network or not. Thanks for the nmcli suggestion, but it seems that if that is available in NM it should be directly available in the dispatcher script without the overhead of running nmcli.
Well, while looking at trying to implement what I wanted to do, I found that it just may be too complicated. One problem is that service/systemctl does not appear to have a "start-if-enabled" command, which may be solved in the future, but for now it just might not be worth it. On the other hand, it still probably makes sense to export a NM_STATE variable or similar.
> Well, while looking at trying to implement what I wanted to do, I found that it > just may be too complicated. Sometimes it's better to at least briefly describe your intentions. > One problem is that service/systemctl does not > appear to have a "start-if-enabled" command What is your use case for that? > but for now it just might not be worth it. On the other hand, it still > probably makes sense to export a NM_STATE variable or similar. Possibly.
I want to run the puppet client only when a network connection is active (and only when puppet is enabled).
(In reply to comment #5) > I want to run the puppet client only when a network connection is active (and > only when puppet is enabled). It's been sitting here without reply for some time. I think that the best way to check overall network status is using the dispatcher scripts to *trigger* your action and then *check* the status via public API (a python script using libnm-glib or, if you're not concerned about API stability, a nmcli command line). Please reopen if that doesn't work for you for some reason or another.