summaryrefslogtreecommitdiff
path: root/usr/src/cmd/avs/sdbc/etc/scm.sh
blob: f5ce4b1a7829a76e3a93bba57c091f8c912a2ba7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
#!/bin/ksh
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
#######################################################################
#
#   This file contains system setup requirements for scm.
#
#   For systems before Solaris 10 it should be located in /etc/init.d
#   directory with the following links:
#
#       ln /etc/init.d/scm /etc/rc0.d/K84scm
#       ln /etc/init.d/scm /etc/rc2.d/S002scm
#
#    For Solaris 10 or later systems this script is run as part of SVC by
#    svc.startd and should be located in /lib/svc/method
#
#USAGE="Usage: $0 { start | stop }
#
#######################################################################

SVCS=/usr/bin/svcs
DSCFG_DEPEND_NOCHK="/tmp/.dscfgadm_pid"
OS_MINOR=`/usr/bin/uname -r | /usr/bin/cut -d '.' -f2`

. /lib/svc/share/smf_include.sh

# Make sure prior SMF dependents are not 'online'
# $1 = name of SMF service to validate dependents
#
do_smf_depends ()
{
  times=0
  count=1

  if [ $OS_MINOR -ge 11 ]
  then
	return 0
  elif [ -f $DSCFG_DEPEND_NOCHK ]
  then
	for pid in `pgrep dscfgadm`
	do
		if [ `grep -c $pid $DSCFG_DEPEND_NOCHK` -gt 0 ]
		then
			return 0
		fi
	done
  elif [ `ps -ef | grep preremove | grep -c SUNWscmu` -gt 0 ]
  then
 	return 0

  fi

  while [ $count -ne 0 ]
  do
    count=`$SVCS -o STATE -D $1 2>>/dev/null | grep "^online" | wc -l`
    if [ $count -ne 0 ]
    then
      # Output banner after waiting first 5 seconds
      #
      if [ $times -eq 1 ]
      then
        echo "Waiting for $1 dependents to be 'offline'"
        $SVCS -D $1 2>>/dev/null | grep "^online"
      fi

      # Has it been longer then 5 minutes? (60 * 5 secs.)
      #
      if [ $times -eq 60 ]
      then
          echo "Error: Failed waiting for $1 dependents to be 'offline'"
          $SVCS -D $1 2>>/dev/null | grep "^online"
	  exit $SMF_EXIT_ERR_FATAL
      fi

      # Now sleep, giving other services time to stop
      #
      sleep 5
      times=`expr $times + 1`
    fi
  done
  return 0
}

set_system_type()
{
	CLINFO=/usr/sbin/clinfo
	ESMSBIN=/usr/sbin
	SCMBIN=/usr/sbin
	ESMSCMLIB=/usr/lib
	SCMLIB=/usr/lib
	DSCFG_LOCKDB=/etc/dscfg_lockdb
}

do_stopsdbc ()
{
    if [ ! -r /dev/sdbc ]
    then
	return
    fi

    ${SCMBIN}/scmadm -d
    if [ $? -ne 0 ] ; then
	# If the disable failed that means we have pinned data.
	echo "Cache Not Deconfigured"
    fi
}

do_stopnskernd ()
{
  ps -e | grep -w nskernd > /dev/null 2>&1
  if [ $? -eq 0 ] ; then
    # make sure that all data services are unloaded before stopping
    # nskernd - cannot stop nskernd when its threads could be in use
    # Note: sv is unloadable, but its threadset is shutdown in the
    # final close(9e) call.
    stop=1
    for m in ste rdc rdcsrv ii sdbc ; do
      mid=`/usr/sbin/modinfo | grep -w $m | awk '{print $1}' -`
      if [ -z "$mid" ] ; then
	continue	# not loaded
      fi
      /usr/sbin/modunload -i $mid > /dev/null 2>&1
      if [ $? -ne 0 ] ; then
	stop=0
	break
      fi
    done

    # kill nskernd if we can
    pid=`ps -e | grep -w nskernd | sed -e 's/^  *//' -e 's/ .*//'`
    if [ $stop -eq 1 ] ; then
      if [ -n "$pid" ] ; then
        kill -15 $pid
      fi
    fi
  fi

  if [ -r /dev/ncall -a -x $ESMSCMLIB/ncalladm ]
  then
    $ESMSCMLIB/ncalladm -d
  fi
}

do_stopdscfglockd ()
{
  pid=`ps -e | grep -w dscfgloc | sed -e 's/^  *//' -e 's/ .*//'`
  if [ -n "$pid" ] ; then
    kill -15 $pid
  fi
}

do_stop ()
{
  do_smf_depends "system/nws_scm"
  do_stopsdbc
  do_stopnskernd
  do_stopdscfglockd
}

do_nskernd ()
{
  if [ -x $ESMSCMLIB/ncalladm ]
  then
    $ESMSCMLIB/ncalladm -e
  fi

  ps -e | grep -w nskernd > /dev/null 2>&1
  if [ $? -ne 0 ] ; then
    ${SCMLIB}/nskernd
    if [ $? -ne 0 ] ; then
      echo "Error: Unable to start nskernd"
      exit $SMF_EXIT_ERR_FATAL
    fi
  fi
}

do_dscfglockd ()
{
	ps -e | grep -w dscfgloc > /dev/null 2>&1
	if [ $? -ne 0 ]
	then
		rm -f /var/tmp/.cfglockd.pid
	else
		# dscfglockd already running
		return
	fi

	if ${CLINFO}
	then
		#
		# create or update the dscfg_lockdb file
		#

		# create clean tmpnodelist
		NODELIST=/tmp/$$.dscfg_nodelist
		rm -f $NODELIST >/dev/null 2>&1
		touch $NODELIST

		if [ -x /usr/cluster/bin/scstat ]
		then
			# get valid names in cluster
			/usr/cluster/bin/scstat -n | grep node: | \
			    awk '{print $3}' >> $NODELIST
			if [ ! -f $DSCFG_LOCKDB ]
			then
				printf "In clustered environment.\n"
				printf "creating per node dscfg_lockdb database"
				printf " with following nodenames:\n"
				cat $NODELIST
				cp $NODELIST $DSCFG_LOCKDB
			else
				# check if there are any changes
				diff $NODELIST $DSCFG_LOCKDB > /dev/null
				if [ $? != 0 ]
				then
					printf "The cluster node names have "
					printf "changed. Updating dscfg_lockdb "
					printf "database.\n"
					printf "Previous node names:\n"
					cat $DSCFG_LOCKDB
					printf "New node names:\n"
					cat $NODELIST
					rm -f $DSCFG_LOCKDB
					cp $NODELIST $DSCFG_LOCKDB
				fi
			fi
		else
			# we're in a cluster, but scstat is not available
			printf "In clustered environment.\n"
			printf "Required configuration file, $DSCFG_LOCKDB\n"
			printf "was not properly populated with the cluster "
			printf "nodenames.\nThis file needs to be manually"
			printf "updated with the cluster\nnodenames before "
			printf "reboot.  Refer to Sun Storage Availability\n"
			printf "Suite Installation Guide for details.\n"
		fi

		# clustered start of dscfglockd
		if [ -f $DSCFG_LOCKDB ]
		then
			printf "Starting dscfglockd\n"
			${SCMLIB}/dscfglockd -f $DSCFG_LOCKDB
		else
			printf "WARNING: Mis-Configuration of Availability "
			printf "Suite for Sun Cluster\n"
			printf "WARNING: Can't find configuration file for "
			printf "dscfglockd\n"
		fi

		rm -f $NODELIST
	fi
  
}

do_sdbc ()
{
      ${SCMBIN}/scmadm  -e
}


do_start ()
{
  # do nothing if we do not have a dscfg
  if [ ! -f /etc/dscfg_local ]
  then
      echo "Cannot find Availability Suite configuration location"
      exit $SMF_EXIT_ERR_NOSMF
  fi

  #
  # Ordering:
  #	dscfglockd	-- locking must be present before any dscfg access
  #	nskernd		-- starts infrastructure (nskernd, ncall).
  #	sdbc		-- start the cache itself
  #
  do_dscfglockd
  do_nskernd
  do_sdbc
}


do_usage ()
{
  echo "Usage: $0"
  echo "   start"
  echo "   stop"
  exit 1
}

set_system_type

USED=0
ACTION=
CLUSTERTAG=

case $# in 
'0')
     do_usage
     ;;
'1') 
     ACTION=$1
     USED=1
     ;;
'2')
     ACTION=$1
     CLUSTERTAG="$2"
     USED=1
     exit 0
     ;;
'*')
     do_usage
     ;;
esac

if [ $USED = 0 ] ; then
     do_usage
fi

if [ $ACTION = "start" ] ; then
  do_start
elif [ $ACTION = "stop" ] ; then
  do_stop
else 
  do_usage
fi

exit $SMF_EXIT_OK