8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / avs / rdc / etc / rdc.sh
blob198d1186b2c053b6bf328e1938328453ca2b11a3
1 #!/bin/sh
2 # CDDL HEADER START
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.
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.
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]
19 # CDDL HEADER END
22 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 # Use is subject to license terms.
25 # SNDR start script
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.
36 PATH=/etc:/bin
37 RDCBOOT="/usr/sbin/sndrboot"
38 USAGE="Usage: $0 {start|stop} [cluster_resource]"
39 SVCS=/usr/bin/svcs
40 DSCFG_DEPEND_NOCHK="/tmp/.dscfgadm_pid"
41 OS_MINOR=`/usr/bin/uname -r | /usr/bin/cut -d '.' -f2`
43 . /lib/svc/share/smf_include.sh
45 # Make sure prior SMF dependents are not 'online'
46 # $1 = name of SMF service to validate dependents
48 do_smf_depends ()
50 times=0
51 count=1
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`
60 if [ `grep -c $pid $DSCFG_DEPEND_NOCHK` -gt 0 ]
61 then
62 return 0
64 done
65 elif [ `ps -ef | grep preremove | grep -c SUNWrdcu` -gt 0 ]
66 then
67 return 0
71 while [ $count -ne 0 ]
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
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"
84 # Has it been longer then 5 minutes? (60 * 5 secs.)
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
93 # Now sleep, giving other services time to stop
95 sleep 5
96 times=`expr $times + 1`
98 done
99 return 0
102 CLINFO=/usr/sbin/clinfo
104 killproc() { # 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
112 case "$1" in
113 'start')
114 COPT=
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
127 COPT="-C -"
128 ${RDCBOOT} ${COPT} -r
130 else
131 # non-clustered start
132 ${RDCBOOT} -r
137 'stop')
138 COPT=
140 if [ ! -r /dev/rdc ]
141 then
142 RDCBOOT=/usr/bin/true
145 do_smf_depends "system/nws_rdc"
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
158 echo "killing SNDR daemons"
159 killproc sndrd
160 killproc sndrsync
162 else
163 # non-clustered stop
165 ${RDCBOOT} -s
167 echo "killing SNDR daemons"
168 killproc sndrd
169 killproc sndrsync
171 else
172 # no sndr boot command, kill daemon anyway
174 echo "killing SNDR daemons"
175 killproc sndrd
176 killproc sndrsync
182 echo $USAGE
183 exit 1
185 esac
186 exit $SMF_EXIT_OK