8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / avs / sdbc / etc / scm.sh
blobf5ce4b1a7829a76e3a93bba57c091f8c912a2ba7
1 #!/bin/ksh
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 #######################################################################
27 # This file contains system setup requirements for scm.
29 # For systems before Solaris 10 it should be located in /etc/init.d
30 # directory with the following links:
32 # ln /etc/init.d/scm /etc/rc0.d/K84scm
33 # ln /etc/init.d/scm /etc/rc2.d/S002scm
35 # For Solaris 10 or later systems this script is run as part of SVC by
36 # svc.startd and should be located in /lib/svc/method
38 #USAGE="Usage: $0 { start | stop }
40 #######################################################################
42 SVCS=/usr/bin/svcs
43 DSCFG_DEPEND_NOCHK="/tmp/.dscfgadm_pid"
44 OS_MINOR=`/usr/bin/uname -r | /usr/bin/cut -d '.' -f2`
46 . /lib/svc/share/smf_include.sh
48 # Make sure prior SMF dependents are not 'online'
49 # $1 = name of SMF service to validate dependents
51 do_smf_depends ()
53 times=0
54 count=1
56 if [ $OS_MINOR -ge 11 ]
57 then
58 return 0
59 elif [ -f $DSCFG_DEPEND_NOCHK ]
60 then
61 for pid in `pgrep dscfgadm`
63 if [ `grep -c $pid $DSCFG_DEPEND_NOCHK` -gt 0 ]
64 then
65 return 0
67 done
68 elif [ `ps -ef | grep preremove | grep -c SUNWscmu` -gt 0 ]
69 then
70 return 0
74 while [ $count -ne 0 ]
76 count=`$SVCS -o STATE -D $1 2>>/dev/null | grep "^online" | wc -l`
77 if [ $count -ne 0 ]
78 then
79 # Output banner after waiting first 5 seconds
81 if [ $times -eq 1 ]
82 then
83 echo "Waiting for $1 dependents to be 'offline'"
84 $SVCS -D $1 2>>/dev/null | grep "^online"
87 # Has it been longer then 5 minutes? (60 * 5 secs.)
89 if [ $times -eq 60 ]
90 then
91 echo "Error: Failed waiting for $1 dependents to be 'offline'"
92 $SVCS -D $1 2>>/dev/null | grep "^online"
93 exit $SMF_EXIT_ERR_FATAL
96 # Now sleep, giving other services time to stop
98 sleep 5
99 times=`expr $times + 1`
101 done
102 return 0
105 set_system_type()
107 CLINFO=/usr/sbin/clinfo
108 ESMSBIN=/usr/sbin
109 SCMBIN=/usr/sbin
110 ESMSCMLIB=/usr/lib
111 SCMLIB=/usr/lib
112 DSCFG_LOCKDB=/etc/dscfg_lockdb
115 do_stopsdbc ()
117 if [ ! -r /dev/sdbc ]
118 then
119 return
122 ${SCMBIN}/scmadm -d
123 if [ $? -ne 0 ] ; then
124 # If the disable failed that means we have pinned data.
125 echo "Cache Not Deconfigured"
129 do_stopnskernd ()
131 ps -e | grep -w nskernd > /dev/null 2>&1
132 if [ $? -eq 0 ] ; then
133 # make sure that all data services are unloaded before stopping
134 # nskernd - cannot stop nskernd when its threads could be in use
135 # Note: sv is unloadable, but its threadset is shutdown in the
136 # final close(9e) call.
137 stop=1
138 for m in ste rdc rdcsrv ii sdbc ; do
139 mid=`/usr/sbin/modinfo | grep -w $m | awk '{print $1}' -`
140 if [ -z "$mid" ] ; then
141 continue # not loaded
143 /usr/sbin/modunload -i $mid > /dev/null 2>&1
144 if [ $? -ne 0 ] ; then
145 stop=0
146 break
148 done
150 # kill nskernd if we can
151 pid=`ps -e | grep -w nskernd | sed -e 's/^ *//' -e 's/ .*//'`
152 if [ $stop -eq 1 ] ; then
153 if [ -n "$pid" ] ; then
154 kill -15 $pid
159 if [ -r /dev/ncall -a -x $ESMSCMLIB/ncalladm ]
160 then
161 $ESMSCMLIB/ncalladm -d
165 do_stopdscfglockd ()
167 pid=`ps -e | grep -w dscfgloc | sed -e 's/^ *//' -e 's/ .*//'`
168 if [ -n "$pid" ] ; then
169 kill -15 $pid
173 do_stop ()
175 do_smf_depends "system/nws_scm"
176 do_stopsdbc
177 do_stopnskernd
178 do_stopdscfglockd
181 do_nskernd ()
183 if [ -x $ESMSCMLIB/ncalladm ]
184 then
185 $ESMSCMLIB/ncalladm -e
188 ps -e | grep -w nskernd > /dev/null 2>&1
189 if [ $? -ne 0 ] ; then
190 ${SCMLIB}/nskernd
191 if [ $? -ne 0 ] ; then
192 echo "Error: Unable to start nskernd"
193 exit $SMF_EXIT_ERR_FATAL
198 do_dscfglockd ()
200 ps -e | grep -w dscfgloc > /dev/null 2>&1
201 if [ $? -ne 0 ]
202 then
203 rm -f /var/tmp/.cfglockd.pid
204 else
205 # dscfglockd already running
206 return
209 if ${CLINFO}
210 then
212 # create or update the dscfg_lockdb file
215 # create clean tmpnodelist
216 NODELIST=/tmp/$$.dscfg_nodelist
217 rm -f $NODELIST >/dev/null 2>&1
218 touch $NODELIST
220 if [ -x /usr/cluster/bin/scstat ]
221 then
222 # get valid names in cluster
223 /usr/cluster/bin/scstat -n | grep node: | \
224 awk '{print $3}' >> $NODELIST
225 if [ ! -f $DSCFG_LOCKDB ]
226 then
227 printf "In clustered environment.\n"
228 printf "creating per node dscfg_lockdb database"
229 printf " with following nodenames:\n"
230 cat $NODELIST
231 cp $NODELIST $DSCFG_LOCKDB
232 else
233 # check if there are any changes
234 diff $NODELIST $DSCFG_LOCKDB > /dev/null
235 if [ $? != 0 ]
236 then
237 printf "The cluster node names have "
238 printf "changed. Updating dscfg_lockdb "
239 printf "database.\n"
240 printf "Previous node names:\n"
241 cat $DSCFG_LOCKDB
242 printf "New node names:\n"
243 cat $NODELIST
244 rm -f $DSCFG_LOCKDB
245 cp $NODELIST $DSCFG_LOCKDB
248 else
249 # we're in a cluster, but scstat is not available
250 printf "In clustered environment.\n"
251 printf "Required configuration file, $DSCFG_LOCKDB\n"
252 printf "was not properly populated with the cluster "
253 printf "nodenames.\nThis file needs to be manually"
254 printf "updated with the cluster\nnodenames before "
255 printf "reboot. Refer to Sun Storage Availability\n"
256 printf "Suite Installation Guide for details.\n"
259 # clustered start of dscfglockd
260 if [ -f $DSCFG_LOCKDB ]
261 then
262 printf "Starting dscfglockd\n"
263 ${SCMLIB}/dscfglockd -f $DSCFG_LOCKDB
264 else
265 printf "WARNING: Mis-Configuration of Availability "
266 printf "Suite for Sun Cluster\n"
267 printf "WARNING: Can't find configuration file for "
268 printf "dscfglockd\n"
271 rm -f $NODELIST
276 do_sdbc ()
278 ${SCMBIN}/scmadm -e
282 do_start ()
284 # do nothing if we do not have a dscfg
285 if [ ! -f /etc/dscfg_local ]
286 then
287 echo "Cannot find Availability Suite configuration location"
288 exit $SMF_EXIT_ERR_NOSMF
292 # Ordering:
293 # dscfglockd -- locking must be present before any dscfg access
294 # nskernd -- starts infrastructure (nskernd, ncall).
295 # sdbc -- start the cache itself
297 do_dscfglockd
298 do_nskernd
299 do_sdbc
303 do_usage ()
305 echo "Usage: $0"
306 echo " start"
307 echo " stop"
308 exit 1
311 set_system_type
313 USED=0
314 ACTION=
315 CLUSTERTAG=
317 case $# in
318 '0')
319 do_usage
321 '1')
322 ACTION=$1
323 USED=1
325 '2')
326 ACTION=$1
327 CLUSTERTAG="$2"
328 USED=1
329 exit 0
331 '*')
332 do_usage
334 esac
336 if [ $USED = 0 ] ; then
337 do_usage
340 if [ $ACTION = "start" ] ; then
341 do_start
342 elif [ $ACTION = "stop" ] ; then
343 do_stop
344 else
345 do_usage
348 exit $SMF_EXIT_OK