1 #!/bin/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 CMD=/usr/sbin/iiboot
  26 IIADM=/usr/sbin/iiadm
  27 SVCS=/usr/bin/svcs
  28 DSCFG_DEPEND_NOCHK="/tmp/.dscfgadm_pid"
  29 OS_MINOR=`/usr/bin/uname -r | /usr/bin/cut -d '.' -f2`
  30 
  31 . /lib/svc/share/smf_include.sh
  32 
  33 # Make sure prior SMF dependents are not 'online'
  34 # $1 = name of SMF service to validate dependents
  35 #
  36 do_smf_depends ()
  37 {
  38   times=0
  39   count=1
  40   
  41   if [ $OS_MINOR -ge 11 ]
  42   then
  43         return 0
  44   elif [ -f $DSCFG_DEPEND_NOCHK ]
  45   then
  46         for pid in `pgrep dscfgadm`
  47         do
  48                 if [ `grep -c $pid $DSCFG_DEPEND_NOCHK` -gt 0 ]
  49                 then
  50                         return 0
  51                 fi
  52         done
  53   elif [ `ps -ef | grep preremove | grep -c SUNWiiu` -gt 0 ]
  54   then
  55         return 0
  56 
  57   fi
  58 
  59   while [ $count -ne 0 ]
  60   do
  61     count=`$SVCS -o STATE -D $1 2>>/dev/null | grep "^online" | wc -l`
  62     if [ $count -ne 0 ]
  63     then
  64       # Output banner after waiting first 5 seconds
  65       #
  66       if [ $times -eq 1 ]
  67       then
  68         echo "Waiting for $1 dependents to be 'offline'"
  69         $SVCS -D $1 2>>/dev/null | grep "^online"
  70       fi
  71 
  72       # Has it been longer then 5 minutes? (60 * 5 secs.)
  73       #
  74       if [ $times -eq 60 ]
  75       then
  76           echo "Error: Failed waiting for $1 dependents to be 'offline'"
  77           $SVCS -D $1 2>>/dev/null | grep "^online"
  78           exit $SMF_EXIT_ERR_FATAL
  79       fi
  80 
  81       # Now sleep, giving other services time to stop
  82       #
  83       sleep 5
  84       times=`expr $times + 1`
  85     fi
  86   done
  87   return 0
  88 }
  89 
  90 
  91 CLINFO=/usr/sbin/clinfo
  92 
  93 rc=0
  94 
  95 case $1 in
  96 'start')
  97 
  98         COPT=
  99 
 100         if [ -x ${CMD} ]
 101         then
 102                 if ${CLINFO}
 103                 then
 104                         # in cluster - look for local volumes only
 105                         COPT="-C -"
 106                 fi
 107 
 108                 ${CMD} $COPT -r > /dev/null 2>&1
 109                 rc=$?
 110         fi
 111         ;;
 112 'stop')
 113         if [ ! -r /dev/ii ]
 114         then
 115                 exit $SMF_EXIT_OK
 116         fi
 117 
 118         do_smf_depends "system/nws_ii"
 119 
 120         COPT=
 121 
 122         if [ -x ${CMD} ]
 123         then
 124                 if ${CLINFO}
 125                 then
 126                         # in cluster - look for local volumes only
 127                         COPT="-C -"
 128                 fi
 129 
 130                 ${CMD} $COPT -s > /dev/null 2>&1
 131                 rc=$?
 132         fi
 133         ;;
 134 *)
 135         echo "usage: /etc/init.d/ii {start|stop} "
 136         exit 1
 137         ;;
 138 esac
 139 if [ $rc -ne 0 ]
 140 then
 141         exit $SMF_MON_OFFLINE
 142 else
 143         exit $SMF_EXIT_OK
 144 fi