[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: Looking for simple ifplugd example script
From:       Denys Vlasenko <vda.linux () googlemail ! com>
Date:       2014-02-21 20:20:56
Message-ID: CAK1hOcMSih=Sy=2nHbhNuwbwUkEGF9SkPcybA3LHtXOXdiG3wA () mail ! gmail ! com
[Download RAW message or body]

On Fri, Feb 21, 2014 at 5:43 PM, Bryan Evenson <bevenson@melinkcorp.com> wrote:
> A copy of examples/var_service/nmeter/README in examples/var_service/ifplugd_if/ \
> would be helpful.  In my searches for examples on how to use ifplugd, everything I \
> found said "see /etc/default/ifplugd for example usage", which I didn't have.  I'm \
> unfamiliar with runsvdir, so I didn't know "run" was the file that called ifplugd.  \
> So the example in run is as follows: 
> ifplugd -apqns -t3 -u8 -d8 -i "$if" -r "$pwd/ifplugd_handler"
> 
> I'm trying to get a better understanding as to what this command does and how it'd \
> apply to my setup if I wanted to use it in an init script with sysVinit.  Following \
> the setup from the other init scripts in my system, I would be using \
> start-stop-daemon to start ifplugd.  And as far as right now, forget what I'd \
> mentioned before about the static IP address; first step is just getting the system \
> to re-attempt DHCP when someone plugs in the Ethernet cable. 
> Based on how I'm assuming I would need to call ifplugd from a sysVinit script, here \
> is the script I have as a starting point: 
> #! /bin/sh
> #
> # ifplugd  init.d script
> test  -x /usr/bin/ifplugd || exit 0
> 
> #Functions to do individual actions
> startdaemon(){
> # Start the application
> echo -n "Starting ifplugd: "
> start-stop-daemon --start --quiet --background --exec /usr/bin/ifplugd -- "-apq -t3 \
> -u8 -d8 -i eth0 -r /etc/udhcpc.d/50default"

Not that direct.  /etc/udhcpc.d/50default is probably not expecting
to be used like that.

See examples/var_service/ifplugd_if/ifplugd_handler. It says:

#!/bin/sh
# parameters:
# $1: interface
# $2: state
if test -d "/var/service/dhcp_$1"; then
        if test x"$2" = x"down"; then
            ...what to do if link disappeared...
        fi
        if test x"$2" = x"up"; then
            ...what to do if link appeared (or was 'on' at start)...
        fi
fi

Decide what needs to be in those two if blocks for your system.
Do you need to run /etc/udhcpc.d/50default? In both cases?
With some params? (E.g. how do you tell your system
"restart udhcpc for interface $1"? Your current script
clearly fails to take into account interface name).

> Basically, start ifplugd and let it call udhcpc if ifplugd detects a change in the \
> link.  My startup says that its calling this script, and I can call  \
> "/etc/init.d/ifplugd start" on the command line and I don't see any complaints.

ifplugd won't call its script with $1="start".
It runs its script with $1="ethN" and $2="up"/"down".
You need a shim to translate that into  "/etc/init.d/ifplugd start"
and (I'm guessing)  "/etc/init.d/ifplugd stop"

> However, I don't see ifplugd in my running process list; for some reason the daemon \
> isn't running (or, maybe it starts but fails for some reason).  I also don't see \
> any message related to ifplugd in my system log.  Are there some arguments I got \
> wrong in the call to ifplugd?

Try to run in from command line, and see what it says.


> > > If not ifup, what would you suggest?  I'm open to ideas, just looking
> > > for the simplest path to get to where I want to go.
> > 
> > The very simplest path wouldn't work: you can't design your networking for a
> > single wired ethernet with static address or DHCP, and then start bolting on
> > hacks to make it work with wifi, more than one interface, vpn's, dynamic
> > firewalling etc. It would be a horrifying mess.
> > I went through that path already.
> > 
> 
> Agreed, trying to do all that with either a static IP address or with DHCP would be \
> a horrifying mess.  I'm not looking for something that complicated.  We have one \
> Ethernet port on our board, and there are instances that we would want to direct \
> connect a laptop to the board for pulling data off of the board, etc.  My thought \
> would be the easiest way to do that would be to just have it use a known static IP \
> address if DHCP failed.  We do have a secondary static IP address right now that is \
> live all the time at eth0:0, but we want to get away from that for some of the \
> reasons you mentioned. 
> So back to my original question: assuming I use ifplugd in a sysVinit for \
> automatically starting DHCP when someone plugs in the Ethernet cable (and I get \
> that working), is there a good way with ifplugd (or udhcpc for that matter) to set \
> a static IP address if DHCP fails?

udhcpc runs its -s SCRIPT with $1="leasefail" when it fails to get a lease.
You can hook on that.
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic