xref: /titanic_51/usr/src/cmd/avs/sdbc/etc/scm.sh (revision fcf3ce441efd61da9bb2884968af01cb7c1452cc)
1*fcf3ce44SJohn Forte#!/bin/ksh
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#
27*fcf3ce44SJohn Forte#   This file contains system setup requirements for scm.
28*fcf3ce44SJohn Forte#
29*fcf3ce44SJohn Forte#   For systems before Solaris 10 it should be located in /etc/init.d
30*fcf3ce44SJohn Forte#   directory with the following links:
31*fcf3ce44SJohn Forte#
32*fcf3ce44SJohn Forte#       ln /etc/init.d/scm /etc/rc0.d/K84scm
33*fcf3ce44SJohn Forte#       ln /etc/init.d/scm /etc/rc2.d/S002scm
34*fcf3ce44SJohn Forte#
35*fcf3ce44SJohn Forte#    For Solaris 10 or later systems this script is run as part of SVC by
36*fcf3ce44SJohn Forte#    svc.startd and should be located in /lib/svc/method
37*fcf3ce44SJohn Forte#
38*fcf3ce44SJohn Forte#USAGE="Usage: $0 { start | stop }
39*fcf3ce44SJohn Forte#
40*fcf3ce44SJohn Forte#######################################################################
41*fcf3ce44SJohn Forte
42*fcf3ce44SJohn ForteSVCS=/usr/bin/svcs
43*fcf3ce44SJohn ForteDSCFG_DEPEND_NOCHK="/tmp/.dscfgadm_pid"
44*fcf3ce44SJohn ForteOS_MINOR=`/usr/bin/uname -r | /usr/bin/cut -d '.' -f2`
45*fcf3ce44SJohn Forte
46*fcf3ce44SJohn Forte. /lib/svc/share/smf_include.sh
47*fcf3ce44SJohn Forte
48*fcf3ce44SJohn Forte# Make sure prior SMF dependents are not 'online'
49*fcf3ce44SJohn Forte# $1 = name of SMF service to validate dependents
50*fcf3ce44SJohn Forte#
51*fcf3ce44SJohn Fortedo_smf_depends ()
52*fcf3ce44SJohn Forte{
53*fcf3ce44SJohn Forte  times=0
54*fcf3ce44SJohn Forte  count=1
55*fcf3ce44SJohn Forte
56*fcf3ce44SJohn Forte  if [ $OS_MINOR -ge 11 ]
57*fcf3ce44SJohn Forte  then
58*fcf3ce44SJohn Forte	return 0
59*fcf3ce44SJohn Forte  elif [ -f $DSCFG_DEPEND_NOCHK ]
60*fcf3ce44SJohn Forte  then
61*fcf3ce44SJohn Forte	for pid in `pgrep dscfgadm`
62*fcf3ce44SJohn Forte	do
63*fcf3ce44SJohn Forte		if [ `grep -c $pid $DSCFG_DEPEND_NOCHK` -gt 0 ]
64*fcf3ce44SJohn Forte		then
65*fcf3ce44SJohn Forte			return 0
66*fcf3ce44SJohn Forte		fi
67*fcf3ce44SJohn Forte	done
68*fcf3ce44SJohn Forte  elif [ `ps -ef | grep preremove | grep -c SUNWscmu` -gt 0 ]
69*fcf3ce44SJohn Forte  then
70*fcf3ce44SJohn Forte 	return 0
71*fcf3ce44SJohn Forte
72*fcf3ce44SJohn Forte  fi
73*fcf3ce44SJohn Forte
74*fcf3ce44SJohn Forte  while [ $count -ne 0 ]
75*fcf3ce44SJohn Forte  do
76*fcf3ce44SJohn Forte    count=`$SVCS -o STATE -D $1 2>>/dev/null | grep "^online" | wc -l`
77*fcf3ce44SJohn Forte    if [ $count -ne 0 ]
78*fcf3ce44SJohn Forte    then
79*fcf3ce44SJohn Forte      # Output banner after waiting first 5 seconds
80*fcf3ce44SJohn Forte      #
81*fcf3ce44SJohn Forte      if [ $times -eq 1 ]
82*fcf3ce44SJohn Forte      then
83*fcf3ce44SJohn Forte        echo "Waiting for $1 dependents to be 'offline'"
84*fcf3ce44SJohn Forte        $SVCS -D $1 2>>/dev/null | grep "^online"
85*fcf3ce44SJohn Forte      fi
86*fcf3ce44SJohn Forte
87*fcf3ce44SJohn Forte      # Has it been longer then 5 minutes? (60 * 5 secs.)
88*fcf3ce44SJohn Forte      #
89*fcf3ce44SJohn Forte      if [ $times -eq 60 ]
90*fcf3ce44SJohn Forte      then
91*fcf3ce44SJohn Forte          echo "Error: Failed waiting for $1 dependents to be 'offline'"
92*fcf3ce44SJohn Forte          $SVCS -D $1 2>>/dev/null | grep "^online"
93*fcf3ce44SJohn Forte	  exit $SMF_EXIT_ERR_FATAL
94*fcf3ce44SJohn Forte      fi
95*fcf3ce44SJohn Forte
96*fcf3ce44SJohn Forte      # Now sleep, giving other services time to stop
97*fcf3ce44SJohn Forte      #
98*fcf3ce44SJohn Forte      sleep 5
99*fcf3ce44SJohn Forte      times=`expr $times + 1`
100*fcf3ce44SJohn Forte    fi
101*fcf3ce44SJohn Forte  done
102*fcf3ce44SJohn Forte  return 0
103*fcf3ce44SJohn Forte}
104*fcf3ce44SJohn Forte
105*fcf3ce44SJohn Forteset_system_type()
106*fcf3ce44SJohn Forte{
107*fcf3ce44SJohn Forte	CLINFO=/usr/sbin/clinfo
108*fcf3ce44SJohn Forte	ESMSBIN=/usr/sbin
109*fcf3ce44SJohn Forte	SCMBIN=/usr/sbin
110*fcf3ce44SJohn Forte	ESMSCMLIB=/usr/lib
111*fcf3ce44SJohn Forte	SCMLIB=/usr/lib
112*fcf3ce44SJohn Forte	DSCFG_LOCKDB=/etc/dscfg_lockdb
113*fcf3ce44SJohn Forte}
114*fcf3ce44SJohn Forte
115*fcf3ce44SJohn Fortedo_stopsdbc ()
116*fcf3ce44SJohn Forte{
117*fcf3ce44SJohn Forte    if [ ! -r /dev/sdbc ]
118*fcf3ce44SJohn Forte    then
119*fcf3ce44SJohn Forte	return
120*fcf3ce44SJohn Forte    fi
121*fcf3ce44SJohn Forte
122*fcf3ce44SJohn Forte    ${SCMBIN}/scmadm -d
123*fcf3ce44SJohn Forte    if [ $? -ne 0 ] ; then
124*fcf3ce44SJohn Forte	# If the disable failed that means we have pinned data.
125*fcf3ce44SJohn Forte	echo "Cache Not Deconfigured"
126*fcf3ce44SJohn Forte    fi
127*fcf3ce44SJohn Forte}
128*fcf3ce44SJohn Forte
129*fcf3ce44SJohn Fortedo_stopnskernd ()
130*fcf3ce44SJohn Forte{
131*fcf3ce44SJohn Forte  ps -e | grep -w nskernd > /dev/null 2>&1
132*fcf3ce44SJohn Forte  if [ $? -eq 0 ] ; then
133*fcf3ce44SJohn Forte    # make sure that all data services are unloaded before stopping
134*fcf3ce44SJohn Forte    # nskernd - cannot stop nskernd when its threads could be in use
135*fcf3ce44SJohn Forte    # Note: sv is unloadable, but its threadset is shutdown in the
136*fcf3ce44SJohn Forte    # final close(9e) call.
137*fcf3ce44SJohn Forte    stop=1
138*fcf3ce44SJohn Forte    for m in ste rdc rdcsrv ii sdbc ; do
139*fcf3ce44SJohn Forte      mid=`/usr/sbin/modinfo | grep -w $m | awk '{print $1}' -`
140*fcf3ce44SJohn Forte      if [ -z "$mid" ] ; then
141*fcf3ce44SJohn Forte	continue	# not loaded
142*fcf3ce44SJohn Forte      fi
143*fcf3ce44SJohn Forte      /usr/sbin/modunload -i $mid > /dev/null 2>&1
144*fcf3ce44SJohn Forte      if [ $? -ne 0 ] ; then
145*fcf3ce44SJohn Forte	stop=0
146*fcf3ce44SJohn Forte	break
147*fcf3ce44SJohn Forte      fi
148*fcf3ce44SJohn Forte    done
149*fcf3ce44SJohn Forte
150*fcf3ce44SJohn Forte    # kill nskernd if we can
151*fcf3ce44SJohn Forte    pid=`ps -e | grep -w nskernd | sed -e 's/^  *//' -e 's/ .*//'`
152*fcf3ce44SJohn Forte    if [ $stop -eq 1 ] ; then
153*fcf3ce44SJohn Forte      if [ -n "$pid" ] ; then
154*fcf3ce44SJohn Forte        kill -15 $pid
155*fcf3ce44SJohn Forte      fi
156*fcf3ce44SJohn Forte    fi
157*fcf3ce44SJohn Forte  fi
158*fcf3ce44SJohn Forte
159*fcf3ce44SJohn Forte  if [ -r /dev/ncall -a -x $ESMSCMLIB/ncalladm ]
160*fcf3ce44SJohn Forte  then
161*fcf3ce44SJohn Forte    $ESMSCMLIB/ncalladm -d
162*fcf3ce44SJohn Forte  fi
163*fcf3ce44SJohn Forte}
164*fcf3ce44SJohn Forte
165*fcf3ce44SJohn Fortedo_stopdscfglockd ()
166*fcf3ce44SJohn Forte{
167*fcf3ce44SJohn Forte  pid=`ps -e | grep -w dscfgloc | sed -e 's/^  *//' -e 's/ .*//'`
168*fcf3ce44SJohn Forte  if [ -n "$pid" ] ; then
169*fcf3ce44SJohn Forte    kill -15 $pid
170*fcf3ce44SJohn Forte  fi
171*fcf3ce44SJohn Forte}
172*fcf3ce44SJohn Forte
173*fcf3ce44SJohn Fortedo_stop ()
174*fcf3ce44SJohn Forte{
175*fcf3ce44SJohn Forte  do_smf_depends "system/nws_scm"
176*fcf3ce44SJohn Forte  do_stopsdbc
177*fcf3ce44SJohn Forte  do_stopnskernd
178*fcf3ce44SJohn Forte  do_stopdscfglockd
179*fcf3ce44SJohn Forte}
180*fcf3ce44SJohn Forte
181*fcf3ce44SJohn Fortedo_nskernd ()
182*fcf3ce44SJohn Forte{
183*fcf3ce44SJohn Forte  if [ -x $ESMSCMLIB/ncalladm ]
184*fcf3ce44SJohn Forte  then
185*fcf3ce44SJohn Forte    $ESMSCMLIB/ncalladm -e
186*fcf3ce44SJohn Forte  fi
187*fcf3ce44SJohn Forte
188*fcf3ce44SJohn Forte  ps -e | grep -w nskernd > /dev/null 2>&1
189*fcf3ce44SJohn Forte  if [ $? -ne 0 ] ; then
190*fcf3ce44SJohn Forte    ${SCMLIB}/nskernd
191*fcf3ce44SJohn Forte    if [ $? -ne 0 ] ; then
192*fcf3ce44SJohn Forte      echo "Error: Unable to start nskernd"
193*fcf3ce44SJohn Forte      exit $SMF_EXIT_ERR_FATAL
194*fcf3ce44SJohn Forte    fi
195*fcf3ce44SJohn Forte  fi
196*fcf3ce44SJohn Forte}
197*fcf3ce44SJohn Forte
198*fcf3ce44SJohn Fortedo_dscfglockd ()
199*fcf3ce44SJohn Forte{
200*fcf3ce44SJohn Forte	ps -e | grep -w dscfgloc > /dev/null 2>&1
201*fcf3ce44SJohn Forte	if [ $? -ne 0 ]
202*fcf3ce44SJohn Forte	then
203*fcf3ce44SJohn Forte		rm -f /var/tmp/.cfglockd.pid
204*fcf3ce44SJohn Forte	else
205*fcf3ce44SJohn Forte		# dscfglockd already running
206*fcf3ce44SJohn Forte		return
207*fcf3ce44SJohn Forte	fi
208*fcf3ce44SJohn Forte
209*fcf3ce44SJohn Forte	if ${CLINFO}
210*fcf3ce44SJohn Forte	then
211*fcf3ce44SJohn Forte		#
212*fcf3ce44SJohn Forte		# create or update the dscfg_lockdb file
213*fcf3ce44SJohn Forte		#
214*fcf3ce44SJohn Forte
215*fcf3ce44SJohn Forte		# create clean tmpnodelist
216*fcf3ce44SJohn Forte		NODELIST=/tmp/$$.dscfg_nodelist
217*fcf3ce44SJohn Forte		rm -f $NODELIST >/dev/null 2>&1
218*fcf3ce44SJohn Forte		touch $NODELIST
219*fcf3ce44SJohn Forte
220*fcf3ce44SJohn Forte		if [ -x /usr/cluster/bin/scstat ]
221*fcf3ce44SJohn Forte		then
222*fcf3ce44SJohn Forte			# get valid names in cluster
223*fcf3ce44SJohn Forte			/usr/cluster/bin/scstat -n | grep node: | \
224*fcf3ce44SJohn Forte			    awk '{print $3}' >> $NODELIST
225*fcf3ce44SJohn Forte			if [ ! -f $DSCFG_LOCKDB ]
226*fcf3ce44SJohn Forte			then
227*fcf3ce44SJohn Forte				printf "In clustered environment.\n"
228*fcf3ce44SJohn Forte				printf "creating per node dscfg_lockdb database"
229*fcf3ce44SJohn Forte				printf " with following nodenames:\n"
230*fcf3ce44SJohn Forte				cat $NODELIST
231*fcf3ce44SJohn Forte				cp $NODELIST $DSCFG_LOCKDB
232*fcf3ce44SJohn Forte			else
233*fcf3ce44SJohn Forte				# check if there are any changes
234*fcf3ce44SJohn Forte				diff $NODELIST $DSCFG_LOCKDB > /dev/null
235*fcf3ce44SJohn Forte				if [ $? != 0 ]
236*fcf3ce44SJohn Forte				then
237*fcf3ce44SJohn Forte					printf "The cluster node names have "
238*fcf3ce44SJohn Forte					printf "changed. Updating dscfg_lockdb "
239*fcf3ce44SJohn Forte					printf "database.\n"
240*fcf3ce44SJohn Forte					printf "Previous node names:\n"
241*fcf3ce44SJohn Forte					cat $DSCFG_LOCKDB
242*fcf3ce44SJohn Forte					printf "New node names:\n"
243*fcf3ce44SJohn Forte					cat $NODELIST
244*fcf3ce44SJohn Forte					rm -f $DSCFG_LOCKDB
245*fcf3ce44SJohn Forte					cp $NODELIST $DSCFG_LOCKDB
246*fcf3ce44SJohn Forte				fi
247*fcf3ce44SJohn Forte			fi
248*fcf3ce44SJohn Forte		else
249*fcf3ce44SJohn Forte			# we're in a cluster, but scstat is not available
250*fcf3ce44SJohn Forte			printf "In clustered environment.\n"
251*fcf3ce44SJohn Forte			printf "Required configuration file, $DSCFG_LOCKDB\n"
252*fcf3ce44SJohn Forte			printf "was not properly populated with the cluster "
253*fcf3ce44SJohn Forte			printf "nodenames.\nThis file needs to be manually"
254*fcf3ce44SJohn Forte			printf "updated with the cluster\nnodenames before "
255*fcf3ce44SJohn Forte			printf "reboot.  Refer to Sun Storage Availability\n"
256*fcf3ce44SJohn Forte			printf "Suite Installation Guide for details.\n"
257*fcf3ce44SJohn Forte		fi
258*fcf3ce44SJohn Forte
259*fcf3ce44SJohn Forte		# clustered start of dscfglockd
260*fcf3ce44SJohn Forte		if [ -f $DSCFG_LOCKDB ]
261*fcf3ce44SJohn Forte		then
262*fcf3ce44SJohn Forte			printf "Starting dscfglockd\n"
263*fcf3ce44SJohn Forte			${SCMLIB}/dscfglockd -f $DSCFG_LOCKDB
264*fcf3ce44SJohn Forte		else
265*fcf3ce44SJohn Forte			printf "WARNING: Mis-Configuration of Availability "
266*fcf3ce44SJohn Forte			printf "Suite for Sun Cluster\n"
267*fcf3ce44SJohn Forte			printf "WARNING: Can't find configuration file for "
268*fcf3ce44SJohn Forte			printf "dscfglockd\n"
269*fcf3ce44SJohn Forte		fi
270*fcf3ce44SJohn Forte
271*fcf3ce44SJohn Forte		rm -f $NODELIST
272*fcf3ce44SJohn Forte	fi
273*fcf3ce44SJohn Forte
274*fcf3ce44SJohn Forte}
275*fcf3ce44SJohn Forte
276*fcf3ce44SJohn Fortedo_sdbc ()
277*fcf3ce44SJohn Forte{
278*fcf3ce44SJohn Forte      ${SCMBIN}/scmadm  -e
279*fcf3ce44SJohn Forte}
280*fcf3ce44SJohn Forte
281*fcf3ce44SJohn Forte
282*fcf3ce44SJohn Fortedo_start ()
283*fcf3ce44SJohn Forte{
284*fcf3ce44SJohn Forte  # do nothing if we do not have a dscfg
285*fcf3ce44SJohn Forte  if [ ! -f /etc/dscfg_local ]
286*fcf3ce44SJohn Forte  then
287*fcf3ce44SJohn Forte      echo "Cannot find Availability Suite configuration location"
288*fcf3ce44SJohn Forte      exit $SMF_EXIT_ERR_NOSMF
289*fcf3ce44SJohn Forte  fi
290*fcf3ce44SJohn Forte
291*fcf3ce44SJohn Forte  #
292*fcf3ce44SJohn Forte  # Ordering:
293*fcf3ce44SJohn Forte  #	dscfglockd	-- locking must be present before any dscfg access
294*fcf3ce44SJohn Forte  #	nskernd		-- starts infrastructure (nskernd, ncall).
295*fcf3ce44SJohn Forte  #	sdbc		-- start the cache itself
296*fcf3ce44SJohn Forte  #
297*fcf3ce44SJohn Forte  do_dscfglockd
298*fcf3ce44SJohn Forte  do_nskernd
299*fcf3ce44SJohn Forte  do_sdbc
300*fcf3ce44SJohn Forte}
301*fcf3ce44SJohn Forte
302*fcf3ce44SJohn Forte
303*fcf3ce44SJohn Fortedo_usage ()
304*fcf3ce44SJohn Forte{
305*fcf3ce44SJohn Forte  echo "Usage: $0"
306*fcf3ce44SJohn Forte  echo "   start"
307*fcf3ce44SJohn Forte  echo "   stop"
308*fcf3ce44SJohn Forte  exit 1
309*fcf3ce44SJohn Forte}
310*fcf3ce44SJohn Forte
311*fcf3ce44SJohn Forteset_system_type
312*fcf3ce44SJohn Forte
313*fcf3ce44SJohn ForteUSED=0
314*fcf3ce44SJohn ForteACTION=
315*fcf3ce44SJohn ForteCLUSTERTAG=
316*fcf3ce44SJohn Forte
317*fcf3ce44SJohn Fortecase $# in
318*fcf3ce44SJohn Forte'0')
319*fcf3ce44SJohn Forte     do_usage
320*fcf3ce44SJohn Forte     ;;
321*fcf3ce44SJohn Forte'1')
322*fcf3ce44SJohn Forte     ACTION=$1
323*fcf3ce44SJohn Forte     USED=1
324*fcf3ce44SJohn Forte     ;;
325*fcf3ce44SJohn Forte'2')
326*fcf3ce44SJohn Forte     ACTION=$1
327*fcf3ce44SJohn Forte     CLUSTERTAG="$2"
328*fcf3ce44SJohn Forte     USED=1
329*fcf3ce44SJohn Forte     exit 0
330*fcf3ce44SJohn Forte     ;;
331*fcf3ce44SJohn Forte'*')
332*fcf3ce44SJohn Forte     do_usage
333*fcf3ce44SJohn Forte     ;;
334*fcf3ce44SJohn Forteesac
335*fcf3ce44SJohn Forte
336*fcf3ce44SJohn Forteif [ $USED = 0 ] ; then
337*fcf3ce44SJohn Forte     do_usage
338*fcf3ce44SJohn Fortefi
339*fcf3ce44SJohn Forte
340*fcf3ce44SJohn Forteif [ $ACTION = "start" ] ; then
341*fcf3ce44SJohn Forte  do_start
342*fcf3ce44SJohn Forteelif [ $ACTION = "stop" ] ; then
343*fcf3ce44SJohn Forte  do_stop
344*fcf3ce44SJohn Forteelse
345*fcf3ce44SJohn Forte  do_usage
346*fcf3ce44SJohn Fortefi
347*fcf3ce44SJohn Forte
348*fcf3ce44SJohn Forteexit $SMF_EXIT_OK
349