DIP questions: setup, timeout and cleanup DIP process

DIP questions: setup, timeout and cleanup DIP process

Post by Joel M. Hoffm » Wed, 25 Oct 1995 04:00:00




>  I am using DIP to connect to my slip account. I want to setup
>DIP as transparent as possible, say, I can invoke DIP whenever  a network
>program is launched. Then I would like to kill the DIP process whenever
>the connection has idle time more than some certain amount, say 10 minutes.
>  Since I have several users having cron jobs involving the DIP, I
>would like to let each user has the ability to kill the DIP process
>launched by others in the case of timeout is reached.

I did exactly this with "term," but with PPP it's a bit more
difficult.  The basic idea is to move all network programs to a
special directory (say /usr/local/network-bin), and then write a shell
script along the lines of:

  #!/bin/bash
  # run any network program -- call this ppp.any
  #
  WHATAMI=`basename $0`
  if [ -f /etc/ppp.is.up]
    /usr/local/network-bin/$WHATAMI
  else
    echo $0:  waiting for PPP connection....
    bring-PPP-up
    /usr/local/network-bin/$WHATAMI
  fi
  # end of ppp.any

Put ppp.any in /usr/local/network-bin, and then link ppp.any to each
real network program (e.g., "ln /usr/local/network-bin/ppp.any
/usr/bin/telnet").  You'll also have to write a script for
"bring-PPP-up," which probably invokes dip.  With this setup, when you
run, say, /usr/bin/netscape, you are really running the above script,
which checks to make sure the PPP link is up, and then runs the real
netscape.

To bring the PPP link down after a certain delay, you need a watchdog
daemon that monitors the output of /proc/net/dev, specifially, the
ppp0 line.  Something like:

  #!/bin/bash
  #watchdog daemon for PPP.  Run this from bring-PPP-up

  TIMEOUT=540 # 9 minutes

  LASTPPP="dummy"
  while : ; do
    sleep 60 # the maximum idle time is roughly $TIMEOUT + 60
    #get the current time
    NOW=`cut -f1 -d" " < /dev/uptime | cut -f1 -d.`
    #if no ppp stats have changed...
    if test "$LASTPPP" == "`grep ppp0 < /proc/net/dev`" ; then
      #...and $TIMEOUT minutes have passed, then:
      if test $[$NOW-$THEN] -gt $TIMEOUT ; then
        kill-ppp #write a script to do this
      fi
    else
      #store the time and the ppp stats
      THEN=`grep ppp0 < /proc/net/dev`
      LASTPPP="`grep ppp0 < /proc/net/dev`"
    fi
  done
  #end of watchdog daemon

One problem with this is that it only watches for PPP activity.  So if
you have a dozen xterms open on a remote host, with lots of
interesting things happening, but you leave for 10 minutes, you lose.
A second problem is that some programs are both local and network
programs, like "telnet."  You will need a "telnet" and a
"local-telnet," the latter just runs /usr/local/network-bin/telnet

The third problem is one of care of implementation.  You need to make
sure that you don't have two users trying to bring ppp up at the same
time, and you want to make sure that you don't have one person trying
to bring ppp up even as the daemon is killing ppp.  The way to do this
is via files such as /tmp/.ppp.is.coming.up, /tmp/.ppp.is.up, and so
forth.  To do this right is a bit tricky (see any book on concurrent
programming and semaphores), but to do it almost right is a piece of
cake.

Don't forget to write a script that restarts everything.  Sooner or
later, your modem connection will hang, so you'll want to make sure
you have a "kill-ppp-for-real" that not only over-rides bring-PPP-up
but also takes care of anything that might be wrong.  It should kill
pppd, reset the indicator files (ppp.is.up etc.), reset any
semaphores, and so on.  (And, if you're a stickler for details, don't
forget to make sure that no one can bring up ppp even as you're
killing it for real.)

Finally, it has come to my attention that my news reader, when I post,
sometimes mangles programs and mis-spells words that I have spelled
correctly.  You may have to adjust for that.... :-)

-Joel

--
-----------------------------------------------------------------------------
|_|~~ Germany, Europe. 1940's ``A DISTINGUISHED speaker said that we must put
__|~| 16 Million DEAD.          our children first.   We in Bosnia wonder  if
                                we have any children left. Seven* thousand
 cnc  Bosnia, Europe. 1990's    children  have been killed  in Bosnia in  the
 cnc  HOW MANY MORE?            last three  years.   Those living, some  with
                                gray hair and eyes and hearts of old men, are
``May the world you             hardly children any more.''
  live in be the world                             - H. Silajdzic
  of your dreams.'' - Debbie Friedman                Prime Minister of Bosnia
-----------------------------------------------------------------------------

 
 
 

1. dip dip dip

I'm trying to beat the system by making my mouse and dip connection work
on my new linux installation.

I have a 2-button mouse. When I run startx my mouse is dead under the
"Microsoft" setting in Xconfig. I've read that "gpm" may be necessary, but
I may just buy a cheap 3-button.

I seem to be very close on my dynamic dip connection, but after the login
I don't seem to get the right $remote and $host values. I'm using the
example in "running linux" for my *.dip chat script. There has got to be
some little error in my "/etc/hosts" or "/etc/diphosts" files.

Can anyone work with me? I've read through the manuals and tried all the
combinations but I'm really stuck now. Thanks very much.

..............................................................................
Daniel A. Washburn

..............................................................................

2. setting hostname with net-2

3. Dip vs Dip-uri, which one should I use?

4. DLPAR -- getting errors

5. DIP (can someone give me dip ex.script

6. boot: ramdisk error

7. Dip needs help with dip

8. GO2CALL problems behind firewall

9. DIP: dip -k leaves modem in funny state?

10. dip-3.3.7n-inaky DIP: tty_login cannot TIOCSCTTY: ???

11. DIP problem: DIP creates bad lock file

12. DIP-3.3.7-uri (was Re: Bizzare DIP/CSLIP problem

13. Dip dies "DIP must never be here!!"