xref: /titanic_53/usr/src/cmd/avs/dscfg/dscfgadm.sh (revision fcf3ce441efd61da9bb2884968af01cb7c1452cc)
1*fcf3ce44SJohn Forte#!/usr/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 Fortetypeset -r PROG=$(basename $0)
27*fcf3ce44SJohn Fortetypeset -r CTAG_NULL="-"
28*fcf3ce44SJohn Forte
29*fcf3ce44SJohn Forte#
30*fcf3ce44SJohn Forte# help message
31*fcf3ce44SJohn Forte#
32*fcf3ce44SJohn Fortehelp()
33*fcf3ce44SJohn Forte{
34*fcf3ce44SJohn Forte	$xopt
35*fcf3ce44SJohn Forte
36*fcf3ce44SJohn Forte	cluster_configured
37*fcf3ce44SJohn Forte	CLUSTER_CONFIGURED=$?
38*fcf3ce44SJohn Forte
39*fcf3ce44SJohn Forte	echo "\
40*fcf3ce44SJohn Forteusage:
41*fcf3ce44SJohn Forte	$PROG
42*fcf3ce44SJohn Forte	$PROG -i
43*fcf3ce44SJohn Forte	$PROG -e [-r][-p]
44*fcf3ce44SJohn Forte	$PROG -d [-r]" >&2
45*fcf3ce44SJohn Forte	if [ $CLUSTER_CONFIGURED -eq 1 ]; then
46*fcf3ce44SJohn Forte		echo "\
47*fcf3ce44SJohn Forte	$PROG -s" >&2
48*fcf3ce44SJohn Forte	fi
49*fcf3ce44SJohn Forte
50*fcf3ce44SJohn Forte	echo "\
51*fcf3ce44SJohn Forte	-i	: display information on the Availability Suite services
52*fcf3ce44SJohn Forte	-e	: enable Availability Suite services (all, by default)
53*fcf3ce44SJohn Forte	-d	: disable Availability Suite services (all, by default)
54*fcf3ce44SJohn Forte	-r	: enable/disable Remote Mirror
55*fcf3ce44SJohn Forte	-p	: enable Point in Time Copy" >&2
56*fcf3ce44SJohn Forte	if [ $CLUSTER_CONFIGURED -eq 1 ]; then
57*fcf3ce44SJohn Forte		echo "\
58*fcf3ce44SJohn Forte	-s	: set the location of the cluster configuration database" >&2
59*fcf3ce44SJohn Forte	fi
60*fcf3ce44SJohn Forte	echo "\
61*fcf3ce44SJohn Forte	-x	: turn on script debugging (may be used with any valid option)
62*fcf3ce44SJohn Forte
63*fcf3ce44SJohn Forte	 When executed with no options or with nothing but -x, $PROG runs in
64*fcf3ce44SJohn Forte	 interactive fashion, allowing the user to initialize the local (and
65*fcf3ce44SJohn Forte	 if applicable, the cluster) configuration database, and to start the
66*fcf3ce44SJohn Forte	 Availability Suite services." >&2
67*fcf3ce44SJohn Forte
68*fcf3ce44SJohn Forte	exit 2
69*fcf3ce44SJohn Forte}
70*fcf3ce44SJohn Forte
71*fcf3ce44SJohn Forte########################## SET GLOBAL VARIABLES ######################
72*fcf3ce44SJohn Forte
73*fcf3ce44SJohn Forte# root directory
74*fcf3ce44SJohn FortePKG_INSTALL_ROOT=""
75*fcf3ce44SJohn Forteexport PKG_INSTALL_ROOT
76*fcf3ce44SJohn Forte
77*fcf3ce44SJohn Forte# set lib path
78*fcf3ce44SJohn ForteLD_LIBRARY_PATH=/usr/lib:/usr/lib
79*fcf3ce44SJohn Forteexport LD_LIBRARY_PATH
80*fcf3ce44SJohn Forte
81*fcf3ce44SJohn Forte# set dscfg
82*fcf3ce44SJohn ForteDSCFG="/usr/sbin/dscfg"
83*fcf3ce44SJohn Forteexport DSCFG
84*fcf3ce44SJohn Forte
85*fcf3ce44SJohn Forte# set parser config location
86*fcf3ce44SJohn FortePCONFIG="/etc/dscfg_format"
87*fcf3ce44SJohn Forteexport PCONFIG
88*fcf3ce44SJohn Forte
89*fcf3ce44SJohn Forte# set local dscfg location
90*fcf3ce44SJohn Forteexport LOCAL_DSCFG="/etc/dscfg_local"
91*fcf3ce44SJohn Forte
92*fcf3ce44SJohn Forte# set cluster dscfg reference file
93*fcf3ce44SJohn Forteexport CLUSTER_REF="/etc/dscfg_cluster"
94*fcf3ce44SJohn Forte
95*fcf3ce44SJohn Forte# a service that has a dependency on us
96*fcf3ce44SJohn ForteFS_LOCAL_SVC="svc:/system/filesystem/local"
97*fcf3ce44SJohn Forte
98*fcf3ce44SJohn ForteNODELIST="/tmp/nodelist"
99*fcf3ce44SJohn ForteDSCFGLOCKDCF="/etc/dscfg_lockdb"
100*fcf3ce44SJohn ForteDSCFG_DEPEND_NOCHK="/tmp/.dscfgadm_pid"
101*fcf3ce44SJohn Forte
102*fcf3ce44SJohn Forte# SMF defines
103*fcf3ce44SJohn ForteMANIFEST_PATH=/var/svc/manifest/system
104*fcf3ce44SJohn Forte
105*fcf3ce44SJohn Forte# SMF services (enable and disable)
106*fcf3ce44SJohn ForteSMF_ENABLE="nws_scm nws_sv nws_ii nws_rdc nws_rdcsyncd"
107*fcf3ce44SJohn ForteSMF_DISABLE="nws_rdcsyncd nws_rdc nws_ii nws_sv nws_scm"
108*fcf3ce44SJohn Forte
109*fcf3ce44SJohn Forte# state of each service
110*fcf3ce44SJohn Fortenws_scm_enabled=0
111*fcf3ce44SJohn Fortenws_sv_enabled=0
112*fcf3ce44SJohn Fortenws_ii_enabled=0
113*fcf3ce44SJohn Fortenws_rdc_enabled=0
114*fcf3ce44SJohn Fortenws_rdcsyncd_enabled=0
115*fcf3ce44SJohn Forte
116*fcf3ce44SJohn Forte# set path
117*fcf3ce44SJohn FortePATH=/usr/bin:/usr/sbin:/sbin/sh
118*fcf3ce44SJohn Forteexport PATH
119*fcf3ce44SJohn Forte
120*fcf3ce44SJohn Forte# set architecture
121*fcf3ce44SJohn ForteARCH=`uname -p`
122*fcf3ce44SJohn Forteexport ARCH
123*fcf3ce44SJohn ForteOS_MINOR=`uname -r | cut -d '.' -f2`
124*fcf3ce44SJohn Forte
125*fcf3ce44SJohn Forte# number of sectors required for database
126*fcf3ce44SJohn Forte# 1024*1024*5.5/512
127*fcf3ce44SJohn ForteREQUIRED=11264
128*fcf3ce44SJohn Forte
129*fcf3ce44SJohn Forte# must set here, else seen as null in MAIN
130*fcf3ce44SJohn ForteVALID_DB_ENTERED=0
131*fcf3ce44SJohn Forte
132*fcf3ce44SJohn ForteNO_ARGS=0
133*fcf3ce44SJohn Forte
134*fcf3ce44SJohn Forte# for debugging
135*fcf3ce44SJohn Fortexopt=
136*fcf3ce44SJohn Forte
137*fcf3ce44SJohn Forte# set lengthy message here
138*fcf3ce44SJohn ForteCLUST_LOC_MESS="The current location is invalid for a Sun StorageTek \
139*fcf3ce44SJohn ForteData Services configuration database.  Once a valid location is \
140*fcf3ce44SJohn Forteentered (raw slice on \"did\" device), you may upgrade the existing \
141*fcf3ce44SJohn Fortedatabase to this new location - following the procedure outlined \
142*fcf3ce44SJohn Fortein the Installation and Configuration Guide."
143*fcf3ce44SJohn Forte
144*fcf3ce44SJohn Forte########################## SET GLOBAL VARIABLES ######################
145*fcf3ce44SJohn Forte
146*fcf3ce44SJohn Forte
147*fcf3ce44SJohn Forte########################## ERROR  ####################################
148*fcf3ce44SJohn Forte
149*fcf3ce44SJohn Forte# called with optional error msg $1
150*fcf3ce44SJohn Forte# prints basic guidelines for configuration of the database location
151*fcf3ce44SJohn Forteerror()
152*fcf3ce44SJohn Forte{
153*fcf3ce44SJohn Forte    $xopt
154*fcf3ce44SJohn Forte
155*fcf3ce44SJohn Forte    echo >&2
156*fcf3ce44SJohn Forte    echo "INSTALLATION ERROR" >&2
157*fcf3ce44SJohn Forte    echo "Error: $1" >&2
158*fcf3ce44SJohn Forte    echo >&2
159*fcf3ce44SJohn Forte    in_cluster
160*fcf3ce44SJohn Forte
161*fcf3ce44SJohn Forte    if [ $? -eq 1 ]; then
162*fcf3ce44SJohn Forte	echo "GENERAL INSTALLATION RULES:" >&2
163*fcf3ce44SJohn Forte	echo "\tBecause you are installing on a cluster," >&2
164*fcf3ce44SJohn Forte	echo "\tthe database must be located on a raw slice of a did device.">&2
165*fcf3ce44SJohn Forte	echo "\t  e.g. /dev/did/rdsk/d17s1" >&2
166*fcf3ce44SJohn Forte    fi
167*fcf3ce44SJohn Forte    # let?
168*fcf3ce44SJohn Forte    MB=`expr $REQUIRED / 2 / 1024`
169*fcf3ce44SJohn Forte    echo "\t$REQUIRED sectors ($MB MBs) are required for the database." >&2
170*fcf3ce44SJohn Forte}
171*fcf3ce44SJohn Forte
172*fcf3ce44SJohn Forte########################## ERROR  ####################################
173*fcf3ce44SJohn Forte
174*fcf3ce44SJohn Forte########################## ALL LOCATION TESTS ########################
175*fcf3ce44SJohn Forte
176*fcf3ce44SJohn Forte# sets numerous environment variables describing the state of the system
177*fcf3ce44SJohn Forteget_system_state()
178*fcf3ce44SJohn Forte{
179*fcf3ce44SJohn Forte	$xopt
180*fcf3ce44SJohn Forte
181*fcf3ce44SJohn Forte	valid_local_dscfg_exists
182*fcf3ce44SJohn Forte	VALID_LOCAL_DB=$?
183*fcf3ce44SJohn Forte	OLD_VALID_LOCAL_DB=$VALID_LOCAL_DB
184*fcf3ce44SJohn Forte
185*fcf3ce44SJohn Forte	in_cluster
186*fcf3ce44SJohn Forte	IN_CLUSTER=$?
187*fcf3ce44SJohn Forte
188*fcf3ce44SJohn Forte	cluster_configured
189*fcf3ce44SJohn Forte	CLUSTER_CONFIGURED=$?
190*fcf3ce44SJohn Forte
191*fcf3ce44SJohn Forte	if [ $IN_CLUSTER = 1 ]; then
192*fcf3ce44SJohn Forte		valid_cluster_dscfg_exists
193*fcf3ce44SJohn Forte		VALID_CLUSTER_DB=$?
194*fcf3ce44SJohn Forte		OLD_VALID_CLUSTER_DB=$VALID_CLUSTER_DB
195*fcf3ce44SJohn Forte	else
196*fcf3ce44SJohn Forte		VALID_CLUSTER_DB=0
197*fcf3ce44SJohn Forte	fi
198*fcf3ce44SJohn Forte}
199*fcf3ce44SJohn Forte
200*fcf3ce44SJohn Forte# Checks if in cluster
201*fcf3ce44SJohn Forte# returns 1 if in cluster, else 0
202*fcf3ce44SJohn Forte#
203*fcf3ce44SJohn Fortein_cluster()
204*fcf3ce44SJohn Forte{
205*fcf3ce44SJohn Forte    $xopt
206*fcf3ce44SJohn Forte
207*fcf3ce44SJohn Forte    if [ -x /usr/sbin/clinfo ]; then
208*fcf3ce44SJohn Forte	    clinfo
209*fcf3ce44SJohn Forte	if [ $? -eq 0 ]; then
210*fcf3ce44SJohn Forte            return 1
211*fcf3ce44SJohn Forte	else
212*fcf3ce44SJohn Forte	    return 0
213*fcf3ce44SJohn Forte	fi
214*fcf3ce44SJohn Forte    else
215*fcf3ce44SJohn Forte        return 0
216*fcf3ce44SJohn Forte    fi
217*fcf3ce44SJohn Forte}
218*fcf3ce44SJohn Forte
219*fcf3ce44SJohn Forte# checks if a system is configured as a cluster
220*fcf3ce44SJohn Forte# returns 1 if configured as a cluster, 0 if not
221*fcf3ce44SJohn Forte#
222*fcf3ce44SJohn Fortecluster_configured()
223*fcf3ce44SJohn Forte{
224*fcf3ce44SJohn Forte    $xopt
225*fcf3ce44SJohn Forte
226*fcf3ce44SJohn Forte    if [ -f /etc/cluster/nodeid ]; then
227*fcf3ce44SJohn Forte	return 1
228*fcf3ce44SJohn Forte    else
229*fcf3ce44SJohn Forte	return 0
230*fcf3ce44SJohn Forte    fi
231*fcf3ce44SJohn Forte}
232*fcf3ce44SJohn Forte
233*fcf3ce44SJohn Forte# Check the list of Sun Cluster device groups known in the dscfg, determing
234*fcf3ce44SJohn Forte# if they are currently enabled on this Sun Cluster node. If so, fail allowing
235*fcf3ce44SJohn Forte# the system administator to scswitch them elsewhere.
236*fcf3ce44SJohn Forte#
237*fcf3ce44SJohn Fortecheck_device_groups()
238*fcf3ce44SJohn Forte{
239*fcf3ce44SJohn Forte	$xopt
240*fcf3ce44SJohn Forte
241*fcf3ce44SJohn Forte	if [ $VALID_CLUSTER_DB == 1 ]; then
242*fcf3ce44SJohn Forte		DEVICE_GROUPS=`$DSCFG -s $FILE_LOC -l 2>/dev/null | \
243*fcf3ce44SJohn Forte		grep "^dsvol:" | cut -d' ' -f3 | sort | uniq | xargs`
244*fcf3ce44SJohn Forte		for x in $DEVICE_GROUPS
245*fcf3ce44SJohn Forte		do
246*fcf3ce44SJohn Forte			$DSCFG -D $x 2>/dev/null
247*fcf3ce44SJohn Forte			if [ $? -eq 1 ]
248*fcf3ce44SJohn Forte			then
249*fcf3ce44SJohn Forte				IN_USE="$IN_USE $x"
250*fcf3ce44SJohn Forte			fi
251*fcf3ce44SJohn Forte		done
252*fcf3ce44SJohn Forte
253*fcf3ce44SJohn Forte		if [ -n "$IN_USE" ]
254*fcf3ce44SJohn Forte		then
255*fcf3ce44SJohn Forte		    print "The following Sun Cluster device groups are in use "
256*fcf3ce44SJohn Forte		    print "by Availability Suite on this node."
257*fcf3ce44SJohn Forte		    print ""
258*fcf3ce44SJohn Forte		    print "$IN_USE"
259*fcf3ce44SJohn Forte		    print ""
260*fcf3ce44SJohn Forte		    print "'scswitch' them to another Sun Cluster node before "
261*fcf3ce44SJohn Forte		    print "attempting to disable any data services."
262*fcf3ce44SJohn Forte		    return 1
263*fcf3ce44SJohn Forte		else
264*fcf3ce44SJohn Forte		    return 0
265*fcf3ce44SJohn Forte		fi
266*fcf3ce44SJohn Forte	fi
267*fcf3ce44SJohn Forte
268*fcf3ce44SJohn Forte	return 0
269*fcf3ce44SJohn Forte}
270*fcf3ce44SJohn Forte
271*fcf3ce44SJohn Forte# checks to see if this is a char device in the
272*fcf3ce44SJohn Forte# /dev/did/rdsk directory returns 1 if so.
273*fcf3ce44SJohn Forte#
274*fcf3ce44SJohn Forteis_did_device()
275*fcf3ce44SJohn Forte{
276*fcf3ce44SJohn Forte	$xopt
277*fcf3ce44SJohn Forte
278*fcf3ce44SJohn Forte	DID=`echo $1 | awk -F/ '{print $3}'`
279*fcf3ce44SJohn Forte	RDSK=`echo $1 | awk -F/ '{print $4}'`
280*fcf3ce44SJohn Forte
281*fcf3ce44SJohn Forte	if [ "did" = $DID -a "rdsk" = $RDSK -a -c $1 ]; then
282*fcf3ce44SJohn Forte		return 1
283*fcf3ce44SJohn Forte	else
284*fcf3ce44SJohn Forte		return 0
285*fcf3ce44SJohn Forte	fi
286*fcf3ce44SJohn Forte}
287*fcf3ce44SJohn Forte
288*fcf3ce44SJohn Forte#
289*fcf3ce44SJohn Forte# checks size of area for db location
290*fcf3ce44SJohn Forte#
291*fcf3ce44SJohn Fortecheck_size()
292*fcf3ce44SJohn Forte{
293*fcf3ce44SJohn Forte	$xopt
294*fcf3ce44SJohn Forte
295*fcf3ce44SJohn Forte	# if in cluster look for d*s*
296*fcf3ce44SJohn Forte	SLICE=`echo $1 | sed -n 's/.*d.*s\(.*\)/\1/p'`
297*fcf3ce44SJohn Forte
298*fcf3ce44SJohn Forte	SECTORS=`prtvtoc $1 | tr -s ' '| grep "^ $SLICE " | awk '{print $5}'`
299*fcf3ce44SJohn Forte
300*fcf3ce44SJohn Forte	if [ -z "$SECTORS" ]; then
301*fcf3ce44SJohn Forte            echo "SLICE at $1 not found on this device"
302*fcf3ce44SJohn Forte            return 0
303*fcf3ce44SJohn Forte	fi
304*fcf3ce44SJohn Forte
305*fcf3ce44SJohn Forte	# if required size is greater than space available, then fail
306*fcf3ce44SJohn Forte	if [ $REQUIRED -gt $SECTORS ]; then
307*fcf3ce44SJohn Forte		return 0
308*fcf3ce44SJohn Forte	else
309*fcf3ce44SJohn Forte		return 1
310*fcf3ce44SJohn Forte	fi
311*fcf3ce44SJohn Forte}
312*fcf3ce44SJohn Forte
313*fcf3ce44SJohn Forte# looks in dscfg_cluster reference file.  if a location is configured,
314*fcf3ce44SJohn Forte# tests to see if it is a valid database.  if so, returns 1
315*fcf3ce44SJohn Forte#
316*fcf3ce44SJohn Fortevalid_cluster_dscfg_exists()
317*fcf3ce44SJohn Forte{
318*fcf3ce44SJohn Forte    $xopt
319*fcf3ce44SJohn Forte
320*fcf3ce44SJohn Forte    if [ -s $CLUSTER_REF ]; then
321*fcf3ce44SJohn Forte	FILE_LOC=`head -1 $CLUSTER_REF`
322*fcf3ce44SJohn Forte	contains_data $FILE_LOC
323*fcf3ce44SJohn Forte	return $?
324*fcf3ce44SJohn Forte    else
325*fcf3ce44SJohn Forte	return 0
326*fcf3ce44SJohn Forte    fi
327*fcf3ce44SJohn Forte}
328*fcf3ce44SJohn Forte
329*fcf3ce44SJohn Forte
330*fcf3ce44SJohn Forte# checks for the existence of dscfg_local database, and if it exists,
331*fcf3ce44SJohn Forte# tests to see if it is a valid database.  if so, returns 1
332*fcf3ce44SJohn Forte#
333*fcf3ce44SJohn Fortevalid_local_dscfg_exists()
334*fcf3ce44SJohn Forte{
335*fcf3ce44SJohn Forte    $xopt
336*fcf3ce44SJohn Forte
337*fcf3ce44SJohn Forte    if [ -s $LOCAL_DSCFG ]; then
338*fcf3ce44SJohn Forte	contains_data $LOCAL_DSCFG
339*fcf3ce44SJohn Forte	return $?
340*fcf3ce44SJohn Forte    else
341*fcf3ce44SJohn Forte       return 0
342*fcf3ce44SJohn Forte    fi
343*fcf3ce44SJohn Forte}
344*fcf3ce44SJohn Forte
345*fcf3ce44SJohn Forte# used to test if a valid DS config database exists on machine already
346*fcf3ce44SJohn Forte# MAGIC_STRING is the top line in the config used in v3.1 & v3.2
347*fcf3ce44SJohn Forte#
348*fcf3ce44SJohn Fortecontains_data()
349*fcf3ce44SJohn Forte{
350*fcf3ce44SJohn Forte    $xopt
351*fcf3ce44SJohn Forte
352*fcf3ce44SJohn Forte    # dscfg distinct strings, varies on the architecture
353*fcf3ce44SJohn Forte    if [ $ARCH = "sparc" ]
354*fcf3ce44SJohn Forte    then
355*fcf3ce44SJohn Forte	MAGIC_STRING="MAGI"
356*fcf3ce44SJohn Forte    elif [ $ARCH = "i386" ]
357*fcf3ce44SJohn Forte    then
358*fcf3ce44SJohn Forte	MAGIC_STRING="IGAM"
359*fcf3ce44SJohn Forte    fi
360*fcf3ce44SJohn Forte
361*fcf3ce44SJohn Forte    # Create a PID unique temporary file
362*fcf3ce44SJohn Forte    TMP_FILE=/tmp/$$
363*fcf3ce44SJohn Forte
364*fcf3ce44SJohn Forte    # Write the first or 16th block (skipping over VTOC) to
365*fcf3ce44SJohn Forte    # the TMP_FILE, then scan for the presence of the "MAGI"
366*fcf3ce44SJohn Forte    #
367*fcf3ce44SJohn Forte    for offset in 0 16
368*fcf3ce44SJohn Forte    do
369*fcf3ce44SJohn Forte	if [ ! -z "$1" ]; then
370*fcf3ce44SJohn Forte	    dd if=$1 of=$TMP_FILE count=1 iseek=$offset 2>/dev/null
371*fcf3ce44SJohn Forte	    FILECONTENTS=`strings $TMP_FILE | head -1 2>/dev/null`
372*fcf3ce44SJohn Forte	    if [ `echo $FILECONTENTS | grep -c "$MAGIC_STRING"` -gt 0 ]; then
373*fcf3ce44SJohn Forte		rm $TMP_FILE
374*fcf3ce44SJohn Forte		return 1
375*fcf3ce44SJohn Forte	    fi
376*fcf3ce44SJohn Forte	fi
377*fcf3ce44SJohn Forte    done
378*fcf3ce44SJohn Forte
379*fcf3ce44SJohn Forte    rm $TMP_FILE
380*fcf3ce44SJohn Forte    return 0
381*fcf3ce44SJohn Forte}
382*fcf3ce44SJohn Forte
383*fcf3ce44SJohn Forte########################## ALL LOCATION TESTS ########################
384*fcf3ce44SJohn Forte
385*fcf3ce44SJohn Forte
386*fcf3ce44SJohn Forte########################## MAIN FUNCTIONS ############################
387*fcf3ce44SJohn Forte
388*fcf3ce44SJohn Forte# since location already has been set, asks what to do now?  keeping
389*fcf3ce44SJohn Forte# it still checks the size (since an upgrade from 3.0 may still be
390*fcf3ce44SJohn Forte# occuring) and also checks if was an old cluster config on disallowed
391*fcf3ce44SJohn Forte# /dev/did/dsk directory
392*fcf3ce44SJohn Forte#
393*fcf3ce44SJohn Forte# returns:
394*fcf3ce44SJohn Forte#	0 if cluster location is invalid or the user does not want to keep it
395*fcf3ce44SJohn Forte#	1 if the location is valid and the user wants to keep it.
396*fcf3ce44SJohn Forte#
397*fcf3ce44SJohn Fortekeep_it()
398*fcf3ce44SJohn Forte{
399*fcf3ce44SJohn Forte    $xopt
400*fcf3ce44SJohn Forte
401*fcf3ce44SJohn Forte    NOTE="\nThe Sun StorageTek Data Services database configuration"
402*fcf3ce44SJohn Forte    NOTE="$NOTE location has already been set."
403*fcf3ce44SJohn Forte    echo $NOTE
404*fcf3ce44SJohn Forte
405*fcf3ce44SJohn Forte    echo "\nCurrent location: $PKG_INSTALL_ROOT$FILE_LOC"
406*fcf3ce44SJohn Forte
407*fcf3ce44SJohn Forte    QUEST="Would you like to preserve the existing configuration"
408*fcf3ce44SJohn Forte    QUEST="$QUEST information at its current location? "
409*fcf3ce44SJohn Forte
410*fcf3ce44SJohn Forte    ANS=`ckyorn -Qd n -p "$QUEST"`
411*fcf3ce44SJohn Forte
412*fcf3ce44SJohn Forte    case $ANS in
413*fcf3ce44SJohn Forte	y|Y|yes|YES|Yes)
414*fcf3ce44SJohn Forte            #Since the user has said "yes I want to keep this current one"
415*fcf3ce44SJohn Forte            #it may actually be a 3.x database, which only required 4.5mb
416*fcf3ce44SJohn Forte            #space, so now will check that there is room to grow another 1mb"
417*fcf3ce44SJohn Forte	    check_location $FILE_LOC
418*fcf3ce44SJohn Forte            if [ $? = 0 ]; then
419*fcf3ce44SJohn Forte		error "$CLUST_LOC_MESS"
420*fcf3ce44SJohn Forte		return 0
421*fcf3ce44SJohn Forte	    else
422*fcf3ce44SJohn Forte		OLD_FILE_LOC=$FILE_LOC
423*fcf3ce44SJohn Forte		FILE_LOC=$NULL
424*fcf3ce44SJohn Forte		return 1
425*fcf3ce44SJohn Forte	    fi
426*fcf3ce44SJohn Forte            ;;
427*fcf3ce44SJohn Forte	*)
428*fcf3ce44SJohn Forte            return 0
429*fcf3ce44SJohn Forte            ;;
430*fcf3ce44SJohn Forte    esac
431*fcf3ce44SJohn Forte}
432*fcf3ce44SJohn Forte
433*fcf3ce44SJohn Forte#
434*fcf3ce44SJohn Forte# asks if user wants to keep existing db information, overwrite with
435*fcf3ce44SJohn Forte# a new db, or view the contents, and be asked again...
436*fcf3ce44SJohn Forte# returns:
437*fcf3ce44SJohn Forte#	0 if old location is bad
438*fcf3ce44SJohn Forte#	1 if old location is good
439*fcf3ce44SJohn Forte#
440*fcf3ce44SJohn Fortepreserve_overwrite_maybe()
441*fcf3ce44SJohn Forte{
442*fcf3ce44SJohn Forte    $xopt
443*fcf3ce44SJohn Forte
444*fcf3ce44SJohn Forte    echo "\nIt appears a valid database configuration exists here already."
445*fcf3ce44SJohn Forte
446*fcf3ce44SJohn Forte    while true
447*fcf3ce44SJohn Forte    do
448*fcf3ce44SJohn Forte      SAFE_LOC=$FILE_LOC
449*fcf3ce44SJohn Forte
450*fcf3ce44SJohn Forte	echo "\nWould you like to preserve this information and continue?"
451*fcf3ce44SJohn Forte	echo "\ty - preserve current configuration"
452*fcf3ce44SJohn Forte	echo "\tn - overwrite with new configuration"
453*fcf3ce44SJohn Forte	echo "\tmaybe - view contents of current configuration"
454*fcf3ce44SJohn Forte
455*fcf3ce44SJohn Forte	ANS=`ckkeywd -Q y n maybe`
456*fcf3ce44SJohn Forte	case $ANS in
457*fcf3ce44SJohn Forte	  y)
458*fcf3ce44SJohn Forte		check_location $FILE_LOC
459*fcf3ce44SJohn Forte		if [ $? = 0 ]; then
460*fcf3ce44SJohn Forte			error "$CLUST_LOC_MESS"
461*fcf3ce44SJohn Forte			return 0
462*fcf3ce44SJohn Forte		else
463*fcf3ce44SJohn Forte			$DSCFG -s "$FILE_LOC" -C $CTAG_NULL >/dev/null 2>&1
464*fcf3ce44SJohn Forte			OLD_FILE_LOC=$FILE_LOC
465*fcf3ce44SJohn Forte			FILE_LOC=$NULL
466*fcf3ce44SJohn Forte			return 1
467*fcf3ce44SJohn Forte		fi
468*fcf3ce44SJohn Forte		;;
469*fcf3ce44SJohn Forte	  n)
470*fcf3ce44SJohn Forte		check_location $FILE_LOC
471*fcf3ce44SJohn Forte		if [ $? = 0 ]; then
472*fcf3ce44SJohn Forte			error "$CLUST_LOC_MESS"
473*fcf3ce44SJohn Forte			return 0
474*fcf3ce44SJohn Forte		else
475*fcf3ce44SJohn Forte			return 1
476*fcf3ce44SJohn Forte		fi
477*fcf3ce44SJohn Forte		;;
478*fcf3ce44SJohn Forte
479*fcf3ce44SJohn Forte	  maybe)
480*fcf3ce44SJohn Forte		# print contents of this db config.
481*fcf3ce44SJohn Forte		echo "\nContents of database configuration found at $SAFE_LOC are:"
482*fcf3ce44SJohn Forte 		$DSCFG -l -s "$FILE_LOC" | more
483*fcf3ce44SJohn Forte		FILE_LOC=$SAFE_LOC
484*fcf3ce44SJohn Forte		continue
485*fcf3ce44SJohn Forte              ;;
486*fcf3ce44SJohn Forte	esac
487*fcf3ce44SJohn Forte    done
488*fcf3ce44SJohn Forte}
489*fcf3ce44SJohn Forte
490*fcf3ce44SJohn Forte# gets location from user
491*fcf3ce44SJohn Forte#
492*fcf3ce44SJohn Forteget_location()
493*fcf3ce44SJohn Forte{
494*fcf3ce44SJohn Forte    $xopt
495*fcf3ce44SJohn Forte
496*fcf3ce44SJohn Forte    #Checks for absolute path name, and if file name and file doesn't
497*fcf3ce44SJohn Forte    #exist, creates it.
498*fcf3ce44SJohn Forte    echo "\n\n----------ENTER DATABASE CONFIGURATION LOCATION-----------------"
499*fcf3ce44SJohn Forte    echo "Note:	 Please ensure this location meets all requirements specified"
500*fcf3ce44SJohn Forte    echo "in the Availability Suite Installation Guide."
501*fcf3ce44SJohn Forte
502*fcf3ce44SJohn Forte    FILE_LOC=`ckpath -artwQ -p "Enter location:"`
503*fcf3ce44SJohn Forte    if [ $? = 1 ]
504*fcf3ce44SJohn Forte	then
505*fcf3ce44SJohn Forte	    exit 1
506*fcf3ce44SJohn Forte	fi
507*fcf3ce44SJohn Forte
508*fcf3ce44SJohn Forte    # allow non-root user to access for least privileges
509*fcf3ce44SJohn Forte    chmod 666 $FILE_LOC
510*fcf3ce44SJohn Forte}
511*fcf3ce44SJohn Forte
512*fcf3ce44SJohn Forte
513*fcf3ce44SJohn Forte#
514*fcf3ce44SJohn Forte# tests for proper config
515*fcf3ce44SJohn Forte#
516*fcf3ce44SJohn Forte# returns:
517*fcf3ce44SJohn Forte#	0 if bad location
518*fcf3ce44SJohn Forte#	1 if good location
519*fcf3ce44SJohn Forte#
520*fcf3ce44SJohn Fortecheck_location()
521*fcf3ce44SJohn Forte{
522*fcf3ce44SJohn Forte	$xopt
523*fcf3ce44SJohn Forte
524*fcf3ce44SJohn Forte	# set to FILE_LOC
525*fcf3ce44SJohn Forte	LOCATION=$1
526*fcf3ce44SJohn Forte
527*fcf3ce44SJohn Forte	did_clust_msg="You are in cluster and $LOCATION is not valid DID device"
528*fcf3ce44SJohn Forte
529*fcf3ce44SJohn Forte	# Set "actual file location" variable here to equal file location
530*fcf3ce44SJohn Forte	# entered by user because getting here means contains_data was already
531*fcf3ce44SJohn Forte	# successfully called before and now the two can equal each other for
532*fcf3ce44SJohn Forte	# future testing.
533*fcf3ce44SJohn Forte
534*fcf3ce44SJohn Forte	SAFE_LOC=$FILE_LOC
535*fcf3ce44SJohn Forte
536*fcf3ce44SJohn Forte	if [ $IN_CLUSTER = 1 -o $CLUSTER_CONFIGURED = 1 ]; then
537*fcf3ce44SJohn Forte		if [ -b "$LOCATION" ] || [ -c "$LOCATION" ]; then
538*fcf3ce44SJohn Forte			is_did_device $LOCATION
539*fcf3ce44SJohn Forte			if [ $? = 0 ]; then
540*fcf3ce44SJohn Forte				error "$did_clust_msg"
541*fcf3ce44SJohn Forte				return 0
542*fcf3ce44SJohn Forte			fi
543*fcf3ce44SJohn Forte		else
544*fcf3ce44SJohn Forte			error "$did_clust_msg"
545*fcf3ce44SJohn Forte			return 0
546*fcf3ce44SJohn Forte		fi
547*fcf3ce44SJohn Forte	else
548*fcf3ce44SJohn Forte		echo "Location may not be changed in a non Sun Cluster OE." 2>&1
549*fcf3ce44SJohn Forte		return 0
550*fcf3ce44SJohn Forte	fi
551*fcf3ce44SJohn Forte
552*fcf3ce44SJohn Forte	check_size $LOCATION
553*fcf3ce44SJohn Forte
554*fcf3ce44SJohn Forte	if [ $? != 1 ]; then
555*fcf3ce44SJohn Forte		error "$LOCATION does not meet minimum space requirement."
556*fcf3ce44SJohn Forte		return 0
557*fcf3ce44SJohn Forte	else
558*fcf3ce44SJohn Forte		return 1
559*fcf3ce44SJohn Forte	fi
560*fcf3ce44SJohn Forte}
561*fcf3ce44SJohn Forte
562*fcf3ce44SJohn Forte#
563*fcf3ce44SJohn Forte# Notifies the user that the SMF services are online,
564*fcf3ce44SJohn Forte# and gives him the option to disable the services before proceeding.  If
565*fcf3ce44SJohn Forte# the services are not disabled, the program cannot proceed with setting
566*fcf3ce44SJohn Forte# a new dscfg location.
567*fcf3ce44SJohn Forte#
568*fcf3ce44SJohn Forteask_to_disable()
569*fcf3ce44SJohn Forte{
570*fcf3ce44SJohn Forte    $xopt
571*fcf3ce44SJohn Forte
572*fcf3ce44SJohn Forte    echo "\
573*fcf3ce44SJohn Forte\nYour services must be disabled before a new configuration location is set.\n"
574*fcf3ce44SJohn Forte
575*fcf3ce44SJohn Forte    QUEST="Would you like to disable the services now and continue with the"
576*fcf3ce44SJohn Forte    QUEST="$QUEST Availability Suite setup? "
577*fcf3ce44SJohn Forte
578*fcf3ce44SJohn Forte    ANS=`ckyorn -Qd n -p "$QUEST"`
579*fcf3ce44SJohn Forte
580*fcf3ce44SJohn Forte    case $ANS
581*fcf3ce44SJohn Forte	in y|Y|yes|YES|Yes)
582*fcf3ce44SJohn Forte	    return 1
583*fcf3ce44SJohn Forte	    ;;
584*fcf3ce44SJohn Forte	*)
585*fcf3ce44SJohn Forte            return 0
586*fcf3ce44SJohn Forte            ;;
587*fcf3ce44SJohn Forte    esac
588*fcf3ce44SJohn Forte}
589*fcf3ce44SJohn Forte
590*fcf3ce44SJohn Forte#
591*fcf3ce44SJohn Forte# Asks the user if he would like to enable the services now.  If so,
592*fcf3ce44SJohn Forte# import them (if necessary) and enable them.
593*fcf3ce44SJohn Forte#
594*fcf3ce44SJohn Forteask_to_enable()
595*fcf3ce44SJohn Forte{
596*fcf3ce44SJohn Forte    $xopt
597*fcf3ce44SJohn Forte
598*fcf3ce44SJohn Forte    echo "\
599*fcf3ce44SJohn Forte\nIf you would like to start using the Availability Suite immediately, you may
600*fcf3ce44SJohn Fortestart the SMF services now.  You may also choose to start the services later
601*fcf3ce44SJohn Forteusing the $PROG -e command."
602*fcf3ce44SJohn Forte
603*fcf3ce44SJohn Forte    QUEST="Would you like to start the services now? "
604*fcf3ce44SJohn Forte
605*fcf3ce44SJohn Forte    ANS=`ckyorn -Qd n -p "$QUEST"`
606*fcf3ce44SJohn Forte
607*fcf3ce44SJohn Forte    case $ANS
608*fcf3ce44SJohn Forte	in y|Y|yes|YES|Yes)
609*fcf3ce44SJohn Forte	    return 1
610*fcf3ce44SJohn Forte	    ;;
611*fcf3ce44SJohn Forte	*)
612*fcf3ce44SJohn Forte            return 0
613*fcf3ce44SJohn Forte            ;;
614*fcf3ce44SJohn Forte    esac
615*fcf3ce44SJohn Forte}
616*fcf3ce44SJohn Forte
617*fcf3ce44SJohn Forte#
618*fcf3ce44SJohn Forte# display information about the system
619*fcf3ce44SJohn Forte#
620*fcf3ce44SJohn Fortedisplay_info()
621*fcf3ce44SJohn Forte{
622*fcf3ce44SJohn Forte	$xopt
623*fcf3ce44SJohn Forte
624*fcf3ce44SJohn Forte	typeset grp_error_flg=0
625*fcf3ce44SJohn Forte	typeset -L15 svc state en SVC="SERVICE" STATE="STATE" EN="ENABLED"
626*fcf3ce44SJohn Forte	echo "$SVC\t$STATE\t$EN"
627*fcf3ce44SJohn Forte
628*fcf3ce44SJohn Forte	for i in $SMF_ENABLE
629*fcf3ce44SJohn Forte	do
630*fcf3ce44SJohn Forte		is_imported $i
631*fcf3ce44SJohn Forte		if [ $? = 1 ]
632*fcf3ce44SJohn Forte		then
633*fcf3ce44SJohn Forte			state=`svcprop -c -p restarter/state \
634*fcf3ce44SJohn Forte			    svc:/system/${i}:default`
635*fcf3ce44SJohn Forte			en=`svcprop -c -p general/enabled \
636*fcf3ce44SJohn Forte			    svc:/system/${i}:default`
637*fcf3ce44SJohn Forte			check_fs_local_grouping $i
638*fcf3ce44SJohn Forte			if [ $? -ne 0 ]
639*fcf3ce44SJohn Forte			then
640*fcf3ce44SJohn Forte				svc="${i}***"
641*fcf3ce44SJohn Forte				grp_error_flg=$((grp_error_flg + 1))
642*fcf3ce44SJohn Forte			else
643*fcf3ce44SJohn Forte				svc=$i
644*fcf3ce44SJohn Forte			fi
645*fcf3ce44SJohn Forte
646*fcf3ce44SJohn Forte			echo "$svc\t$state\t$en"
647*fcf3ce44SJohn Forte		fi
648*fcf3ce44SJohn Forte	done
649*fcf3ce44SJohn Forte
650*fcf3ce44SJohn Forte	print "\nAvailability Suite Configuration:"
651*fcf3ce44SJohn Forte	printf "Local configuration database: "
652*fcf3ce44SJohn Forte	if [ $VALID_LOCAL_DB = 1 ]
653*fcf3ce44SJohn Forte	then
654*fcf3ce44SJohn Forte		print "valid"
655*fcf3ce44SJohn Forte	else
656*fcf3ce44SJohn Forte		print "invalid"
657*fcf3ce44SJohn Forte	fi
658*fcf3ce44SJohn Forte
659*fcf3ce44SJohn Forte	if [ $CLUSTER_CONFIGURED = 1 ]
660*fcf3ce44SJohn Forte	then
661*fcf3ce44SJohn Forte		printf "cluster configuration database: "
662*fcf3ce44SJohn Forte		if [ $VALID_CLUSTER_DB = 1 ]
663*fcf3ce44SJohn Forte		then
664*fcf3ce44SJohn Forte			print "valid"
665*fcf3ce44SJohn Forte			print "cluster configuration location: ${FILE_LOC}"
666*fcf3ce44SJohn Forte		else
667*fcf3ce44SJohn Forte			print "invalid"
668*fcf3ce44SJohn Forte		fi
669*fcf3ce44SJohn Forte	fi
670*fcf3ce44SJohn Forte
671*fcf3ce44SJohn Forte	if [ $grp_error_flg -gt 0 ]
672*fcf3ce44SJohn Forte	then
673*fcf3ce44SJohn Forte		typeset p
674*fcf3ce44SJohn Forte		typeset p_has
675*fcf3ce44SJohn Forte		if [ $grp_error_flg -gt 1 ]
676*fcf3ce44SJohn Forte		then
677*fcf3ce44SJohn Forte			p="s"
678*fcf3ce44SJohn Forte			p_has="have"
679*fcf3ce44SJohn Forte		else
680*fcf3ce44SJohn Forte			p=""
681*fcf3ce44SJohn Forte			p_has="has"
682*fcf3ce44SJohn Forte		fi
683*fcf3ce44SJohn Forte
684*fcf3ce44SJohn Forte		printf "\n*** Warning: The service$p above $p_has an incorrect "
685*fcf3ce44SJohn Forte		printf "dependency.  To repair the\n"
686*fcf3ce44SJohn Forte		printf "problem, run \"dscfgadm\".\n"
687*fcf3ce44SJohn Forte	fi
688*fcf3ce44SJohn Forte}
689*fcf3ce44SJohn Forte
690*fcf3ce44SJohn Forte#
691*fcf3ce44SJohn Forte# initialize the local configuration database (only called if none exists)
692*fcf3ce44SJohn Forte# returns 0 if successful, 1 if failed
693*fcf3ce44SJohn Forte#
694*fcf3ce44SJohn Forteinitialize_local_db()
695*fcf3ce44SJohn Forte{
696*fcf3ce44SJohn Forte	$xopt
697*fcf3ce44SJohn Forte
698*fcf3ce44SJohn Forte	echo "Could not find a valid local configuration database."
699*fcf3ce44SJohn Forte	echo "Initializing local configuration database..."
700*fcf3ce44SJohn Forte	echo y | ${DSCFG} -i > /dev/null 2>&1
701*fcf3ce44SJohn Forte	${DSCFG} -i -p ${PCONFIG} > /dev/null 2>&1
702*fcf3ce44SJohn Forte
703*fcf3ce44SJohn Forte	# Make sure the new location is initialized properly
704*fcf3ce44SJohn Forte	valid_local_dscfg_exists
705*fcf3ce44SJohn Forte	VALID_LOCAL_DB=$?
706*fcf3ce44SJohn Forte	if [ $VALID_LOCAL_DB != 1 ]
707*fcf3ce44SJohn Forte	then
708*fcf3ce44SJohn Forte		echo "Unable to initialize local configuration database" >&2
709*fcf3ce44SJohn Forte		return 1
710*fcf3ce44SJohn Forte	else
711*fcf3ce44SJohn Forte		echo "Successfully initialized local configuration database"
712*fcf3ce44SJohn Forte	fi
713*fcf3ce44SJohn Forte
714*fcf3ce44SJohn Forte	return 0
715*fcf3ce44SJohn Forte}
716*fcf3ce44SJohn Forte
717*fcf3ce44SJohn Forte#
718*fcf3ce44SJohn Forte# initialize the cluster configuration database, if necessary
719*fcf3ce44SJohn Forte# returns 0 if successful, 1 if failed
720*fcf3ce44SJohn Forte#
721*fcf3ce44SJohn Forteinitialize_cluster_db()
722*fcf3ce44SJohn Forte{
723*fcf3ce44SJohn Forte	$xopt
724*fcf3ce44SJohn Forte
725*fcf3ce44SJohn Forte	if [ ! -n "$FILE_LOC" ]
726*fcf3ce44SJohn Forte	then
727*fcf3ce44SJohn Forte		return 0
728*fcf3ce44SJohn Forte	fi
729*fcf3ce44SJohn Forte
730*fcf3ce44SJohn Forte	echo "Initializing cluster configuration database..."
731*fcf3ce44SJohn Forte	${DSCFG} -s ${FILE_LOC} -C $CTAG_NULL > /dev/null 2>&1
732*fcf3ce44SJohn Forte	echo y | ${DSCFG} -i -C $CTAG_NULL > /dev/null 2>&1
733*fcf3ce44SJohn Forte	${DSCFG} -i -p ${PCONFIG} -C $CTAG_NULL > /dev/null 2>&1
734*fcf3ce44SJohn Forte
735*fcf3ce44SJohn Forte	# make sure the cluster db is valid now
736*fcf3ce44SJohn Forte	valid_cluster_dscfg_exists
737*fcf3ce44SJohn Forte	VALID_CLUSTER_DB=$?
738*fcf3ce44SJohn Forte	if [ $VALID_CLUSTER_DB != 1 ]
739*fcf3ce44SJohn Forte	then
740*fcf3ce44SJohn Forte		echo "Unable to initialize cluster configuration database" >&2
741*fcf3ce44SJohn Forte			return 1
742*fcf3ce44SJohn Forte	else
743*fcf3ce44SJohn Forte		echo "Successfully initialized cluster configuration database"
744*fcf3ce44SJohn Forte	fi
745*fcf3ce44SJohn Forte
746*fcf3ce44SJohn Forte	return 0
747*fcf3ce44SJohn Forte
748*fcf3ce44SJohn Forte}
749*fcf3ce44SJohn Forte
750*fcf3ce44SJohn Forte#
751*fcf3ce44SJohn Forte# prompt the user for a config location and set AVS to use that location
752*fcf3ce44SJohn Forte#
753*fcf3ce44SJohn Forteset_cluster_config()
754*fcf3ce44SJohn Forte{
755*fcf3ce44SJohn Forte
756*fcf3ce44SJohn Forte$xopt
757*fcf3ce44SJohn Forte
758*fcf3ce44SJohn ForteREPEAT=0
759*fcf3ce44SJohn Fortewhile [ $REPEAT -eq 0 ]; do
760*fcf3ce44SJohn Forte  # See if user has entered location already, and it was an existing
761*fcf3ce44SJohn Forte  # db.	 Retruns FILE_LOC value
762*fcf3ce44SJohn Forte  if [ $VALID_DB_ENTERED = 1 ]; then
763*fcf3ce44SJohn Forte
764*fcf3ce44SJohn Forte	# reset
765*fcf3ce44SJohn Forte      VALID_DB_ENTERED=0
766*fcf3ce44SJohn Forte	preserve_overwrite_maybe
767*fcf3ce44SJohn Forte
768*fcf3ce44SJohn Forte	# if 1, location passes, and FILE_LOC being passed to end, else
769*fcf3ce44SJohn Forte      # set VALID_CLUSTER_DB to 0 since the "valid one" isn't valid anymore
770*fcf3ce44SJohn Forte      # (bad size, etc) thereby when looping go straight to get_location
771*fcf3ce44SJohn Forte      if [ $? = 1 ]; then
772*fcf3ce44SJohn Forte          REPEAT=1
773*fcf3ce44SJohn Forte          continue
774*fcf3ce44SJohn Forte      else
775*fcf3ce44SJohn Forte          VALID_CLUSTER_DB=0
776*fcf3ce44SJohn Forte          continue
777*fcf3ce44SJohn Forte      fi
778*fcf3ce44SJohn Forte  fi
779*fcf3ce44SJohn Forte
780*fcf3ce44SJohn Forte  # if 1, then valid db exists, now see what user wants to do
781*fcf3ce44SJohn Forte  if [ $VALID_CLUSTER_DB = 1 ]; then
782*fcf3ce44SJohn Forte      SAFE_LOC=$FILE_LOC
783*fcf3ce44SJohn Forte      keep_it
784*fcf3ce44SJohn Forte
785*fcf3ce44SJohn Forte      # if 0, then user can't or won't keep location.  set PROMPT
786*fcf3ce44SJohn Forte      # so we will get new location from user.
787*fcf3ce44SJohn Forte      if [ $? = 0 ]; then
788*fcf3ce44SJohn Forte          PROMPT=0
789*fcf3ce44SJohn Forte      else
790*fcf3ce44SJohn Forte          PROMPT=1
791*fcf3ce44SJohn Forte	fi
792*fcf3ce44SJohn Forte  fi
793*fcf3ce44SJohn Forte
794*fcf3ce44SJohn Forte  # if either are 0, then user wants or needs new db as outlined in
795*fcf3ce44SJohn Forte  # earlier comments
796*fcf3ce44SJohn Forte  if [ $VALID_CLUSTER_DB = 0 ] || [ $PROMPT = 0 ]; then
797*fcf3ce44SJohn Forte	#
798*fcf3ce44SJohn Forte	# We cannot proceed if the services are running.  Give the user
799*fcf3ce44SJohn Forte	# a chance to stop the services.  If he chooses not to, bail.
800*fcf3ce44SJohn Forte	#
801*fcf3ce44SJohn Forte	check_enabled
802*fcf3ce44SJohn Forte	if [ $? = 1 ]
803*fcf3ce44SJohn Forte	then
804*fcf3ce44SJohn Forte		show_enabled
805*fcf3ce44SJohn Forte		ask_to_disable
806*fcf3ce44SJohn Forte		if [ $? = 0 ]
807*fcf3ce44SJohn Forte		then
808*fcf3ce44SJohn Forte			echo "A new configuration location was not set."
809*fcf3ce44SJohn Forte			exit 1
810*fcf3ce44SJohn Forte		else
811*fcf3ce44SJohn Forte			disable_services
812*fcf3ce44SJohn Forte			if [ $? != 0 ]
813*fcf3ce44SJohn Forte			then
814*fcf3ce44SJohn Forte				exit 1
815*fcf3ce44SJohn Forte			fi
816*fcf3ce44SJohn Forte		fi
817*fcf3ce44SJohn Forte
818*fcf3ce44SJohn Forte	fi
819*fcf3ce44SJohn Forte
820*fcf3ce44SJohn Forte	get_location
821*fcf3ce44SJohn Forte	contains_data $FILE_LOC
822*fcf3ce44SJohn Forte
823*fcf3ce44SJohn Forte	# if 1, then user entered an existsing db location, loop
824*fcf3ce44SJohn Forte	# back to ask what to do with it
825*fcf3ce44SJohn Forte	if [ $? = 1 ]; then
826*fcf3ce44SJohn Forte	  VALID_DB_ENTERED=1
827*fcf3ce44SJohn Forte	  continue
828*fcf3ce44SJohn Forte	else
829*fcf3ce44SJohn Forte          check_location $FILE_LOC
830*fcf3ce44SJohn Forte
831*fcf3ce44SJohn Forte	  # if 0, that means location has failed, loop and
832*fcf3ce44SJohn Forte	  # get_location again
833*fcf3ce44SJohn Forte	  if [ $? = 0 ]; then
834*fcf3ce44SJohn Forte		VALID_CLUSTER_DB=0
835*fcf3ce44SJohn Forte		continue
836*fcf3ce44SJohn Forte	  fi
837*fcf3ce44SJohn Forte          # entered location passes tests
838*fcf3ce44SJohn Forte	  REPEAT=1
839*fcf3ce44SJohn Forte	  continue
840*fcf3ce44SJohn Forte	fi
841*fcf3ce44SJohn Forte  else
842*fcf3ce44SJohn Forte      # user wants to leave location where and how it is
843*fcf3ce44SJohn Forte	# FILE_LOC being passed all the way to end
844*fcf3ce44SJohn Forte	REPEAT=1
845*fcf3ce44SJohn Forte	continue
846*fcf3ce44SJohn Forte  fi
847*fcf3ce44SJohn Fortedone
848*fcf3ce44SJohn Forte
849*fcf3ce44SJohn Forte}
850*fcf3ce44SJohn Forte
851*fcf3ce44SJohn Forte########################## MAIN FUNCTIONS ############################
852*fcf3ce44SJohn Forte
853*fcf3ce44SJohn Forte######################## SMF HELPER FUNCTIONS ########################
854*fcf3ce44SJohn Forte#
855*fcf3ce44SJohn Forte# check if any SMF service is online (enabled)
856*fcf3ce44SJohn Forte#
857*fcf3ce44SJohn Fortecheck_enabled()
858*fcf3ce44SJohn Forte{
859*fcf3ce44SJohn Forte	$xopt
860*fcf3ce44SJohn Forte	typeset ret=0
861*fcf3ce44SJohn Forte	typeset svc
862*fcf3ce44SJohn Forte
863*fcf3ce44SJohn Forte	for svc in $SMF_ENABLE
864*fcf3ce44SJohn Forte	do
865*fcf3ce44SJohn Forte		is_enabled $svc
866*fcf3ce44SJohn Forte		eval ${svc}_enabled=$?
867*fcf3ce44SJohn Forte		ret=$((ret | ${svc}_enabled))
868*fcf3ce44SJohn Forte	done
869*fcf3ce44SJohn Forte
870*fcf3ce44SJohn Forte	return $ret
871*fcf3ce44SJohn Forte}
872*fcf3ce44SJohn Forte
873*fcf3ce44SJohn Forte#
874*fcf3ce44SJohn Forte# Display which services are enabled.  (Must be called after check_enabled)
875*fcf3ce44SJohn Forte#
876*fcf3ce44SJohn Forteshow_enabled()
877*fcf3ce44SJohn Forte{
878*fcf3ce44SJohn Forte	$xopt
879*fcf3ce44SJohn Forte	typeset svc
880*fcf3ce44SJohn Forte
881*fcf3ce44SJohn Forte	echo "\nThe following Availability Suite services are enabled:"
882*fcf3ce44SJohn Forte
883*fcf3ce44SJohn Forte	for svc in $SMF_ENABLE
884*fcf3ce44SJohn Forte	do
885*fcf3ce44SJohn Forte	if (( ${svc}_enabled == 1 ))
886*fcf3ce44SJohn Forte	then
887*fcf3ce44SJohn Forte	    printf "$svc "
888*fcf3ce44SJohn Forte	fi
889*fcf3ce44SJohn Forte	done
890*fcf3ce44SJohn Forte
891*fcf3ce44SJohn Forte	echo ""
892*fcf3ce44SJohn Forte}
893*fcf3ce44SJohn Forte
894*fcf3ce44SJohn Forte
895*fcf3ce44SJohn Forte#
896*fcf3ce44SJohn Forte# check if the given SMF service is online (enabled)
897*fcf3ce44SJohn Forte#
898*fcf3ce44SJohn Forte# $1: service name to check for
899*fcf3ce44SJohn Forte#
900*fcf3ce44SJohn Forteis_enabled()
901*fcf3ce44SJohn Forte{
902*fcf3ce44SJohn Forte	$xopt
903*fcf3ce44SJohn Forte	typeset en
904*fcf3ce44SJohn Forte
905*fcf3ce44SJohn Forte	is_imported $1
906*fcf3ce44SJohn Forte	if [ $? = 1 ]
907*fcf3ce44SJohn Forte	then
908*fcf3ce44SJohn Forte		en=`svcprop -c -p general/enabled svc:/system/${1}:default`
909*fcf3ce44SJohn Forte		if [ $en = "true" ]
910*fcf3ce44SJohn Forte		then
911*fcf3ce44SJohn Forte			return 1
912*fcf3ce44SJohn Forte		fi
913*fcf3ce44SJohn Forte	fi
914*fcf3ce44SJohn Forte
915*fcf3ce44SJohn Forte	return 0
916*fcf3ce44SJohn Forte
917*fcf3ce44SJohn Forte}
918*fcf3ce44SJohn Forte
919*fcf3ce44SJohn Forte#
920*fcf3ce44SJohn Forte# If necessary, flag no dependency check
921*fcf3ce44SJohn Forte#
922*fcf3ce44SJohn Forteno_depend_check()
923*fcf3ce44SJohn Forte{
924*fcf3ce44SJohn Forte	$xopt
925*fcf3ce44SJohn Forte	typeset pid
926*fcf3ce44SJohn Forte	typeset msg=0
927*fcf3ce44SJohn Forte
928*fcf3ce44SJohn Forte	if [ $OS_MINOR -lt 11 ]
929*fcf3ce44SJohn Forte	then
930*fcf3ce44SJohn Forte		if [ -f $DSCFG_DEPEND_NOCHK ]
931*fcf3ce44SJohn Forte		then
932*fcf3ce44SJohn Forte			pid=`cat $DSCFG_DEPEND_NOCHK`
933*fcf3ce44SJohn Forte			echo "Another dscfgadm disable is in progress."
934*fcf3ce44SJohn Forte			echo "Waiting for pid: $pid to terminate..."
935*fcf3ce44SJohn Forte
936*fcf3ce44SJohn Forte			while [ -f $DSCFG_DEPEND_NOCHK ]
937*fcf3ce44SJohn Forte			do
938*fcf3ce44SJohn Forte				if (( msg && (msg % 6 == 0)))
939*fcf3ce44SJohn Forte				then
940*fcf3ce44SJohn Forte					printf "\nAnother dscfgadm disable "
941*fcf3ce44SJohn Forte					printf "(pid: $pid) still appears to "
942*fcf3ce44SJohn Forte					printf " be in progress.\n"
943*fcf3ce44SJohn Forte					printf "If this is not the case, you "
944*fcf3ce44SJohn Forte					printf "may remove "
945*fcf3ce44SJohn Forte					printf "$DSCFG_DEPEND_NOCHK.\n"
946*fcf3ce44SJohn Forte				fi
947*fcf3ce44SJohn Forte				sleep 5
948*fcf3ce44SJohn Forte				msg=$((msg + 1))
949*fcf3ce44SJohn Forte			done
950*fcf3ce44SJohn Forte		fi
951*fcf3ce44SJohn Forte
952*fcf3ce44SJohn Forte		touch $DSCFG_DEPEND_NOCHK
953*fcf3ce44SJohn Forte		echo $$ >> $DSCFG_DEPEND_NOCHK
954*fcf3ce44SJohn Forte	fi
955*fcf3ce44SJohn Forte}
956*fcf3ce44SJohn Forte
957*fcf3ce44SJohn Forte#
958*fcf3ce44SJohn Forte# If necessary, remove the no dependency check flag
959*fcf3ce44SJohn Forte#
960*fcf3ce44SJohn Forterm_no_depend_check()
961*fcf3ce44SJohn Forte{
962*fcf3ce44SJohn Forte	$xopt
963*fcf3ce44SJohn Forte	if [ $OS_MINOR -lt 11 ]
964*fcf3ce44SJohn Forte	then
965*fcf3ce44SJohn Forte		rm -f $DSCFG_DEPEND_NOCHK
966*fcf3ce44SJohn Forte	fi
967*fcf3ce44SJohn Forte}
968*fcf3ce44SJohn Forte
969*fcf3ce44SJohn Forte#
970*fcf3ce44SJohn Forte# set the filesystem/local dependency type and refresh
971*fcf3ce44SJohn Forte#
972*fcf3ce44SJohn Forte# $1: service name
973*fcf3ce44SJohn Forte# $2: either "require_all" or "optional_all"
974*fcf3ce44SJohn Forte#
975*fcf3ce44SJohn Forteset_fs_local_grouping()
976*fcf3ce44SJohn Forte{
977*fcf3ce44SJohn Forte	$xopt
978*fcf3ce44SJohn Forte	typeset svc=$1
979*fcf3ce44SJohn Forte	typeset dep_group=$2
980*fcf3ce44SJohn Forte
981*fcf3ce44SJohn Forte	# set proper dependency type for fs-local
982*fcf3ce44SJohn Forte	if [ $svc != nws_rdcsyncd ]; then
983*fcf3ce44SJohn Forte		svccfg -s $FS_LOCAL_SVC setprop \
984*fcf3ce44SJohn Forte		   ${svc}-local-fs/grouping=$dep_group
985*fcf3ce44SJohn Forte		if [ $? -ne 0 ]
986*fcf3ce44SJohn Forte		then
987*fcf3ce44SJohn Forte			printf "command failed: svccfg -s $FS_LOCAL_SVC "
988*fcf3ce44SJohn Forte			printf "setprop ${svc}-local-fs/grouping=$dep_group "
989*fcf3ce44SJohn Forte			printf ">&2\n"
990*fcf3ce44SJohn Forte			return 1
991*fcf3ce44SJohn Forte		fi
992*fcf3ce44SJohn Forte
993*fcf3ce44SJohn Forte		# we need local-fs to know about the new grouping attributes
994*fcf3ce44SJohn Forte		svcadm refresh ${FS_LOCAL_SVC}:default
995*fcf3ce44SJohn Forte		if [ $? -ne 0 ]
996*fcf3ce44SJohn Forte		then
997*fcf3ce44SJohn Forte			print "Failed to refresh ${FS_LOCAL_SVC} >&2"
998*fcf3ce44SJohn Forte			return 1
999*fcf3ce44SJohn Forte		fi
1000*fcf3ce44SJohn Forte	fi
1001*fcf3ce44SJohn Forte
1002*fcf3ce44SJohn Forte	return 0
1003*fcf3ce44SJohn Forte}
1004*fcf3ce44SJohn Forte
1005*fcf3ce44SJohn Forte#
1006*fcf3ce44SJohn Forte# check if the grouping dependency type for filesystem/local is correct
1007*fcf3ce44SJohn Forte#
1008*fcf3ce44SJohn Forte# input:
1009*fcf3ce44SJohn Forte# $1: service name
1010*fcf3ce44SJohn Forte#
1011*fcf3ce44SJohn Forte# returns:
1012*fcf3ce44SJohn Forte#	0 if the setting is correct
1013*fcf3ce44SJohn Forte#	1 if the setting is incorrect
1014*fcf3ce44SJohn Forte# outputs: sets CORRECT_GROUPING with the value of what the grouping should be.
1015*fcf3ce44SJohn Forte#
1016*fcf3ce44SJohn Fortecheck_fs_local_grouping()
1017*fcf3ce44SJohn Forte{
1018*fcf3ce44SJohn Forte	$xopt
1019*fcf3ce44SJohn Forte	typeset svc=$1
1020*fcf3ce44SJohn Forte	typeset cur_grouping
1021*fcf3ce44SJohn Forte
1022*fcf3ce44SJohn Forte	if [ $svc = nws_rdcsyncd ]
1023*fcf3ce44SJohn Forte	then
1024*fcf3ce44SJohn Forte		return 0
1025*fcf3ce44SJohn Forte	fi
1026*fcf3ce44SJohn Forte
1027*fcf3ce44SJohn Forte	# If it's not imported, we just return success, since we don't want
1028*fcf3ce44SJohn Forte	# further processing
1029*fcf3ce44SJohn Forte	is_imported $svc
1030*fcf3ce44SJohn Forte	if [ $? = 0 ]
1031*fcf3ce44SJohn Forte	then
1032*fcf3ce44SJohn Forte		return 0
1033*fcf3ce44SJohn Forte	fi
1034*fcf3ce44SJohn Forte
1035*fcf3ce44SJohn Forte	# get the current grouping value from the repository
1036*fcf3ce44SJohn Forte	cur_grouping=`svcprop -c -p ${svc}-local-fs/grouping $FS_LOCAL_SVC`
1037*fcf3ce44SJohn Forte
1038*fcf3ce44SJohn Forte	# Figure out what the grouping should be (based on enabled status)
1039*fcf3ce44SJohn Forte	is_enabled $svc
1040*fcf3ce44SJohn Forte	if [ $? = 1 ]
1041*fcf3ce44SJohn Forte	then
1042*fcf3ce44SJohn Forte		CORRECT_GROUPING="require_all"
1043*fcf3ce44SJohn Forte	else
1044*fcf3ce44SJohn Forte		CORRECT_GROUPING="optional_all"
1045*fcf3ce44SJohn Forte	fi
1046*fcf3ce44SJohn Forte
1047*fcf3ce44SJohn Forte	if [ "$cur_grouping" != "$CORRECT_GROUPING" ]
1048*fcf3ce44SJohn Forte	then
1049*fcf3ce44SJohn Forte		# grouping is incorrect
1050*fcf3ce44SJohn Forte		return 1
1051*fcf3ce44SJohn Forte	else
1052*fcf3ce44SJohn Forte		# grouping is just fine
1053*fcf3ce44SJohn Forte		return 0
1054*fcf3ce44SJohn Forte	fi
1055*fcf3ce44SJohn Forte}
1056*fcf3ce44SJohn Forte
1057*fcf3ce44SJohn Forte#
1058*fcf3ce44SJohn Forte# enable/disable the given SMF service.  Also, update the filesystem-local
1059*fcf3ce44SJohn Forte# dependency, if appropriate.
1060*fcf3ce44SJohn Forte#
1061*fcf3ce44SJohn Forte# $1: service name to check for
1062*fcf3ce44SJohn Forte# $2: "enable" or "disable"
1063*fcf3ce44SJohn Forte#
1064*fcf3ce44SJohn Fortesvc_operation()
1065*fcf3ce44SJohn Forte{
1066*fcf3ce44SJohn Forte	$xopt
1067*fcf3ce44SJohn Forte	typeset svc=$1
1068*fcf3ce44SJohn Forte	typeset command=$2
1069*fcf3ce44SJohn Forte	typeset enable_state
1070*fcf3ce44SJohn Forte	typeset dep_group
1071*fcf3ce44SJohn Forte
1072*fcf3ce44SJohn Forte	# If disabling, then enable_state better be true, and we are
1073*fcf3ce44SJohn Forte	# transitioning to "option_all" grouping
1074*fcf3ce44SJohn Forte	if [ $command = "disable" ]
1075*fcf3ce44SJohn Forte	then
1076*fcf3ce44SJohn Forte		enable_state=1
1077*fcf3ce44SJohn Forte		dep_group="optional_all"
1078*fcf3ce44SJohn Forte
1079*fcf3ce44SJohn Forte	# If enabling, then enable_state better be false, and we are
1080*fcf3ce44SJohn Forte	# transitioning to "require_all" grouping
1081*fcf3ce44SJohn Forte	elif [ $command = "enable" ]
1082*fcf3ce44SJohn Forte	then
1083*fcf3ce44SJohn Forte		enable_state=0
1084*fcf3ce44SJohn Forte		dep_group="require_all"
1085*fcf3ce44SJohn Forte	else
1086*fcf3ce44SJohn Forte		echo "invalid command: $command" >&2
1087*fcf3ce44SJohn Forte	fi
1088*fcf3ce44SJohn Forte
1089*fcf3ce44SJohn Forte	is_imported $svc
1090*fcf3ce44SJohn Forte	if [ $? = 1 ]
1091*fcf3ce44SJohn Forte	then
1092*fcf3ce44SJohn Forte		is_enabled $svc
1093*fcf3ce44SJohn Forte		if [ $? = $enable_state ]
1094*fcf3ce44SJohn Forte		then
1095*fcf3ce44SJohn Forte			if [ $enable_state -eq 1 ]
1096*fcf3ce44SJohn Forte			then
1097*fcf3ce44SJohn Forte				# we're doing a disable--remove hard dependency
1098*fcf3ce44SJohn Forte				set_fs_local_grouping $svc $dep_group
1099*fcf3ce44SJohn Forte				if [ $? -ne 0 ]
1100*fcf3ce44SJohn Forte				then
1101*fcf3ce44SJohn Forte					return 1
1102*fcf3ce44SJohn Forte				fi
1103*fcf3ce44SJohn Forte			fi
1104*fcf3ce44SJohn Forte
1105*fcf3ce44SJohn Forte			svcadm $command -s svc:/system/$svc
1106*fcf3ce44SJohn Forte			if [ $? != 0 ]
1107*fcf3ce44SJohn Forte			then
1108*fcf3ce44SJohn Forte				echo "$svc failed to $command" >&2
1109*fcf3ce44SJohn Forte				return 1
1110*fcf3ce44SJohn Forte			fi
1111*fcf3ce44SJohn Forte
1112*fcf3ce44SJohn Forte			if [ $enable_state -eq 0 ]
1113*fcf3ce44SJohn Forte			then
1114*fcf3ce44SJohn Forte				# we just did an enable--create hard dependency
1115*fcf3ce44SJohn Forte				set_fs_local_grouping $svc $dep_group
1116*fcf3ce44SJohn Forte				if [ $? -ne 0 ]
1117*fcf3ce44SJohn Forte				then
1118*fcf3ce44SJohn Forte					return 1
1119*fcf3ce44SJohn Forte				fi
1120*fcf3ce44SJohn Forte			fi
1121*fcf3ce44SJohn Forte
1122*fcf3ce44SJohn Forte		else
1123*fcf3ce44SJohn Forte			echo "$svc service already ${command}d... skipping"
1124*fcf3ce44SJohn Forte		fi
1125*fcf3ce44SJohn Forte	fi
1126*fcf3ce44SJohn Forte
1127*fcf3ce44SJohn Forte	return 0
1128*fcf3ce44SJohn Forte}
1129*fcf3ce44SJohn Forte
1130*fcf3ce44SJohn Forte#
1131*fcf3ce44SJohn Forte# This chart summarizes the behavior of the -r and -p sub-options for the
1132*fcf3ce44SJohn Forte# -e and -d options.
1133*fcf3ce44SJohn Forte# There are 5 possible states, and 5 transitions out of each state.
1134*fcf3ce44SJohn Forte#
1135*fcf3ce44SJohn Forte# states: (vertical axis)
1136*fcf3ce44SJohn Forte# -------
1137*fcf3ce44SJohn Forte# 0: no services enabled
1138*fcf3ce44SJohn Forte# C: one or both core services enabled (illegal state)
1139*fcf3ce44SJohn Forte# R: both core services and RM services enabled
1140*fcf3ce44SJohn Forte# P: both core services and PITC service enabled
1141*fcf3ce44SJohn Forte# A: all services enabled
1142*fcf3ce44SJohn Forte#
1143*fcf3ce44SJohn Forte# transitions: (horizontal axis)
1144*fcf3ce44SJohn Forte# ------------
1145*fcf3ce44SJohn Forte# +/-a: enable/disable, respectively, with neither -r nor -p
1146*fcf3ce44SJohn Forte# +/-r: enable/disable, respectively, with -r flag
1147*fcf3ce44SJohn Forte# +p: enable with -p flag
1148*fcf3ce44SJohn Forte#
1149*fcf3ce44SJohn Forte# The result of the function is the next state after the action has been
1150*fcf3ce44SJohn Forte# successfully performed.
1151*fcf3ce44SJohn Forte#
1152*fcf3ce44SJohn Forte#      +a | -a | +r | -r | +p |
1153*fcf3ce44SJohn Forte#   ++----+----+----+----+----+
1154*fcf3ce44SJohn Forte#   ++----+----+----+----+----+
1155*fcf3ce44SJohn Forte# 0 || A  | 0* | R  | 0* | P  |
1156*fcf3ce44SJohn Forte# --++----+----+----+----+----+
1157*fcf3ce44SJohn Forte# C || A* | 0* | R  | 0  | P  |
1158*fcf3ce44SJohn Forte# --++----+----+----+----+----+
1159*fcf3ce44SJohn Forte# R || A* | 0* | R* | 0  | A  |
1160*fcf3ce44SJohn Forte# --++----+----+----+----+----+
1161*fcf3ce44SJohn Forte# P || A* | 0* | A* | P* | P* |
1162*fcf3ce44SJohn Forte# --++----+----+----+----+----+
1163*fcf3ce44SJohn Forte# A || A* | 0  | A* | P  | A* |
1164*fcf3ce44SJohn Forte# --++----+----+----+----+----+
1165*fcf3ce44SJohn Forte#
1166*fcf3ce44SJohn Forte# *: warning message is displayed, stating that a service is already
1167*fcf3ce44SJohn Forte#    enabled/disabled.
1168*fcf3ce44SJohn Forte#
1169*fcf3ce44SJohn Forte
1170*fcf3ce44SJohn Forte# enable the SMF services needed for the Availability Suite
1171*fcf3ce44SJohn Forte#
1172*fcf3ce44SJohn Forteenable_services()
1173*fcf3ce44SJohn Forte{
1174*fcf3ce44SJohn Forte	$xopt
1175*fcf3ce44SJohn Forte	typeset svc
1176*fcf3ce44SJohn Forte
1177*fcf3ce44SJohn Forte	# first, import them if they have not yet been imported
1178*fcf3ce44SJohn Forte	import_services
1179*fcf3ce44SJohn Forte
1180*fcf3ce44SJohn Forte	# if neither r_flag nor p_flag is set, enable all services
1181*fcf3ce44SJohn Forte	if (( (r_flag | p_flag) == 0 ))
1182*fcf3ce44SJohn Forte	then
1183*fcf3ce44SJohn Forte		for svc in $SMF_ENABLE
1184*fcf3ce44SJohn Forte		do
1185*fcf3ce44SJohn Forte			if ! svc_operation $svc enable
1186*fcf3ce44SJohn Forte			then
1187*fcf3ce44SJohn Forte				return 1
1188*fcf3ce44SJohn Forte			fi
1189*fcf3ce44SJohn Forte		done
1190*fcf3ce44SJohn Forte	else
1191*fcf3ce44SJohn Forte		# figure out which services are enabled
1192*fcf3ce44SJohn Forte		check_enabled
1193*fcf3ce44SJohn Forte
1194*fcf3ce44SJohn Forte		# First, make sure both core services are enabled
1195*fcf3ce44SJohn Forte		for svc in nws_scm nws_sv
1196*fcf3ce44SJohn Forte		do
1197*fcf3ce44SJohn Forte			if (( ${svc}_enabled == 0 )) && \
1198*fcf3ce44SJohn Forte				! svc_operation $svc enable
1199*fcf3ce44SJohn Forte			then
1200*fcf3ce44SJohn Forte				return 1
1201*fcf3ce44SJohn Forte			fi
1202*fcf3ce44SJohn Forte		done
1203*fcf3ce44SJohn Forte
1204*fcf3ce44SJohn Forte		if ((p_flag))
1205*fcf3ce44SJohn Forte		then
1206*fcf3ce44SJohn Forte			if ! svc_operation nws_ii enable
1207*fcf3ce44SJohn Forte			then
1208*fcf3ce44SJohn Forte				return 1
1209*fcf3ce44SJohn Forte			fi
1210*fcf3ce44SJohn Forte		fi
1211*fcf3ce44SJohn Forte
1212*fcf3ce44SJohn Forte		if ((r_flag))
1213*fcf3ce44SJohn Forte		then
1214*fcf3ce44SJohn Forte			for svc in nws_rdc nws_rdcsyncd
1215*fcf3ce44SJohn Forte			do
1216*fcf3ce44SJohn Forte				if ! svc_operation $svc enable
1217*fcf3ce44SJohn Forte				then
1218*fcf3ce44SJohn Forte					return 1
1219*fcf3ce44SJohn Forte				fi
1220*fcf3ce44SJohn Forte			done
1221*fcf3ce44SJohn Forte		fi
1222*fcf3ce44SJohn Forte
1223*fcf3ce44SJohn Forte	fi
1224*fcf3ce44SJohn Forte
1225*fcf3ce44SJohn Forte	return 0
1226*fcf3ce44SJohn Forte}
1227*fcf3ce44SJohn Forte
1228*fcf3ce44SJohn Forte#
1229*fcf3ce44SJohn Forte# disable the SMF services needed for the Availability Suite
1230*fcf3ce44SJohn Forte#
1231*fcf3ce44SJohn Fortedisable_services()
1232*fcf3ce44SJohn Forte{
1233*fcf3ce44SJohn Forte	$xopt
1234*fcf3ce44SJohn Forte	typeset svc
1235*fcf3ce44SJohn Forte
1236*fcf3ce44SJohn Forte	check_device_groups
1237*fcf3ce44SJohn Forte	if [ $? == 1 ]
1238*fcf3ce44SJohn Forte	then
1239*fcf3ce44SJohn Forte		return 1
1240*fcf3ce44SJohn Forte	fi
1241*fcf3ce44SJohn Forte
1242*fcf3ce44SJohn Forte	# This flags the shutdown scripts to not check to make sure the
1243*fcf3ce44SJohn Forte	# services' dependents have been disabled.  The flag must be removed
1244*fcf3ce44SJohn Forte	# before returning from this function.
1245*fcf3ce44SJohn Forte	no_depend_check
1246*fcf3ce44SJohn Forte
1247*fcf3ce44SJohn Forte	# NB: p_flag is not allowed for disables.  II should not be
1248*fcf3ce44SJohn Forte	# disabled if sndr is enabled.  If rdc is not enabled, disabling just
1249*fcf3ce44SJohn Forte        # II is equivalent to disabling all the remaining services.
1250*fcf3ce44SJohn Forte
1251*fcf3ce44SJohn Forte	# If no flags passed in, just disable everything
1252*fcf3ce44SJohn Forte	if (( r_flag == 0 ))
1253*fcf3ce44SJohn Forte	then
1254*fcf3ce44SJohn Forte		for svc in $SMF_DISABLE
1255*fcf3ce44SJohn Forte		do
1256*fcf3ce44SJohn Forte			if ! svc_operation $svc disable
1257*fcf3ce44SJohn Forte			then
1258*fcf3ce44SJohn Forte				rm_no_depend_check
1259*fcf3ce44SJohn Forte				return 1
1260*fcf3ce44SJohn Forte			fi
1261*fcf3ce44SJohn Forte		done
1262*fcf3ce44SJohn Forte
1263*fcf3ce44SJohn Forte		# Now that we've disable the services, lets unload them
1264*fcf3ce44SJohn Forte		# from the Solaris kernel
1265*fcf3ce44SJohn Forte		#
1266*fcf3ce44SJohn Forte		modinfo | grep '(nws:' | grep -v "kRPC Stub" | sort -r | cut -d' ' -f1 | xargs -l modunload -i 2>/dev/null
1267*fcf3ce44SJohn Forte		modinfo | grep '(nws:' | grep -v "kRPC Stub" | sort -r | cut -d' ' -f1 | xargs -l modunload -i 2>/dev/null
1268*fcf3ce44SJohn Forte	else
1269*fcf3ce44SJohn Forte		# we're disabling just rdc.  If II is not already enabled,
1270*fcf3ce44SJohn Forte		# we disable core services, as well.
1271*fcf3ce44SJohn Forte
1272*fcf3ce44SJohn Forte		# figure out which services are enabled
1273*fcf3ce44SJohn Forte		check_enabled
1274*fcf3ce44SJohn Forte
1275*fcf3ce44SJohn Forte		for svc in nws_rdcsyncd nws_rdc
1276*fcf3ce44SJohn Forte		do
1277*fcf3ce44SJohn Forte			if ! svc_operation $svc disable
1278*fcf3ce44SJohn Forte			then
1279*fcf3ce44SJohn Forte				rm_no_depend_check
1280*fcf3ce44SJohn Forte				return 1
1281*fcf3ce44SJohn Forte			fi
1282*fcf3ce44SJohn Forte		done
1283*fcf3ce44SJohn Forte
1284*fcf3ce44SJohn Forte		if (( nws_ii_enabled == 0 ))
1285*fcf3ce44SJohn Forte		then
1286*fcf3ce44SJohn Forte			for svc in nws_sv nws_scm
1287*fcf3ce44SJohn Forte			do
1288*fcf3ce44SJohn Forte				if ((${svc}_enabled)) && \
1289*fcf3ce44SJohn Forte					! svc_operation $svc disable
1290*fcf3ce44SJohn Forte				then
1291*fcf3ce44SJohn Forte					rm_no_depend_check
1292*fcf3ce44SJohn Forte					return 1
1293*fcf3ce44SJohn Forte				fi
1294*fcf3ce44SJohn Forte			done
1295*fcf3ce44SJohn Forte		fi
1296*fcf3ce44SJohn Forte	fi
1297*fcf3ce44SJohn Forte
1298*fcf3ce44SJohn Forte
1299*fcf3ce44SJohn Forte	rm_no_depend_check
1300*fcf3ce44SJohn Forte	return 0
1301*fcf3ce44SJohn Forte}
1302*fcf3ce44SJohn Forte
1303*fcf3ce44SJohn Forte#
1304*fcf3ce44SJohn Forte# check if a service has been imported into the repository
1305*fcf3ce44SJohn Forte# $1: service to check
1306*fcf3ce44SJohn Forte# returns 1 if it is imported, 0 if it is not
1307*fcf3ce44SJohn Forte#
1308*fcf3ce44SJohn Forteis_imported()
1309*fcf3ce44SJohn Forte{
1310*fcf3ce44SJohn Forte	$xopt
1311*fcf3ce44SJohn Forte
1312*fcf3ce44SJohn Forte	typeset svc=$1
1313*fcf3ce44SJohn Forte
1314*fcf3ce44SJohn Forte	svcprop -q -p general/entity_stability svc:/system/${svc}
1315*fcf3ce44SJohn Forte	if [ $? = 1 ]
1316*fcf3ce44SJohn Forte	then
1317*fcf3ce44SJohn Forte		return 0
1318*fcf3ce44SJohn Forte	else
1319*fcf3ce44SJohn Forte		return 1
1320*fcf3ce44SJohn Forte	fi
1321*fcf3ce44SJohn Forte}
1322*fcf3ce44SJohn Forte
1323*fcf3ce44SJohn Forte#
1324*fcf3ce44SJohn Forte# import the SMF services into the repository, if necessary
1325*fcf3ce44SJohn Forte#
1326*fcf3ce44SJohn Forteimport_services()
1327*fcf3ce44SJohn Forte{
1328*fcf3ce44SJohn Forte	$xopt
1329*fcf3ce44SJohn Forte	typeset svc
1330*fcf3ce44SJohn Forte
1331*fcf3ce44SJohn Forte 	for svc in $SMF_ENABLE
1332*fcf3ce44SJohn Forte	do
1333*fcf3ce44SJohn Forte          	import_service $svc
1334*fcf3ce44SJohn Forte	done
1335*fcf3ce44SJohn Forte}
1336*fcf3ce44SJohn Forte
1337*fcf3ce44SJohn Forte#
1338*fcf3ce44SJohn Forte# check to see if an SMF service is in the repository.	If it is not,
1339*fcf3ce44SJohn Forte# import it in.
1340*fcf3ce44SJohn Forte# $1: name of service to import
1341*fcf3ce44SJohn Forte#
1342*fcf3ce44SJohn Forteimport_service()
1343*fcf3ce44SJohn Forte{
1344*fcf3ce44SJohn Forte	$xopt
1345*fcf3ce44SJohn Forte 	typeset svc=$1
1346*fcf3ce44SJohn Forte
1347*fcf3ce44SJohn Forte	is_imported $svc
1348*fcf3ce44SJohn Forte	if [ $? = 0 ]
1349*fcf3ce44SJohn Forte	then
1350*fcf3ce44SJohn Forte		if [ -f $PKG_INSTALL_ROOT/$MANIFEST_PATH/$svc.xml ]
1351*fcf3ce44SJohn Forte		then
1352*fcf3ce44SJohn Forte			svccfg import $PKG_INSTALL_ROOT/$MANIFEST_PATH/$svc.xml
1353*fcf3ce44SJohn Forte
1354*fcf3ce44SJohn Forte			if [ $OS_MINOR -lt 11 ]
1355*fcf3ce44SJohn Forte			then
1356*fcf3ce44SJohn Forte				# workaround for 6221374--let local-fs know
1357*fcf3ce44SJohn Forte				# that it depends on us.
1358*fcf3ce44SJohn Forte				svcadm refresh ${FS_LOCAL_SVC}:default
1359*fcf3ce44SJohn Forte			fi
1360*fcf3ce44SJohn Forte		fi
1361*fcf3ce44SJohn Forte	fi
1362*fcf3ce44SJohn Forte}
1363*fcf3ce44SJohn Forte
1364*fcf3ce44SJohn Forte
1365*fcf3ce44SJohn Forte########################## MAIN ######################################
1366*fcf3ce44SJohn Forte
1367*fcf3ce44SJohn Forte# getopt processing
1368*fcf3ce44SJohn Forteenable=0
1369*fcf3ce44SJohn Fortedisable=0
1370*fcf3ce44SJohn Forteset_location=0
1371*fcf3ce44SJohn Forteget_info=0
1372*fcf3ce44SJohn Forter_flag=0
1373*fcf3ce44SJohn Fortep_flag=0
1374*fcf3ce44SJohn Fortewhile getopts "xedsirp" opt 2>/dev/null
1375*fcf3ce44SJohn Fortedo
1376*fcf3ce44SJohn Forte  	case $opt in
1377*fcf3ce44SJohn Forte	\?)
1378*fcf3ce44SJohn Forte           	help
1379*fcf3ce44SJohn Forte		;;
1380*fcf3ce44SJohn Forte	e)
1381*fcf3ce44SJohn Forte          	enable=1
1382*fcf3ce44SJohn Forte		;;
1383*fcf3ce44SJohn Forte	d)
1384*fcf3ce44SJohn Forte          	disable=1
1385*fcf3ce44SJohn Forte		;;
1386*fcf3ce44SJohn Forte	x)
1387*fcf3ce44SJohn Forte          	xopt="set -x"
1388*fcf3ce44SJohn Forte		set -x
1389*fcf3ce44SJohn Forte		;;
1390*fcf3ce44SJohn Forte	s)
1391*fcf3ce44SJohn Forte		set_location=1
1392*fcf3ce44SJohn Forte		;;
1393*fcf3ce44SJohn Forte	i)
1394*fcf3ce44SJohn Forte		get_info=1
1395*fcf3ce44SJohn Forte		;;
1396*fcf3ce44SJohn Forte	r)
1397*fcf3ce44SJohn Forte		r_flag=1
1398*fcf3ce44SJohn Forte		;;
1399*fcf3ce44SJohn Forte	p)
1400*fcf3ce44SJohn Forte		p_flag=1
1401*fcf3ce44SJohn Forte		;;
1402*fcf3ce44SJohn Forte	esac
1403*fcf3ce44SJohn Fortedone
1404*fcf3ce44SJohn Forte
1405*fcf3ce44SJohn Forte# at most one option (besides -x) may be specified at a time
1406*fcf3ce44SJohn Forteoptions_count=$((enable + disable + set_location + get_info))
1407*fcf3ce44SJohn Forteif [ $options_count -gt 1 ]
1408*fcf3ce44SJohn Fortethen
1409*fcf3ce44SJohn Forte	help
1410*fcf3ce44SJohn Forteelif [ $options_count = 0 ]
1411*fcf3ce44SJohn Fortethen
1412*fcf3ce44SJohn Forte	NO_ARGS=1
1413*fcf3ce44SJohn Fortefi
1414*fcf3ce44SJohn Forte
1415*fcf3ce44SJohn Forteif (( ((r_flag + p_flag) > 0) && ((enable | disable) == 0) ))
1416*fcf3ce44SJohn Fortethen
1417*fcf3ce44SJohn Forte	echo "-r and -p options may only be used with -d or -e options" >&2
1418*fcf3ce44SJohn Forte	return 1
1419*fcf3ce44SJohn Forteelif (( p_flag && disable ))
1420*fcf3ce44SJohn Fortethen
1421*fcf3ce44SJohn Forte	echo "The -p option may not be used with the -d option" >&2
1422*fcf3ce44SJohn Forte	return 1
1423*fcf3ce44SJohn Fortefi
1424*fcf3ce44SJohn Forte
1425*fcf3ce44SJohn Forte
1426*fcf3ce44SJohn Forte
1427*fcf3ce44SJohn Forte# set all the system information variables
1428*fcf3ce44SJohn Forteget_system_state
1429*fcf3ce44SJohn Forte
1430*fcf3ce44SJohn Forte# if we're enabling, we need to make sure we have a valid dscfg out there.
1431*fcf3ce44SJohn Forteif [ $enable = 1 -a $VALID_LOCAL_DB != 1 ]
1432*fcf3ce44SJohn Fortethen
1433*fcf3ce44SJohn Forte	echo "Cannot find a valid configuration database" >&2
1434*fcf3ce44SJohn Forte	return 1
1435*fcf3ce44SJohn Fortefi
1436*fcf3ce44SJohn Forte
1437*fcf3ce44SJohn Forteif [ $NO_ARGS = 1 ]
1438*fcf3ce44SJohn Fortethen
1439*fcf3ce44SJohn Forte
1440*fcf3ce44SJohn Forte	# only initialize the database if necessary
1441*fcf3ce44SJohn Forte	if [ $VALID_LOCAL_DB = 1 ]; then
1442*fcf3ce44SJohn Forte		echo "Local configuration database is already initialized."
1443*fcf3ce44SJohn Forte	else
1444*fcf3ce44SJohn Forte		initialize_local_db
1445*fcf3ce44SJohn Forte		if [ $? != 0 ]; then
1446*fcf3ce44SJohn Forte			return 1
1447*fcf3ce44SJohn Forte		fi
1448*fcf3ce44SJohn Forte	fi
1449*fcf3ce44SJohn Forte
1450*fcf3ce44SJohn Forte	if [ $CLUSTER_CONFIGURED = 1 ]
1451*fcf3ce44SJohn Forte	then
1452*fcf3ce44SJohn Forte		if [ $VALID_CLUSTER_DB = 1 ]; then
1453*fcf3ce44SJohn Forte			printf "Cluster configuration database is already "
1454*fcf3ce44SJohn Forte			printf "initialized.\n"
1455*fcf3ce44SJohn Forte		else
1456*fcf3ce44SJohn Forte			# ask the user for a cluster database location
1457*fcf3ce44SJohn Forte			set_cluster_config
1458*fcf3ce44SJohn Forte
1459*fcf3ce44SJohn Forte			# initialize the new db
1460*fcf3ce44SJohn Forte			initialize_cluster_db
1461*fcf3ce44SJohn Forte			if [ $? != 0 ]; then
1462*fcf3ce44SJohn Forte				return 1
1463*fcf3ce44SJohn Forte			fi
1464*fcf3ce44SJohn Forte		fi
1465*fcf3ce44SJohn Forte
1466*fcf3ce44SJohn Forte	fi
1467*fcf3ce44SJohn Forte
1468*fcf3ce44SJohn Forte	# make sure that the local filesystem dependency type is correct
1469*fcf3ce44SJohn Forte	for svc in $SMF_ENABLE
1470*fcf3ce44SJohn Forte	do
1471*fcf3ce44SJohn Forte		check_fs_local_grouping $svc
1472*fcf3ce44SJohn Forte		if [ $? -ne 0 ]
1473*fcf3ce44SJohn Forte		then
1474*fcf3ce44SJohn Forte			# NOTE: check_fs_local_grouping sets CORRECT_GROUPING
1475*fcf3ce44SJohn Forte			# To avoid this issue in the future, always administer
1476*fcf3ce44SJohn Forte			# the services using dscfgadm.
1477*fcf3ce44SJohn Forte			printf "Warning: Fixing dependency for $svc.\n"
1478*fcf3ce44SJohn Forte			set_fs_local_grouping $svc $CORRECT_GROUPING
1479*fcf3ce44SJohn Forte			if [ $? -ne 0 ]
1480*fcf3ce44SJohn Forte			then
1481*fcf3ce44SJohn Forte				return 1
1482*fcf3ce44SJohn Forte			fi
1483*fcf3ce44SJohn Forte		fi
1484*fcf3ce44SJohn Forte	done
1485*fcf3ce44SJohn Forte
1486*fcf3ce44SJohn Forte	# give the user the chance to startup AVS services, if not started
1487*fcf3ce44SJohn Forte	check_enabled
1488*fcf3ce44SJohn Forte	if [ $? = 1 ]; then
1489*fcf3ce44SJohn Forte		if [ $OLD_VALID_LOCAL_DB = 0 ]; then
1490*fcf3ce44SJohn Forte			printf "WARNING: AVS services are running on a system "
1491*fcf3ce44SJohn Forte			printf "which had no valid configuration\ndatabase\n"
1492*fcf3ce44SJohn Forte		fi
1493*fcf3ce44SJohn Forte		show_enabled
1494*fcf3ce44SJohn Forte	else
1495*fcf3ce44SJohn Forte		ask_to_enable
1496*fcf3ce44SJohn Forte		if [ $? = 1 ]; then
1497*fcf3ce44SJohn Forte			enable_services
1498*fcf3ce44SJohn Forte			if [ $? != 0 ]
1499*fcf3ce44SJohn Forte			then
1500*fcf3ce44SJohn Forte				return 1
1501*fcf3ce44SJohn Forte			fi
1502*fcf3ce44SJohn Forte		fi
1503*fcf3ce44SJohn Forte	fi
1504*fcf3ce44SJohn Forte
1505*fcf3ce44SJohn Forteelif [ $enable = 1 ]
1506*fcf3ce44SJohn Fortethen
1507*fcf3ce44SJohn Forte	enable_services
1508*fcf3ce44SJohn Forte	if [ $? != 0 ]
1509*fcf3ce44SJohn Forte	then
1510*fcf3ce44SJohn Forte		return 1
1511*fcf3ce44SJohn Forte	fi
1512*fcf3ce44SJohn Forte
1513*fcf3ce44SJohn Forteelif [ $disable = 1 ]
1514*fcf3ce44SJohn Fortethen
1515*fcf3ce44SJohn Forte    	disable_services
1516*fcf3ce44SJohn Forte	if [ $? != 0 ]
1517*fcf3ce44SJohn Forte	then
1518*fcf3ce44SJohn Forte		return 1
1519*fcf3ce44SJohn Forte	fi
1520*fcf3ce44SJohn Forte
1521*fcf3ce44SJohn Forteelif [ $get_info = 1 ]
1522*fcf3ce44SJohn Fortethen
1523*fcf3ce44SJohn Forte	display_info
1524*fcf3ce44SJohn Forte
1525*fcf3ce44SJohn Forteelif [ $set_location = 1 ]
1526*fcf3ce44SJohn Fortethen
1527*fcf3ce44SJohn Forte	if [ $CLUSTER_CONFIGURED = 1 ]
1528*fcf3ce44SJohn Forte	then
1529*fcf3ce44SJohn Forte		# ask the user for a cluster database location
1530*fcf3ce44SJohn Forte		set_cluster_config
1531*fcf3ce44SJohn Forte
1532*fcf3ce44SJohn Forte		# initialize the new db
1533*fcf3ce44SJohn Forte		initialize_cluster_db
1534*fcf3ce44SJohn Forte		if [ $? != 0 ]; then
1535*fcf3ce44SJohn Forte			return 1
1536*fcf3ce44SJohn Forte		fi
1537*fcf3ce44SJohn Forte	else
1538*fcf3ce44SJohn Forte		echo "$PROG -s is only available on Sun Cluster OE systems" >&2
1539*fcf3ce44SJohn Forte		return 1
1540*fcf3ce44SJohn Forte	fi
1541*fcf3ce44SJohn Fortefi
1542*fcf3ce44SJohn Forte
1543*fcf3ce44SJohn Fortereturn 0
1544*fcf3ce44SJohn Forte
1545*fcf3ce44SJohn Forte
1546*fcf3ce44SJohn Forte########################## MAIN ######################################
1547*fcf3ce44SJohn Forte
1548