1 #!/sbin/sh
   2 #
   3 # CDDL HEADER START
   4 #
   5 # The contents of this file are subject to the terms of the
   6 # Common Development and Distribution License (the "License").
   7 # You may not use this file except in compliance with the License.
   8 #
   9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10 # or http://www.opensolaris.org/os/licensing.
  11 # See the License for the specific language governing permissions
  12 # and limitations under the License.
  13 #
  14 # When distributing Covered Code, include this CDDL HEADER in each
  15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16 # If applicable, add the following below this CDDL HEADER, with the
  17 # fields enclosed by brackets "[]" replaced with your own identifying
  18 # information: Portions Copyright [yyyy] [name of copyright owner]
  19 #
  20 # CDDL HEADER END
  21 #
  22 #
  23 # Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  24 # Use is subject to license terms.
  25 #
  26 #
  27 
  28 #
  29 # Start script for the SPARC-Enterprise DSCP service.
  30 #
  31 
  32 . /lib/svc/share/smf_include.sh
  33 
  34 OPL=SUNW,SPARC-Enterprise
  35 OPL_LIB=/usr/platform/${OPL}/lib
  36 DM2S_DEVICE=/dev/dm2s0
  37 PPP_OPTIONS=${OPL_LIB}/dscp.ppp.options
  38 DSCP_IFNAME=/var/run/dscp.ifname
  39 PRTDSCP=/usr/platform/${OPL}/sbin/prtdscp
  40 PLATFORM=`/sbin/uname -i`
  41 SLEEP=/bin/sleep
  42 PKILL=/bin/pkill
  43 
  44 LD_LIBRARY_PATH=/lib:${OPL_LIB}; export LD_LIBRARY_PATH
  45 
  46 # This service can only run on OPL.
  47 if  [ "${PLATFORM}" != "${OPL}" ]; then
  48         exit $SMF_EXIT_ERR_CONFIG
  49 fi
  50 
  51 case "$1" in
  52 'start')
  53 
  54         if [ ! -x /usr/bin/pppd ]; then
  55                 exit $SMF_EXIT_ERR_CONFIG
  56         fi
  57 
  58         if [ ! -c $DM2S_DEVICE ]; then
  59                 exit $SMF_EXIT_ERR_CONFIG
  60         fi
  61 
  62         if [ ! -f $PPP_OPTIONS ]; then
  63                 exit $SMF_EXIT_ERR_CONFIG
  64         fi
  65                 
  66         SUCCESS=0
  67         for UNIT in 0 1 2 3 4 5 6 7 8 9; do
  68                 /usr/bin/pppd $DM2S_DEVICE unit $UNIT file $PPP_OPTIONS
  69                 if [ ! "$?" = "1" ]; then
  70                         echo "sppp$UNIT" > $DSCP_IFNAME
  71                         SUCCESS=1
  72                         break
  73                 fi
  74         done
  75 
  76         if [ $SUCCESS -ne 1 ]; then
  77                 exit $SMF_EXIT_ERR_FATAL
  78         fi
  79 
  80         # Wait for the DSCP link to come up, but only for 30 seconds
  81         for RETRY in 0 1 2 3 4 5; do
  82                 ${PRTDSCP} >/dev/null 2>&1
  83                 if [ $? -eq 0 ]; then
  84                         exit $SMF_EXIT_OK
  85                 fi
  86                 ${SLEEP} 5
  87         done
  88         
  89         # Stop pppd before we return failure
  90         ${PKILL} -TERM -f "pppd ${DM2S_DEVICE}"
  91         ${SLEEP} 1
  92         ${PKILL} -KILL -f "pppd ${DM2S_DEVICE}"
  93         rm -f $DSCP_IFNAME
  94         exit $SMF_EXIT_ERR_FATAL
  95         ;;
  96 
  97 'stop')
  98         # First try SIGTERM and then SIGKILL
  99         ${PKILL} -TERM -f "pppd ${DM2S_DEVICE}"
 100         ${SLEEP} 1
 101         ${PKILL} -KILL -f "pppd ${DM2S_DEVICE}"
 102         rm -f $DSCP_IFNAME
 103         exit $SMF_EXIT_OK
 104         ;;
 105 esac