xref: /onnv-gate/usr/src/cmd/avs/rdc/etc/rdc.sh (revision 7836:4e95154b5b7a)
1*7836SJohn.Forte@Sun.COM#!/bin/sh
2*7836SJohn.Forte@Sun.COM# CDDL HEADER START
3*7836SJohn.Forte@Sun.COM#
4*7836SJohn.Forte@Sun.COM# The contents of this file are subject to the terms of the
5*7836SJohn.Forte@Sun.COM# Common Development and Distribution License (the "License").
6*7836SJohn.Forte@Sun.COM# You may not use this file except in compliance with the License.
7*7836SJohn.Forte@Sun.COM#
8*7836SJohn.Forte@Sun.COM# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*7836SJohn.Forte@Sun.COM# or http://www.opensolaris.org/os/licensing.
10*7836SJohn.Forte@Sun.COM# See the License for the specific language governing permissions
11*7836SJohn.Forte@Sun.COM# and limitations under the License.
12*7836SJohn.Forte@Sun.COM#
13*7836SJohn.Forte@Sun.COM# When distributing Covered Code, include this CDDL HEADER in each
14*7836SJohn.Forte@Sun.COM# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*7836SJohn.Forte@Sun.COM# If applicable, add the following below this CDDL HEADER, with the
16*7836SJohn.Forte@Sun.COM# fields enclosed by brackets "[]" replaced with your own identifying
17*7836SJohn.Forte@Sun.COM# information: Portions Copyright [yyyy] [name of copyright owner]
18*7836SJohn.Forte@Sun.COM#
19*7836SJohn.Forte@Sun.COM# CDDL HEADER END
20*7836SJohn.Forte@Sun.COM#
21*7836SJohn.Forte@Sun.COM#
22*7836SJohn.Forte@Sun.COM# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23*7836SJohn.Forte@Sun.COM# Use is subject to license terms.
24*7836SJohn.Forte@Sun.COM#
25*7836SJohn.Forte@Sun.COM# SNDR start script
26*7836SJohn.Forte@Sun.COM#
27*7836SJohn.Forte@Sun.COM# Description:	This is the SNDR start script. It must be located
28*7836SJohn.Forte@Sun.COM#		in /etc/init.d with links to the appropriate rc2.d and
29*7836SJohn.Forte@Sun.COM#		rc0.d files.
30*7836SJohn.Forte@Sun.COM#		It can also be used to start or stop a specified cluster
31*7836SJohn.Forte@Sun.COM#		resource group when invoked from the data service cluster
32*7836SJohn.Forte@Sun.COM#		failover script.
33*7836SJohn.Forte@Sun.COM#
34*7836SJohn.Forte@Sun.COM#
35*7836SJohn.Forte@Sun.COM#
36*7836SJohn.Forte@Sun.COMPATH=/etc:/bin
37*7836SJohn.Forte@Sun.COMRDCBOOT="/usr/sbin/sndrboot"
38*7836SJohn.Forte@Sun.COMUSAGE="Usage: $0 {start|stop} [cluster_resource]"
39*7836SJohn.Forte@Sun.COMSVCS=/usr/bin/svcs
40*7836SJohn.Forte@Sun.COMDSCFG_DEPEND_NOCHK="/tmp/.dscfgadm_pid"
41*7836SJohn.Forte@Sun.COMOS_MINOR=`/usr/bin/uname -r | /usr/bin/cut -d '.' -f2`
42*7836SJohn.Forte@Sun.COM
43*7836SJohn.Forte@Sun.COM. /lib/svc/share/smf_include.sh
44*7836SJohn.Forte@Sun.COM
45*7836SJohn.Forte@Sun.COM# Make sure prior SMF dependents are not 'online'
46*7836SJohn.Forte@Sun.COM# $1 = name of SMF service to validate dependents
47*7836SJohn.Forte@Sun.COM#
48*7836SJohn.Forte@Sun.COMdo_smf_depends ()
49*7836SJohn.Forte@Sun.COM{
50*7836SJohn.Forte@Sun.COM  times=0
51*7836SJohn.Forte@Sun.COM  count=1
52*7836SJohn.Forte@Sun.COM
53*7836SJohn.Forte@Sun.COM  if [ $OS_MINOR -ge 11 ]
54*7836SJohn.Forte@Sun.COM  then
55*7836SJohn.Forte@Sun.COM	return 0
56*7836SJohn.Forte@Sun.COM  elif [ -f $DSCFG_DEPEND_NOCHK ]
57*7836SJohn.Forte@Sun.COM  then
58*7836SJohn.Forte@Sun.COM	for pid in `pgrep dscfgadm`
59*7836SJohn.Forte@Sun.COM	do
60*7836SJohn.Forte@Sun.COM		if [ `grep -c $pid $DSCFG_DEPEND_NOCHK` -gt 0 ]
61*7836SJohn.Forte@Sun.COM		then
62*7836SJohn.Forte@Sun.COM			return 0
63*7836SJohn.Forte@Sun.COM		fi
64*7836SJohn.Forte@Sun.COM	done
65*7836SJohn.Forte@Sun.COM   elif [ `ps -ef | grep preremove | grep -c SUNWrdcu` -gt 0 ]
66*7836SJohn.Forte@Sun.COM   then
67*7836SJohn.Forte@Sun.COM 	return 0
68*7836SJohn.Forte@Sun.COM
69*7836SJohn.Forte@Sun.COM  fi
70*7836SJohn.Forte@Sun.COM
71*7836SJohn.Forte@Sun.COM  while [ $count -ne 0 ]
72*7836SJohn.Forte@Sun.COM  do
73*7836SJohn.Forte@Sun.COM    count=`$SVCS -o STATE -D $1 2>>/dev/null | grep "^online" | wc -l`
74*7836SJohn.Forte@Sun.COM    if [ $count -ne 0 ]
75*7836SJohn.Forte@Sun.COM    then
76*7836SJohn.Forte@Sun.COM      # Output banner after waiting first 5 seconds
77*7836SJohn.Forte@Sun.COM      #
78*7836SJohn.Forte@Sun.COM      if [ $times -eq 1 ]
79*7836SJohn.Forte@Sun.COM      then
80*7836SJohn.Forte@Sun.COM        echo "Waiting for $1 dependents to be 'offline'"
81*7836SJohn.Forte@Sun.COM        $SVCS -D $1 2>>/dev/null | grep "^online"
82*7836SJohn.Forte@Sun.COM      fi
83*7836SJohn.Forte@Sun.COM
84*7836SJohn.Forte@Sun.COM      # Has it been longer then 5 minutes? (60 * 5 secs.)
85*7836SJohn.Forte@Sun.COM      #
86*7836SJohn.Forte@Sun.COM      if [ $times -eq 60 ]
87*7836SJohn.Forte@Sun.COM      then
88*7836SJohn.Forte@Sun.COM          echo "Error: Failed waiting for $1 dependents to be 'offline'"
89*7836SJohn.Forte@Sun.COM          $SVCS -D $1 2>>/dev/null | grep "^online"
90*7836SJohn.Forte@Sun.COM	  exit $SMF_EXIT_ERR_FATAL
91*7836SJohn.Forte@Sun.COM      fi
92*7836SJohn.Forte@Sun.COM
93*7836SJohn.Forte@Sun.COM      # Now sleep, giving other services time to stop
94*7836SJohn.Forte@Sun.COM      #
95*7836SJohn.Forte@Sun.COM      sleep 5
96*7836SJohn.Forte@Sun.COM      times=`expr $times + 1`
97*7836SJohn.Forte@Sun.COM    fi
98*7836SJohn.Forte@Sun.COM  done
99*7836SJohn.Forte@Sun.COM  return 0
100*7836SJohn.Forte@Sun.COM}
101*7836SJohn.Forte@Sun.COM
102*7836SJohn.Forte@Sun.COMCLINFO=/usr/sbin/clinfo
103*7836SJohn.Forte@Sun.COM
104*7836SJohn.Forte@Sun.COMkillproc() {            # kill the named process(es)
105*7836SJohn.Forte@Sun.COM        pid=`/usr/bin/ps -e |
106*7836SJohn.Forte@Sun.COM             /usr/bin/grep -w $1 |
107*7836SJohn.Forte@Sun.COM             /usr/bin/sed -e 's/^  *//' -e 's/ .*//'`
108*7836SJohn.Forte@Sun.COM        [ "$pid" != "" ] && kill $pid
109*7836SJohn.Forte@Sun.COM}
110*7836SJohn.Forte@Sun.COM
111*7836SJohn.Forte@Sun.COM
112*7836SJohn.Forte@Sun.COMcase "$1" in
113*7836SJohn.Forte@Sun.COM'start')
114*7836SJohn.Forte@Sun.COM	COPT=
115*7836SJohn.Forte@Sun.COM
116*7836SJohn.Forte@Sun.COM	if [ -x ${RDCBOOT} ]
117*7836SJohn.Forte@Sun.COM	then
118*7836SJohn.Forte@Sun.COM		if ${CLINFO}
119*7836SJohn.Forte@Sun.COM		then
120*7836SJohn.Forte@Sun.COM			if [ "$2" != "" ]
121*7836SJohn.Forte@Sun.COM			then
122*7836SJohn.Forte@Sun.COM	 			${RDCBOOT} -r -C $2
123*7836SJohn.Forte@Sun.COM			else
124*7836SJohn.Forte@Sun.COM				# SNDR 3.2 SetIDs fixup
125*7836SJohn.Forte@Sun.COM				${RDCBOOT} -C post-patch-setids -r -s
126*7836SJohn.Forte@Sun.COM
127*7836SJohn.Forte@Sun.COM				COPT="-C -"
128*7836SJohn.Forte@Sun.COM				${RDCBOOT} ${COPT} -r
129*7836SJohn.Forte@Sun.COM			fi
130*7836SJohn.Forte@Sun.COM		else
131*7836SJohn.Forte@Sun.COM			# non-clustered start
132*7836SJohn.Forte@Sun.COM			${RDCBOOT} -r
133*7836SJohn.Forte@Sun.COM		fi
134*7836SJohn.Forte@Sun.COM	fi
135*7836SJohn.Forte@Sun.COM	;;
136*7836SJohn.Forte@Sun.COM
137*7836SJohn.Forte@Sun.COM'stop')
138*7836SJohn.Forte@Sun.COM	COPT=
139*7836SJohn.Forte@Sun.COM
140*7836SJohn.Forte@Sun.COM	if [ ! -r /dev/rdc ]
141*7836SJohn.Forte@Sun.COM	then
142*7836SJohn.Forte@Sun.COM		RDCBOOT=/usr/bin/true
143*7836SJohn.Forte@Sun.COM	fi
144*7836SJohn.Forte@Sun.COM
145*7836SJohn.Forte@Sun.COM        do_smf_depends "system/nws_rdc"
146*7836SJohn.Forte@Sun.COM
147*7836SJohn.Forte@Sun.COM	if [ -x ${RDCBOOT} ]
148*7836SJohn.Forte@Sun.COM	then
149*7836SJohn.Forte@Sun.COM		if ${CLINFO}
150*7836SJohn.Forte@Sun.COM		then
151*7836SJohn.Forte@Sun.COM			if [ "$2" != "" ]
152*7836SJohn.Forte@Sun.COM			then
153*7836SJohn.Forte@Sun.COM				${RDCBOOT} -s -C $2
154*7836SJohn.Forte@Sun.COM			else
155*7836SJohn.Forte@Sun.COM				COPT="-C -"
156*7836SJohn.Forte@Sun.COM				${RDCBOOT} ${COPT} -s
157*7836SJohn.Forte@Sun.COM
158*7836SJohn.Forte@Sun.COM				echo "killing SNDR daemons"
159*7836SJohn.Forte@Sun.COM				killproc sndrd
160*7836SJohn.Forte@Sun.COM				killproc sndrsync
161*7836SJohn.Forte@Sun.COM			fi
162*7836SJohn.Forte@Sun.COM		else
163*7836SJohn.Forte@Sun.COM			# non-clustered stop
164*7836SJohn.Forte@Sun.COM
165*7836SJohn.Forte@Sun.COM			${RDCBOOT} -s
166*7836SJohn.Forte@Sun.COM
167*7836SJohn.Forte@Sun.COM			echo "killing SNDR daemons"
168*7836SJohn.Forte@Sun.COM			killproc sndrd
169*7836SJohn.Forte@Sun.COM			killproc sndrsync
170*7836SJohn.Forte@Sun.COM		fi
171*7836SJohn.Forte@Sun.COM	else
172*7836SJohn.Forte@Sun.COM		# no sndr boot command, kill daemon anyway
173*7836SJohn.Forte@Sun.COM
174*7836SJohn.Forte@Sun.COM		echo "killing SNDR daemons"
175*7836SJohn.Forte@Sun.COM		killproc sndrd
176*7836SJohn.Forte@Sun.COM		killproc sndrsync
177*7836SJohn.Forte@Sun.COM	fi
178*7836SJohn.Forte@Sun.COM
179*7836SJohn.Forte@Sun.COM	;;
180*7836SJohn.Forte@Sun.COM
181*7836SJohn.Forte@Sun.COM*)
182*7836SJohn.Forte@Sun.COM	echo $USAGE
183*7836SJohn.Forte@Sun.COM	exit 1
184*7836SJohn.Forte@Sun.COM	;;
185*7836SJohn.Forte@Sun.COMesac
186*7836SJohn.Forte@Sun.COMexit $SMF_EXIT_OK
187