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