emit net-device-down signal when network-manager deconfigures interface

Bug #998388 reported by muzzol
40
This bug affects 8 people
Affects Status Importance Assigned to Milestone
network-manager (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

I want to execute a script when network (any interface) goes up and when goes down (with parameters).

I've found easy to trigger first part with

    start on (net-device-up IFACE!=lo)

but didn't manage to found an easy way to trigger either net-device-down, net-device-remove(d) , deconfiguring-networking

my job loks like this:

##################################################################
description "network test"

start on (net-device-up IFACE!=lo)
# stop on ((net-device-down IFACE!=lo) or deconfiguring-networking)
stop on net-device-removed IFACE!=lo

pre-start exec /opt/test.sh start "$UPSTART_JOB - EVENT: $UPSTART_EVENTS"

post-stop exec /opt/test.sh stop "$UPSTART_JOB - EVENT: $UPSTART_STOP_EVENTS"

##################################################################

to test it I just go to nm-applet and deactivate one interface.

I've finally managed to make it work creating a simple script in '/etc/network/if-post-down.d' to force emmiting the signal. something like this:

########################################
#!/bin/sh

[ "$IFACE" != "lo" ] || exit 0

initctl emit -n net-device-removed IFACE=$IFACE

########################################

I'm not sure if this is expecte behaviour, if this is a feature request or if it's a real bug, but for company pourposes I really need to emit a signal when any interface (not lo) goes down.

please, ask for further info

EDITED: I can see here

https://lists.ubuntu.com/archives/upstart-devel/2011-January/001379.html

that '/etc/network/if-down.d/upstart' should emit net-device-down but in my case that's not true. so maybe the bug should be:

event not emited by '/etc/network/if-down.d/upstart'

muzzol (muzzol)
description: updated
muzzol (muzzol)
summary: - emmit signal when network-manager deconfigures interface
+ emit signal when network-manager deconfigures interface
summary: - emit signal when network-manager deconfigures interface
+ emit net-device-down signal when network-manager deconfigures interface
Revision history for this message
Clint Byrum (clint-fewbar) wrote : Re: [Bug 998388] Re: emmit signal when network-manager deconfigures interface

Excerpts from muzzol's message of Sat May 12 14:38:54 UTC 2012:
> ** Description changed:
>
> I want to execute a script when network (any interface) goes up and when
> goes down (with parameters).
>
> I've found easy to trigger first part with
>
> - start on (net-device-up IFACE!=lo)
> +     start on (net-device-up IFACE!=lo)
>
> but didn't manage to found an easy way to trigger either net-device-
> down, net-device-remove(d) , deconfiguring-networking
> -
>
> my job loks like this:
>
> ##################################################################
> description "network test"
>
> start on (net-device-up IFACE!=lo)
> # stop on ((net-device-down IFACE!=lo) or deconfiguring-networking)
> stop on net-device-removed IFACE!=lo
>
> pre-start exec /opt/test.sh start "$UPSTART_JOB - EVENT:
> $UPSTART_EVENTS"
>
> post-stop exec /opt/test.sh stop "$UPSTART_JOB - EVENT:
> $UPSTART_STOP_EVENTS"
>

net-device-down should be emitted whenever an interface goes down:

$ cat !$
cat /etc/network/if-down.d/upstart
#!/bin/sh

set -e

initctl emit -n net-device-down \
    "IFACE=$IFACE" \
    "LOGICAL=$LOGICAL" \
    "ADDRFAM=$ADDRFAM" \
    "METHOD=$METHOD"

Revision history for this message
muzzol (muzzol) wrote :

in my case it doesn't.

I tried with a fresh install of 12.04 and some other machines.

can't you reproduce it?

Revision history for this message
muzzol (muzzol) wrote :

I can confirm that '/etc/network/if-down.d/upstart' is NOT executed when any interface is down.

I've added a simple test line to test it:

       echo "`date` - $0 - $IFACE - $METHOD" >> "/tmp/upstart.log"

and no file is created.

I've also found a workaround, if I create a link in '/etc/network/if-post-down.d/' it works. so for now, if anyone is interested, you can execute

     ln -s /etc/network/if-down.d/upstart /etc/network/if-post-down.d/upstart

and you'll get desired behaviour.

I'm still waiting for some dev to confirm this bug

Revision history for this message
Steve Langasek (vorlon) wrote :

The script does work; this seems to be a problem with NetworkManager not invoking the if-down .d scripts as expected.

affects: upstart → network-manager (Ubuntu)
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in network-manager (Ubuntu):
status: New → Confirmed
Revision history for this message
Michael Jonker (citizen-jonker) wrote :

Can confirm that workaround in #3 works for me as well

Revision history for this message
user (meta1729-deactivatedaccount) wrote :

Present in 14.04 as well.
Following workaround works.
$ ln -s /etc/network/if-down.d/upstart /etc/network/if-post-down.d/upstart

Suggestion to upstart developers: Why not move the upstart script from if-down.d/ to if-post-down.d/ dir?

Revision history for this message
Istvan (bergkatten) wrote :

2015 the bug is still there in Ubuntu 14.04.3.

Revision history for this message
Robert Rößler (r-roessler) wrote :

Still there in Ubuntu Ubuntu 14.04.5 LTS. With workaround signal pops up in upstart-monitor.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.