1#!/bin/sh 2# @configure_input@ 3#*********************************************************************** 4# 5# pppoe-stop 6# 7# Shell script to bring down a PPPoE connection 8# 9# Copyright (C) 2000 Roaring Penguin Software Inc. 10# 11# $Id$ 12# 13# This file may be distributed under the terms of the GNU General 14# Public License. 15# 16# LIC: GPL 17# 18# Usage: pppoe-stop [config_file] 19# If config_file is omitted, defaults to /etc/ppp/pppoe.conf 20# 21#*********************************************************************** 22 23# Set to "C" locale so we can parse messages from commands 24LANG=C 25export LANG 26 27ME="`basename $0`" 28LOGGER="/usr/bin/logger -t $ME" 29CONFIG="$1" 30if [ "$CONFIG" = "" ] ; then 31 CONFIG=/etc/ppp/pppoe.conf 32fi 33 34if [ ! -f "$CONFIG" -o ! -r "$CONFIG" ] ; then 35 echo "$ME: Cannot read configuration file '$CONFIG'" >& 2 36 exit 1 37fi 38export CONFIG 39. $CONFIG 40 41PPPOE_PIDFILE="$PIDFILE.pppoe" 42PPPD_PIDFILE="$PIDFILE.pppd" 43STARTPID="$PIDFILE.start" 44 45# Backward config file compatibility 46if test "$DEMAND" = "" ; then 47 DEMAND=no 48fi 49 50# Ignore SIGTERM 51trap "" 15 52 53# Check for pidfile 54if [ -r "$PIDFILE" ] ; then 55 PID=`cat $PIDFILE` 56 57 # Check if still running 58 kill -0 $PID > /dev/null 2>&1 59 if [ $? != 0 ] ; then 60 echo "$ME: The pppoe-connect script (PID $PID) appears to have died" >& 2 61 fi 62 63 # Kill pppd, which should in turn kill pppoe 64 if [ -r "$PPPD_PIDFILE" ] ; then 65 PPPD_PID=`cat "$PPPD_PIDFILE"` 66 $LOGGER -p daemon.notice "Killing pppd" 67 echo "Killing pppd ($PPPD_PID)" 68 kill $PPPD_PID > /dev/null 2>&1 || exit 1 69 fi 70 71 # Kill pppoe-start 72 PIDS=`cat $STARTPID` 73 kill -0 $PIDS > /dev/null 2>&1 74 if [ $? = 0 ] ; then 75 $LOGGER -p daemon.notice "Killing pppoe-connect" 76 kill $PIDS > /dev/null 2>&1 77 fi 78 79 # Kill pppoe-connect 80 $LOGGER -p daemon.notice "Killing pppoe-connect" 81 echo "Killing pppoe-connect ($PID)" 82 kill -9 $PID > /dev/null 2>&1 83 84 # Kill pppd again, in case it's still hanging around 85 if [ -r "$PPPD_PIDFILE" ] ; then 86 PPPD_PID=`cat "$PPPD_PIDFILE"` 87 kill -9 $PPPD_PID > /dev/null 2>&1 || exit 1 88 fi 89 90 rm -f "$PIDFILE" "$PPPD_PIDFILE" "$PPPOE_PIDFILE" "$STARTPID" 91else 92 echo "$ME: No PPPoE connection appears to be running" >&2 93 exit 1 94fi 95 96exit 0 97