udev rules to turn networkmanager on and off?

Matt Price matt.price-H217xnMUJC0sA/PxXw9srA at public.gmane.org
Sun Jan 7 06:06:17 UTC 2007


Hi,

I have a tablet (compaq tc1000) with a flaky atmel wireless card that
cuts out about once a day.  When that happens, I can't get the carad to
start back up again without rebooting, and sometimes even that doesn't
work.  

Foretunately I have a prism2_usb wireless device that I can just plug in
to the ocmputer when that happens.  The device works fine but doesn't
play with network-manager proerly -- n-m sees it, but isn't able to
identify networks to which it might connect.

The solution isn't so difficult -- I just stop n0m with (in ubuntu):

sudo /etc/dbus-1/event.d/25NetworkManager stop
ifup wlan0

where wlan0 is configured thus in /etc/network/interfaces:

iface wlan0 inet dhcp
wireless-mode managed

since I have an unsecured network that's enough to get the thing to
connect.

However, this tablet is used mostly by my daughter who uses it largely
to surf the internet.  Itwould be great if she could use it as much as
possible without the usb device connected, and THEN have the device
brought up automatically, and network-manager stopped, when the device
is plugged in.  It would be great if network-manager could be restarted
when the device is pulled out, too.  

I have a dumb little script that does what I want: 

#!/bin/sh

case "$1" in
    start)

	/etc/dbus-1/event.d/25NetworkManager stop
	ifup wlan0
    ;;
    stop)
        ifdown wlan0
	/etc/dbus-1/event.d/25NetworkManager start
    ;;
  force-reload|restart)
    $0 stop
    $0 start
    ;;
  *)
    echo "Usage: /usr/local/scripts/usb_wireless {start|stop|restart|
force-reload}"
    exit 1
    ;;
esac

exit 0

----------------



this works fine for me, but I'd like to have this script triggered
automagically by udev or something.  I was just wondering whether there
was an obvious way to do this through udev; or if maybe there's also a
better way to do it.  

I did try this in udev (using the udev rule that comes with the ubuntu
linux-wlan-ng package).  The first rule in the bunch is the default
rule, the second is my first unsuccessful try, the third is my second
unsuccessful try... :
#SUBSYSTEM=="net", ACTION=="add", ENV{PHYSDEVDRIVER}=="prism2_usb", RUN+="/bin/sh -c '/sbin/wlanctl-ng $env{INTERFACE} lnxreq_ifstate ifstate=enable && sleep 3 && dbus-send --system /org/freedesktop/NetworkM
anager org.freedesktop.NetworkManager.RefreshDevice string:$env{INTERFACE}'"
#SUBSYSTEM=="net", ACTION=="add", ENV{PHYSDEVDRIVER}=="prism2_usb", RUN+="/bin/sh -c '/sbin/wlanctl-ng $env{INTERFACE} lnxreq_ifstate ifstate=enable && sleep 3 && /etc/dbus-1/event.d/25NetworkManager stop &&
 ifup  string:$env{INTERFACE}'"
SUBSYSTEM=="net", ACTION=="add", ENV{PHYSDEVDRIVER}=="prism2_usb", RUN+="/bin/sh -c '/sbin/wlanctl-ng $env{INTERFACE} lnxreq_ifstate ifstate=enable && sleep 3 && /etc/dbus-1/event.d/25NetworkManager stop && 
ifup  %k'"


anyway I seem to be missing something so if anyone knows what it is I'd be right obliged...

thanks,

matt



anyway htanks,

matt



-- 
Matt Price
History Dept
University of Toronto
matt.price-H217xnMUJC0sA/PxXw9srA at public.gmane.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://gtalug.org/pipermail/legacy/attachments/20070107/2ada6160/attachment.sig>


More information about the Legacy mailing list