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