xref: /titanic_41/usr/src/cmd/avs/rdc/etc/rdc.sh (revision 36e852a172cba914383d7341c988128b2c667fbd)
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# SNDR start script
26#
27# Description:	This is the SNDR start script. It must be located
28#		in /etc/init.d with links to the appropriate rc2.d and
29#		rc0.d files.
30#		It can also be used to start or stop a specified cluster
31#		resource group when invoked from the data service cluster
32#		failover script.
33#
34#
35#
36PATH=/etc:/bin
37RDCBOOT="/usr/sbin/sndrboot"
38USAGE="Usage: $0 {start|stop} [cluster_resource]"
39SVCS=/usr/bin/svcs
40DSCFG_DEPEND_NOCHK="/tmp/.dscfgadm_pid"
41OS_MINOR=`/usr/bin/uname -r | /usr/bin/cut -d '.' -f2`
42
43. /lib/svc/share/smf_include.sh
44
45# Make sure prior SMF dependents are not 'online'
46# $1 = name of SMF service to validate dependents
47#
48do_smf_depends ()
49{
50  times=0
51  count=1
52
53  if [ $OS_MINOR -ge 11 ]
54  then
55	return 0
56  elif [ -f $DSCFG_DEPEND_NOCHK ]
57  then
58	for pid in `pgrep dscfgadm`
59	do
60		if [ `grep -c $pid $DSCFG_DEPEND_NOCHK` -gt 0 ]
61		then
62			return 0
63		fi
64	done
65   elif [ `ps -ef | grep preremove | grep -c SUNWrdcu` -gt 0 ]
66   then
67 	return 0
68
69  fi
70
71  while [ $count -ne 0 ]
72  do
73    count=`$SVCS -o STATE -D $1 2>>/dev/null | grep "^online" | wc -l`
74    if [ $count -ne 0 ]
75    then
76      # Output banner after waiting first 5 seconds
77      #
78      if [ $times -eq 1 ]
79      then
80        echo "Waiting for $1 dependents to be 'offline'"
81        $SVCS -D $1 2>>/dev/null | grep "^online"
82      fi
83
84      # Has it been longer then 5 minutes? (60 * 5 secs.)
85      #
86      if [ $times -eq 60 ]
87      then
88          echo "Error: Failed waiting for $1 dependents to be 'offline'"
89          $SVCS -D $1 2>>/dev/null | grep "^online"
90	  exit $SMF_EXIT_ERR_FATAL
91      fi
92
93      # Now sleep, giving other services time to stop
94      #
95      sleep 5
96      times=`expr $times + 1`
97    fi
98  done
99  return 0
100}
101
102CLINFO=/usr/sbin/clinfo
103
104killproc() {            # kill the named process(es)
105        pid=`/usr/bin/ps -e |
106             /usr/bin/grep -w $1 |
107             /usr/bin/sed -e 's/^  *//' -e 's/ .*//'`
108        [ "$pid" != "" ] && kill $pid
109}
110
111
112case "$1" in
113'start')
114	COPT=
115
116	if [ -x ${RDCBOOT} ]
117	then
118		if ${CLINFO}
119		then
120			if [ "$2" != "" ]
121			then
122	 			${RDCBOOT} -r -C $2
123			else
124				# SNDR 3.2 SetIDs fixup
125				${RDCBOOT} -C post-patch-setids -r -s
126
127				COPT="-C -"
128				${RDCBOOT} ${COPT} -r
129			fi
130		else
131			# non-clustered start
132			${RDCBOOT} -r
133		fi
134	fi
135	;;
136
137'stop')
138	COPT=
139
140	if [ ! -r /dev/rdc ]
141	then
142		RDCBOOT=/usr/bin/true
143	fi
144
145        do_smf_depends "system/nws_rdc"
146
147	if [ -x ${RDCBOOT} ]
148	then
149		if ${CLINFO}
150		then
151			if [ "$2" != "" ]
152			then
153				${RDCBOOT} -s -C $2
154			else
155				COPT="-C -"
156				${RDCBOOT} ${COPT} -s
157
158				echo "killing SNDR daemons"
159				killproc sndrd
160				killproc sndrsync
161			fi
162		else
163			# non-clustered stop
164
165			${RDCBOOT} -s
166
167			echo "killing SNDR daemons"
168			killproc sndrd
169			killproc sndrsync
170		fi
171	else
172		# no sndr boot command, kill daemon anyway
173
174		echo "killing SNDR daemons"
175		killproc sndrd
176		killproc sndrsync
177	fi
178
179	;;
180
181*)
182	echo $USAGE
183	exit 1
184	;;
185esac
186exit $SMF_EXIT_OK
187