1 #!/sbin/sh
   2 # CDDL HEADER START
   3 #
   4 # The contents of this file are subject to the terms of the
   5 # Common Development and Distribution License (the "License").
   6 # You may not use this file except in compliance with the License.
   7 #
   8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9 # or http://www.opensolaris.org/os/licensing.
  10 # See the License for the specific language governing permissions
  11 # and limitations under the License.
  12 #
  13 # When distributing Covered Code, include this CDDL HEADER in each
  14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15 # If applicable, add the following below this CDDL HEADER, with the
  16 # fields enclosed by brackets "[]" replaced with your own identifying
  17 # information: Portions Copyright [yyyy] [name of copyright owner]
  18 #
  19 # CDDL HEADER END
  20 #
  21 #
  22 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23 # Use is subject to license terms.
  24 #
  25 
  26 [ ! -d /usr/sbin -o ! -d /usr/bin ] && exit
  27 
  28 # Constants
  29 
  30 SVBOOT=/usr/sbin/svboot
  31 SVCS=/usr/bin/svcs
  32 DSCFG_DEPEND_NOCHK="/tmp/.dscfgadm_pid"
  33 OS_MINOR=`/usr/bin/uname -r | /usr/bin/cut -d '.' -f2`
  34 
  35 . /lib/svc/share/smf_include.sh
  36 
  37 # Make sure prior SMF dependents are not 'online'
  38 # $1 = name of SMF service to validate dependents
  39 #
  40 do_smf_depends ()
  41 {
  42   times=0
  43   count=1
  44 
  45   if [ $OS_MINOR -ge 11 ]
  46   then
  47         return 0
  48   elif [ -f $DSCFG_DEPEND_NOCHK ]
  49   then
  50         for pid in `pgrep dscfgadm`
  51         do
  52                 if [ `grep -c $pid $DSCFG_DEPEND_NOCHK` -gt 0 ]
  53                 then
  54                         return 0
  55                 fi
  56         done
  57   elif [ `ps -ef | grep preremove | grep -c SUNWspsvu` -gt 0 ]
  58   then
  59         return 0
  60 
  61   fi
  62 
  63 
  64   while [ $count -ne 0 ]
  65   do
  66     count=`$SVCS -o STATE -D $1 2>>/dev/null | grep "^online" | wc -l`
  67     if [ $count -ne 0 ]
  68     then
  69       # Output banner after waiting first 5 seconds
  70       #
  71       if [ $times -eq 1 ]
  72       then
  73         echo "Waiting for $1 dependents to be 'offline'"
  74         $SVCS -D $1 2>>/dev/null | grep "^online"
  75       fi
  76 
  77       # Has it been longer then 5 minutes? (60 * 5 secs.)
  78       #
  79       if [ $times -eq 60 ]
  80       then
  81           echo "Error: Failed waiting for $1 dependents to be 'offline'"
  82           $SVCS -D $1 2>>/dev/null | grep "^online"
  83           exit $SMF_EXIT_ERR_FATAL
  84       fi
  85 
  86       # Now sleep, giving other services time to stop
  87       #
  88       sleep 5
  89       times=`expr $times + 1`
  90     fi
  91   done
  92   return 0
  93 }
  94 
  95 # main program
  96 
  97 if [ ! -x $SVBOOT ]
  98 then
  99         echo "$0: cannot find $SVBOOT"
 100         exit $SMF_EXIT_MON_OFFLINE
 101 fi
 102 
 103 case "$1" in
 104 'start')
 105 
 106         $SVBOOT -r
 107         ;;
 108 
 109 'stop')
 110 
 111         do_smf_depends "system/nws_sv"
 112 
 113         $SVBOOT -s
 114         ;;
 115 
 116 *)
 117         echo "Usage: $0 { start | stop }"
 118         exit $SMF_EXIT_MON_OFFLINE
 119         ;;
 120 esac
 121 
 122 exit $SMF_EXIT_OK