xref: /titanic_44/usr/src/cmd/avs/sdbc/etc/scm.sh (revision 2d6b5ea734bb47d251c82670646fde46af15fd69)
1#!/bin/ksh
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#######################################################################
26#
27#   This file contains system setup requirements for scm.
28#
29#   For systems before Solaris 10 it should be located in /etc/init.d
30#   directory with the following links:
31#
32#       ln /etc/init.d/scm /etc/rc0.d/K84scm
33#       ln /etc/init.d/scm /etc/rc2.d/S002scm
34#
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
37#
38#USAGE="Usage: $0 { start | stop }
39#
40#######################################################################
41
42SVCS=/usr/bin/svcs
43DSCFG_DEPEND_NOCHK="/tmp/.dscfgadm_pid"
44OS_MINOR=`/usr/bin/uname -r | /usr/bin/cut -d '.' -f2`
45
46. /lib/svc/share/smf_include.sh
47
48# Make sure prior SMF dependents are not 'online'
49# $1 = name of SMF service to validate dependents
50#
51do_smf_depends ()
52{
53  times=0
54  count=1
55
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`
62	do
63		if [ `grep -c $pid $DSCFG_DEPEND_NOCHK` -gt 0 ]
64		then
65			return 0
66		fi
67	done
68  elif [ `ps -ef | grep preremove | grep -c SUNWscmu` -gt 0 ]
69  then
70 	return 0
71
72  fi
73
74  while [ $count -ne 0 ]
75  do
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
80      #
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"
85      fi
86
87      # Has it been longer then 5 minutes? (60 * 5 secs.)
88      #
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
94      fi
95
96      # Now sleep, giving other services time to stop
97      #
98      sleep 5
99      times=`expr $times + 1`
100    fi
101  done
102  return 0
103}
104
105set_system_type()
106{
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
113}
114
115do_stopsdbc ()
116{
117    if [ ! -r /dev/sdbc ]
118    then
119	return
120    fi
121
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"
126    fi
127}
128
129do_stopnskernd ()
130{
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
142      fi
143      /usr/sbin/modunload -i $mid > /dev/null 2>&1
144      if [ $? -ne 0 ] ; then
145	stop=0
146	break
147      fi
148    done
149
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
155      fi
156    fi
157  fi
158
159  if [ -r /dev/ncall -a -x $ESMSCMLIB/ncalladm ]
160  then
161    $ESMSCMLIB/ncalladm -d
162  fi
163}
164
165do_stopdscfglockd ()
166{
167  pid=`ps -e | grep -w dscfgloc | sed -e 's/^  *//' -e 's/ .*//'`
168  if [ -n "$pid" ] ; then
169    kill -15 $pid
170  fi
171}
172
173do_stop ()
174{
175  do_smf_depends "system/nws_scm"
176  do_stopsdbc
177  do_stopnskernd
178  do_stopdscfglockd
179}
180
181do_nskernd ()
182{
183  if [ -x $ESMSCMLIB/ncalladm ]
184  then
185    $ESMSCMLIB/ncalladm -e
186  fi
187
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
194    fi
195  fi
196}
197
198do_dscfglockd ()
199{
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
207	fi
208
209	if ${CLINFO}
210	then
211		#
212		# create or update the dscfg_lockdb file
213		#
214
215		# create clean tmpnodelist
216		NODELIST=/tmp/$$.dscfg_nodelist
217		rm -f $NODELIST >/dev/null 2>&1
218		touch $NODELIST
219
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
246				fi
247			fi
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"
257		fi
258
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"
269		fi
270
271		rm -f $NODELIST
272	fi
273
274}
275
276do_sdbc ()
277{
278      ${SCMBIN}/scmadm  -e
279}
280
281
282do_start ()
283{
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
289  fi
290
291  #
292  # Ordering:
293  #	dscfglockd	-- locking must be present before any dscfg access
294  #	nskernd		-- starts infrastructure (nskernd, ncall).
295  #	sdbc		-- start the cache itself
296  #
297  do_dscfglockd
298  do_nskernd
299  do_sdbc
300}
301
302
303do_usage ()
304{
305  echo "Usage: $0"
306  echo "   start"
307  echo "   stop"
308  exit 1
309}
310
311set_system_type
312
313USED=0
314ACTION=
315CLUSTERTAG=
316
317case $# in
318'0')
319     do_usage
320     ;;
321'1')
322     ACTION=$1
323     USED=1
324     ;;
325'2')
326     ACTION=$1
327     CLUSTERTAG="$2"
328     USED=1
329     exit 0
330     ;;
331'*')
332     do_usage
333     ;;
334esac
335
336if [ $USED = 0 ] ; then
337     do_usage
338fi
339
340if [ $ACTION = "start" ] ; then
341  do_start
342elif [ $ACTION = "stop" ] ; then
343  do_stop
344else
345  do_usage
346fi
347
348exit $SMF_EXIT_OK
349