# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2010 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
typeset -r CTAG_NULL="-"
#
# help message
#
{
echo "\
usage:
$PROG -i
$PROG -e [-r][-p]
$PROG -d [-r]" >&2
if [ $CLUSTER_CONFIGURED -eq 1 ]; then
echo "\
$PROG -s" >&2
fi
echo "\
-i : display information on the Availability Suite services
-e : enable Availability Suite services (all, by default)
-d : disable Availability Suite services (all, by default)
-p : enable Point in Time Copy" >&2
if [ $CLUSTER_CONFIGURED -eq 1 ]; then
echo "\
-s : set the location of the cluster configuration database" >&2
fi
echo "\
-x : turn on script debugging (may be used with any valid option)
When executed with no options or with nothing but -x, $PROG runs in
interactive fashion, allowing the user to initialize the local (and
if applicable, the cluster) configuration database, and to start the
Availability Suite services." >&2
exit 2
}
########################## SET GLOBAL VARIABLES ######################
# root directory
export PKG_INSTALL_ROOT
# set lib path
export LD_LIBRARY_PATH
# set dscfg
export DSCFG
# set parser config location
export PCONFIG
# set local dscfg location
export LOCAL_DSCFG="/etc/dscfg_local"
# set cluster dscfg reference file
export CLUSTER_REF="/etc/dscfg_cluster"
# a service that has a dependency on us
FS_LOCAL_SVC="svc:/system/filesystem/local"
DSCFG_DEPEND_NOCHK="/tmp/.dscfgadm_pid"
# SMF defines
# SMF services (enable and disable)
SMF_ENABLE="nws_scm nws_sv nws_ii nws_rdc nws_rdcsyncd"
SMF_DISABLE="nws_rdcsyncd nws_rdc nws_ii nws_sv nws_scm"
# state of each service
# set path
export PATH
# set architecture
export ARCH
# number of sectors required for database
# 1024*1024*5.5/512
REQUIRED=11264
# must set here, else seen as null in MAIN
NO_ARGS=0
# for debugging
xopt=
# set lengthy message here
CLUST_LOC_MESS="The current location is invalid for a Sun StorageTek \
Data Services configuration database. Once a valid location is \
entered (raw slice on \"did\" device), you may upgrade the existing \
database to this new location - following the procedure outlined \
in the Installation and Configuration Guide."
########################## SET GLOBAL VARIABLES ######################
########################## ERROR ####################################
# called with optional error msg $1
# prints basic guidelines for configuration of the database location
{
echo >&2
echo "INSTALLATION ERROR" >&2
echo "Error: $1" >&2
echo >&2
if [ $? -eq 1 ]; then
echo "GENERAL INSTALLATION RULES:" >&2
echo "\tBecause you are installing on a cluster," >&2
echo "\tthe database must be located on a raw slice of a did device.">&2
fi
# let?
}
########################## ERROR ####################################
########################## ALL LOCATION TESTS ########################
# sets numerous environment variables describing the state of the system
{
IN_CLUSTER=$?
if [ $IN_CLUSTER = 1 ]; then
else
fi
}
# Checks if in cluster
# returns 1 if in cluster, else 0
#
{
if [ $? -eq 0 ]; then
return 1
else
return 0
fi
else
return 0
fi
}
# checks if a system is configured as a cluster
# returns 1 if configured as a cluster, 0 if not
#
{
return 1
else
return 0
fi
}
# Check the list of Sun Cluster device groups known in the dscfg, determing
# if they are currently enabled on this Sun Cluster node. If so, fail allowing
# the system administator to scswitch them elsewhere.
#
{
if [ $VALID_CLUSTER_DB == 1 ]; then
DEVICE_GROUPS=`$DSCFG -s $FILE_LOC -l 2>/dev/null | \
for x in $DEVICE_GROUPS
do
if [ $? -eq 1 ]
then
fi
done
then
print "The following Sun Cluster device groups are in use "
print "by Availability Suite on this node."
print ""
print "$IN_USE"
print ""
print "'scswitch' them to another Sun Cluster node before "
print "attempting to disable any data services."
return 1
else
return 0
fi
fi
return 0
}
# checks to see if this is a char device in the
#
{
return 1
else
return 0
fi
}
#
# checks size of area for db location
#
{
# if in cluster look for d*s*
echo "SLICE at $1 not found on this device"
return 0
fi
# if required size is greater than space available, then fail
return 0
else
return 1
fi
}
# looks in dscfg_cluster reference file. if a location is configured,
# tests to see if it is a valid database. if so, returns 1
#
{
if [ -s $CLUSTER_REF ]; then
FILE_LOC=`head -1 $CLUSTER_REF`
return $?
else
return 0
fi
}
# checks for the existence of dscfg_local database, and if it exists,
# tests to see if it is a valid database. if so, returns 1
#
{
if [ -s $LOCAL_DSCFG ]; then
return $?
else
return 0
fi
}
# used to test if a valid DS config database exists on machine already
# MAGIC_STRING is the top line in the config used in v3.1 & v3.2
#
{
# dscfg distinct strings, varies on the architecture
then
MAGIC_STRING="MAGI"
then
MAGIC_STRING="IGAM"
fi
# Create a PID unique temporary file
# Write the first or 16th block (skipping over VTOC) to
# the TMP_FILE, then scan for the presence of the "MAGI"
#
do
if [ ! -z "$1" ]; then
return 1
fi
fi
done
return 0
}
########################## ALL LOCATION TESTS ########################
########################## MAIN FUNCTIONS ############################
# since location already has been set, asks what to do now? keeping
# it still checks the size (since an upgrade from 3.0 may still be
# occuring) and also checks if was an old cluster config on disallowed
#
# returns:
# 0 if cluster location is invalid or the user does not want to keep it
# 1 if the location is valid and the user wants to keep it.
#
{
NOTE="\nThe Sun StorageTek Data Services database configuration"
echo $NOTE
echo "\nCurrent location: $PKG_INSTALL_ROOT$FILE_LOC"
QUEST="Would you like to preserve the existing configuration"
#Since the user has said "yes I want to keep this current one"
#it may actually be a 3.x database, which only required 4.5mb
#space, so now will check that there is room to grow another 1mb"
if [ $? = 0 ]; then
return 0
else
return 1
fi
;;
*)
return 0
;;
esac
}
#
# asks if user wants to keep existing db information, overwrite with
# a new db, or view the contents, and be asked again...
# returns:
# 0 if old location is bad
# 1 if old location is good
#
{
echo "\nIt appears a valid database configuration exists here already."
while true
do
echo "\nWould you like to preserve this information and continue?"
echo "\ty - preserve current configuration"
echo "\tn - overwrite with new configuration"
echo "\tmaybe - view contents of current configuration"
y)
if [ $? = 0 ]; then
return 0
else
return 1
fi
;;
n)
if [ $? = 0 ]; then
return 0
else
return 1
fi
;;
# print contents of this db config.
echo "\nContents of database configuration found at $SAFE_LOC are:"
continue
;;
esac
done
}
# gets location from user
#
{
#Checks for absolute path name, and if file name and file doesn't
#exist, creates it.
echo "\n\n----------ENTER DATABASE CONFIGURATION LOCATION-----------------"
echo "Note: Please ensure this location meets all requirements specified"
echo "in the Availability Suite Installation Guide."
if [ $? = 1 ]
then
exit 1
fi
# allow non-root user to access for least privileges
}
#
# tests for proper config
#
# returns:
# 0 if bad location
# 1 if good location
#
{
# set to FILE_LOC
LOCATION=$1
did_clust_msg="You are in cluster and $LOCATION is not valid DID device"
# Set "actual file location" variable here to equal file location
# entered by user because getting here means contains_data was already
# successfully called before and now the two can equal each other for
# future testing.
if [ $IN_CLUSTER = 1 -o $CLUSTER_CONFIGURED = 1 ]; then
if [ $? = 0 ]; then
return 0
fi
else
return 0
fi
else
echo "Location may not be changed in a non Sun Cluster OE." 2>&1
return 0
fi
if [ $? != 1 ]; then
return 0
else
return 1
fi
}
#
# Notifies the user that the SMF services are online,
# and gives him the option to disable the services before proceeding. If
# the services are not disabled, the program cannot proceed with setting
# a new dscfg location.
#
{
echo "\
\nYour services must be disabled before a new configuration location is set.\n"
QUEST="Would you like to disable the services now and continue with the"
case $ANS
return 1
;;
*)
return 0
;;
esac
}
#
# Asks the user if he would like to enable the services now. If so,
# import them (if necessary) and enable them.
#
{
echo "\
\nIf you would like to start using the Availability Suite immediately, you may
start the SMF services now. You may also choose to start the services later
using the $PROG -e command."
QUEST="Would you like to start the services now? "
case $ANS
return 1
;;
*)
return 0
;;
esac
}
#
# display information about the system
#
{
typeset grp_error_flg=0
for i in $SMF_ENABLE
do
is_imported $i
if [ $? = 1 ]
then
if [ $? -ne 0 ]
then
svc="${i}***"
else
svc=$i
fi
fi
done
print "\nAvailability Suite Configuration:"
printf "Local configuration database: "
if [ $VALID_LOCAL_DB = 1 ]
then
print "valid"
else
print "invalid"
fi
if [ $CLUSTER_CONFIGURED = 1 ]
then
printf "cluster configuration database: "
if [ $VALID_CLUSTER_DB = 1 ]
then
print "valid"
print "cluster configuration location: ${FILE_LOC}"
else
print "invalid"
fi
fi
if [ $grp_error_flg -gt 0 ]
then
typeset p
typeset p_has
if [ $grp_error_flg -gt 1 ]
then
p="s"
p_has="have"
else
p=""
p_has="has"
fi
printf "dependency. To repair the\n"
printf "problem, run \"dscfgadm\".\n"
fi
}
#
# initialize the local configuration database (only called if none exists)
# returns 0 if successful, 1 if failed
#
{
echo "Could not find a valid local configuration database."
echo "Initializing local configuration database..."
# Make sure the new location is initialized properly
if [ $VALID_LOCAL_DB != 1 ]
then
echo "Unable to initialize local configuration database" >&2
return 1
else
echo "Successfully initialized local configuration database"
fi
return 0
}
#
# initialize the cluster configuration database, if necessary
# returns 0 if successful, 1 if failed
#
{
then
return 0
fi
echo "Initializing cluster configuration database..."
${DSCFG} -s ${FILE_LOC} -C $CTAG_NULL > /dev/null 2>&1
echo y | ${DSCFG} -i -C $CTAG_NULL > /dev/null 2>&1
${DSCFG} -i -p ${PCONFIG} -C $CTAG_NULL > /dev/null 2>&1
# make sure the cluster db is valid now
if [ $VALID_CLUSTER_DB != 1 ]
then
echo "Unable to initialize cluster configuration database" >&2
return 1
else
echo "Successfully initialized cluster configuration database"
fi
return 0
}
#
# prompt the user for a config location and set AVS to use that location
#
{
REPEAT=0
# See if user has entered location already, and it was an existing
# db. Retruns FILE_LOC value
if [ $VALID_DB_ENTERED = 1 ]; then
# reset
# if 1, location passes, and FILE_LOC being passed to end, else
# set VALID_CLUSTER_DB to 0 since the "valid one" isn't valid anymore
# (bad size, etc) thereby when looping go straight to get_location
if [ $? = 1 ]; then
REPEAT=1
continue
else
continue
fi
fi
# if 1, then valid db exists, now see what user wants to do
if [ $VALID_CLUSTER_DB = 1 ]; then
# if 0, then user can't or won't keep location. set PROMPT
# so we will get new location from user.
if [ $? = 0 ]; then
PROMPT=0
else
PROMPT=1
fi
fi
# if either are 0, then user wants or needs new db as outlined in
# earlier comments
if [ $VALID_CLUSTER_DB = 0 ] || [ $PROMPT = 0 ]; then
#
# We cannot proceed if the services are running. Give the user
# a chance to stop the services. If he chooses not to, bail.
#
if [ $? = 1 ]
then
if [ $? = 0 ]
then
echo "A new configuration location was not set."
exit 1
else
if [ $? != 0 ]
then
exit 1
fi
fi
fi
# if 1, then user entered an existsing db location, loop
# back to ask what to do with it
if [ $? = 1 ]; then
continue
else
# if 0, that means location has failed, loop and
# get_location again
if [ $? = 0 ]; then
continue
fi
# entered location passes tests
REPEAT=1
continue
fi
else
# user wants to leave location where and how it is
# FILE_LOC being passed all the way to end
REPEAT=1
continue
fi
done
}
########################## MAIN FUNCTIONS ############################
######################## SMF HELPER FUNCTIONS ########################
#
# check if any SMF service is online (enabled)
#
{
typeset ret=0
typeset svc
for svc in $SMF_ENABLE
do
done
return $ret
}
#
# Display which services are enabled. (Must be called after check_enabled)
#
{
typeset svc
echo "\nThe following Availability Suite services are enabled:"
for svc in $SMF_ENABLE
do
then
fi
done
echo ""
}
#
# check if the given SMF service is online (enabled)
#
# $1: service name to check for
#
{
typeset en
is_imported $1
if [ $? = 1 ]
then
then
return 1
fi
fi
return 0
}
#
# If necessary, flag no dependency check
#
{
typeset pid
typeset msg=0
then
if [ -f $DSCFG_DEPEND_NOCHK ]
then
echo "Another dscfgadm disable is in progress."
echo "Waiting for pid: $pid to terminate..."
while [ -f $DSCFG_DEPEND_NOCHK ]
do
then
printf "\nAnother dscfgadm disable "
printf " be in progress.\n"
printf "If this is not the case, you "
printf "may remove "
fi
sleep 5
done
fi
echo $$ >> $DSCFG_DEPEND_NOCHK
fi
}
#
# If necessary, remove the no dependency check flag
#
{
then
fi
}
#
# set the filesystem/local dependency type and refresh
#
# $1: service name
# $2: either "require_all" or "optional_all"
#
{
typeset svc=$1
typeset dep_group=$2
# set proper dependency type for fs-local
if [ $svc != nws_rdcsyncd ]; then
svccfg -s $FS_LOCAL_SVC setprop \
if [ $? -ne 0 ]
then
printf "command failed: svccfg -s $FS_LOCAL_SVC "
printf "setprop ${svc}-local-fs/grouping=$dep_group "
printf ">&2\n"
return 1
fi
# we need local-fs to know about the new grouping attributes
if [ $? -ne 0 ]
then
print "Failed to refresh ${FS_LOCAL_SVC} >&2"
return 1
fi
fi
return 0
}
#
# check if the grouping dependency type for filesystem/local is correct
#
# input:
# $1: service name
#
# returns:
# 0 if the setting is correct
# 1 if the setting is incorrect
# outputs: sets CORRECT_GROUPING with the value of what the grouping should be.
#
{
typeset svc=$1
typeset cur_grouping
if [ $svc = nws_rdcsyncd ]
then
return 0
fi
# If it's not imported, we just return success, since we don't want
# further processing
if [ $? = 0 ]
then
return 0
fi
# get the current grouping value from the repository
cur_grouping=`svcprop -c -p ${svc}-local-fs/grouping $FS_LOCAL_SVC`
# Figure out what the grouping should be (based on enabled status)
if [ $? = 1 ]
then
CORRECT_GROUPING="require_all"
else
CORRECT_GROUPING="optional_all"
fi
then
# grouping is incorrect
return 1
else
# grouping is just fine
return 0
fi
}
#
# dependency, if appropriate.
#
# $1: service name to check for
# $2: "enable" or "disable"
#
{
typeset svc=$1
typeset command=$2
typeset enable_state
typeset dep_group
# If disabling, then enable_state better be true, and we are
# transitioning to "option_all" grouping
then
dep_group="optional_all"
# If enabling, then enable_state better be false, and we are
# transitioning to "require_all" grouping
then
dep_group="require_all"
else
fi
if [ $? = 1 ]
then
if [ $? = $enable_state ]
then
if [ $enable_state -eq 1 ]
then
# we're doing a disable--remove hard dependency
if [ $? -ne 0 ]
then
return 1
fi
fi
if [ $? != 0 ]
then
return 1
fi
if [ $enable_state -eq 0 ]
then
# we just did an enable--create hard dependency
if [ $? -ne 0 ]
then
return 1
fi
fi
else
echo "$svc service already ${command}d... skipping"
fi
fi
return 0
}
#
# This chart summarizes the behavior of the -r and -p sub-options for the
# -e and -d options.
# There are 5 possible states, and 5 transitions out of each state.
#
# states: (vertical axis)
# -------
# 0: no services enabled
# C: one or both core services enabled (illegal state)
# R: both core services and RM services enabled
# P: both core services and PITC service enabled
# A: all services enabled
#
# transitions: (horizontal axis)
# ------------
# +p: enable with -p flag
#
# The result of the function is the next state after the action has been
# successfully performed.
#
# +a | -a | +r | -r | +p |
# ++----+----+----+----+----+
# ++----+----+----+----+----+
# 0 || A | 0* | R | 0* | P |
# --++----+----+----+----+----+
# C || A* | 0* | R | 0 | P |
# --++----+----+----+----+----+
# R || A* | 0* | R* | 0 | A |
# --++----+----+----+----+----+
# P || A* | 0* | A* | P* | P* |
# --++----+----+----+----+----+
# A || A* | 0 | A* | P | A* |
# --++----+----+----+----+----+
#
# *: warning message is displayed, stating that a service is already
#
# enable the SMF services needed for the Availability Suite
#
{
typeset svc
# first, import them if they have not yet been imported
# if neither r_flag nor p_flag is set, enable all services
then
for svc in $SMF_ENABLE
do
if ! svc_operation $svc enable
then
return 1
fi
done
else
# figure out which services are enabled
# First, make sure both core services are enabled
do
then
return 1
fi
done
then
if ! svc_operation nws_ii enable
then
return 1
fi
fi
then
for svc in nws_rdc nws_rdcsyncd
do
if ! svc_operation $svc enable
then
return 1
fi
done
fi
fi
return 0
}
#
# disable the SMF services needed for the Availability Suite
#
{
typeset svc
if [ $? == 1 ]
then
return 1
fi
# This flags the shutdown scripts to not check to make sure the
# services' dependents have been disabled. The flag must be removed
# before returning from this function.
# NB: p_flag is not allowed for disables. II should not be
# disabled if sndr is enabled. If rdc is not enabled, disabling just
# II is equivalent to disabling all the remaining services.
# If no flags passed in, just disable everything
then
for svc in $SMF_DISABLE
do
if ! svc_operation $svc disable
then
return 1
fi
done
# Now that we've disable the services, lets unload them
# from the Solaris kernel
#
modinfo | grep '(nws:' | grep -v "kRPC Stub" | sort -r | cut -d' ' -f1 | xargs -l modunload -i 2>/dev/null
modinfo | grep '(nws:' | grep -v "kRPC Stub" | sort -r | cut -d' ' -f1 | xargs -l modunload -i 2>/dev/null
else
# we're disabling just rdc. If II is not already enabled,
# we disable core services, as well.
# figure out which services are enabled
for svc in nws_rdcsyncd nws_rdc
do
if ! svc_operation $svc disable
then
return 1
fi
done
then
do
then
return 1
fi
done
fi
fi
return 0
}
#
# check if a service has been imported into the repository
# $1: service to check
# returns 1 if it is imported, 0 if it is not
#
{
typeset svc=$1
if [ $? = 1 ]
then
return 0
else
return 1
fi
}
#
# import the SMF services into the repository, if necessary
#
{
typeset svc
for svc in $SMF_ENABLE
do
done
}
#
# check to see if an SMF service is in the repository. If it is not,
# import it in.
# $1: name of service to import
#
{
typeset svc=$1
if [ $? = 0 ]
then
if [ -f $PKG_INSTALL_ROOT/$MANIFEST_PATH/$svc.xml ]
then
then
# workaround for 6221374--let local-fs know
# that it depends on us.
fi
fi
fi
}
########################## MAIN ######################################
# getopt processing
enable=0
disable=0
get_info=0
r_flag=0
p_flag=0
do
\?)
;;
e)
enable=1
;;
d)
disable=1
;;
x)
xopt="set -x"
set -x
;;
s)
;;
i)
get_info=1
;;
r)
r_flag=1
;;
p)
p_flag=1
;;
esac
done
# at most one option (besides -x) may be specified at a time
then
elif [ $options_count = 0 ]
then
NO_ARGS=1
fi
then
echo "-r and -p options may only be used with -d or -e options" >&2
return 1
then
echo "The -p option may not be used with the -d option" >&2
return 1
fi
# set all the system information variables
# if we're enabling, we need to make sure we have a valid dscfg out there.
then
echo "Cannot find a valid configuration database" >&2
return 1
fi
if [ $NO_ARGS = 1 ]
then
# only initialize the database if necessary
if [ $VALID_LOCAL_DB = 1 ]; then
echo "Local configuration database is already initialized."
else
if [ $? != 0 ]; then
return 1
fi
fi
if [ $CLUSTER_CONFIGURED = 1 ]
then
if [ $VALID_CLUSTER_DB = 1 ]; then
printf "Cluster configuration database is already "
printf "initialized.\n"
else
# ask the user for a cluster database location
# initialize the new db
if [ $? != 0 ]; then
return 1
fi
fi
fi
# make sure that the local filesystem dependency type is correct
do
if [ $? -ne 0 ]
then
# NOTE: check_fs_local_grouping sets CORRECT_GROUPING
# To avoid this issue in the future, always administer
# the services using dscfgadm.
if [ $? -ne 0 ]
then
return 1
fi
fi
done
# give the user the chance to startup AVS services, if not started
if [ $? = 1 ]; then
if [ $OLD_VALID_LOCAL_DB = 0 ]; then
printf "WARNING: AVS services are running on a system "
printf "which had no valid configuration\ndatabase\n"
fi
else
if [ $? = 1 ]; then
if [ $? != 0 ]
then
return 1
fi
fi
fi
elif [ $enable = 1 ]
then
if [ $? != 0 ]
then
return 1
fi
elif [ $disable = 1 ]
then
if [ $? != 0 ]
then
return 1
fi
elif [ $get_info = 1 ]
then
elif [ $set_location = 1 ]
then
if [ $CLUSTER_CONFIGURED = 1 ]
then
# ask the user for a cluster database location
# initialize the new db
if [ $? != 0 ]; then
return 1
fi
else
echo "$PROG -s is only available on Sun Cluster OE systems" >&2
return 1
fi
fi
return 0
########################## MAIN ######################################