#!/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
respawn_flag=/tmp/ppp_respawn.flag
if [ -e $respawn_flag ] ; then
 echo "Another $0 is running."
 exit 0
else
touch $respawn_flag
if [ ! -e /var/run/ppp0.pid ] ; then
echo "Seem we're not running pppd.. Respawning."
clock >> /var/log/ppp_respawn.log
killall -HUP pppd >/dev/null
sleep 3
killall -9 pppd   >/dev/null
rm -f /var/run/ppp*
rm -f /var/lock/LCK..ttyS1
/usr/sbin/pppd /dev/ttyS1 57600 file /etc/ppp/options.ttyS1 >/dev/null 2>/dev/null 3>/dev/null &
ifconfig ppp0 195.218.173.129 pointopoint 195.218.173.226 netmask 255.255.255.255 up
/sbin/route add default ppp0
rm -f $respawn_flag
if [ ! -e /var/run/ppp0.pid ] ; then
echo "Seem pppd made braindead idea that it must wake up ppp1 w/ ppp0 params."
 if [ ! -e /var/run/reboot ] ; then
  touch /var/run/reboot
  echo "Rebooting once.. "
  echo "(Created /var/run/reboot. No more reboot unless file exist.)"
  init 6
 fi
fi
exit 0
fi
ppp_pid=`cat /var/run/ppp0.pid`
if [ ! `kill -CONT $ppp_pid >/dev/null 2>&1` ] ; then 
# kill -CONT on running PID gives exit status = 0 
    rm -f $respawn_flag
    exit 0
else
echo "Seem we're not running pppd.. Respawning."
clock >> /var/log/ppp_respawn.log
killall -HUP pppd >/dev/null
sleep 3
killall -9 pppd   >/dev/null
rm -f /var/run/ppp*
rm -f /var/lock/LCK..ttyS1
/usr/sbin/pppd /dev/ttyS1 57600 file /etc/ppp/options.ttyS1 >/dev/null 2>/dev/null 3>/dev/null &
rm -f $respawn_flag
exit 0
fi
fi
exit 0
