: Not a shell script but rather a copy-paste input
#
# Andrei.Ryjov@spasu.net Fri Oct 27 10:47:19 MEST 2006
# Post-Jumpstart SC configuration
#
#
#######################################################3#
#
#  Commands to run on BOTH nodes
#
MANPATH=$MANPATH:/usr/cluster/man
PATH=$PATH:/usr/cluster/bin
export PATH MANPATH

chmod 755 /export/home/.

#
# Get rid of annoying motd at every "su -" run by resource monitors
#
>/etc/motd


#
# Replace the /dev/[r]dsk by /dev/global/[r]dsk for globally mounted filesystems
# and enable automatic mounting at boot (replace "no" to "yes" in vfstab)
#
SHARED_DIRS=`awk  '$1~/^\/dev\/dsk\/c[0-9][0-9]*t/ && $3~/\/global\/[^.]/ {print $3}' /etc/vfstab | sort -u`
SHARED_DISKS=`awk '$1~/^\/dev\/dsk\/c[0-9][0-9]*t/ && $3~/\/global\/[^.]/ {print $1}' /etc/vfstab | awk -F/ '$NF~/^c[0-9][0-9]*t/ {print $NF}' | sed 's/s[0-9]$//' | sort -u`
cp /etc/vfstab /etc/vfstab.pre-`basename $0`
for i in $SHARED_DISKS; do
  DID=`/usr/cluster/bin/scdidadm -l $i | awk -F/ '{print $NF}'`
  DID=`echo $DID`
  #
  # Make sure dev/did and dev/global instances refer to the same pseudo
  #
  [ x$DID != x ] || { echo "\n\n\nNo DID for $i - exiting\n\n\n"; /bin/sh; }
  [ `ls -lL /dev/did/rdsk/${DID}s2 | awk '{print $5}'` = `ls -lL /dev/global/rdsk/${DID}s2 | awk '{print $5}'` ] || { echo "\n\nDID and GLOBAL instances differ!"; /bin/sh; }

  printf "
    g/\/dev\/dsk\/${i}s/
    s/\/dev\/dsk\/${i}s/\/dev\/global\/dsk\/${DID}s/
    s/\/dev\/rdsk\/${i}s/\/dev\/global\/rdsk\/${DID}s/
    s/forcedirectio/forcedirectio,global/
    s/ no / yes /
    w
    q
  " | expand | sed 's/^ *//;/^ *$/d' | ed -s /etc/vfstab
done

diff /etc/vfstab.pre-`basename $0` /etc/vfstab

#
# The following loop can also be run on both nodes, however, you'll be glad
# to discover that "the other" node will report filesystems already umounted.
# Welcome to the Cluster Filesystem World!
#
for i in $SHARED_DIRS; do
  /sbin/umount $i
  /sbin/mount  $i   || { echo "\n\n\nFailed to remount $i - pausing\n\n"; /bin/sh; }
done

#######################################################
#
#  Commands to run on EITHER node only
#
#######################################################
#
# Add the quirum device. It can be any disk, not necessarily the unused one
#
scconf -p | grep "Quorum devices:" | grep NULL && {
  scconf -a -q globaldev=d4
  scconf -c -q reset
  scconf -a -T node=.
}

scconf -p | grep "Quorum devices:"

#
# Define resource type that we'll need.
# Standard Sun resource types are OK
#
#
scrgadm -a -t SUNW.gds:5  # Thats for any generic data service - we just need the start/stop/check method.
scrgadm -a -t SUNW.HAStoragePlus:2 # thats for cluster storage. We shall failover it

#
# A little function to fetch the global device name from resourcegroup name,
# we'll use it below in resource definitions
GetGDev() {
  [ x$1 = x ] && { echo "\n\nArg1 must be RG name"; /bin/sh; }
  GDev=`/sbin/mount | awk '$1~/\/'$1'$/ {print $3}' | awk -F/ '{print $NF}' | awk -Fs '{print $1}'`
  [ x$GDev = x ] && { echo "\n\nFailed to find DID for $1"; /bin/sh; }
  echo dsk/$GDev
}

#
# Now, finally, define the resources
#
RG=MW1
scrgadm -a    -g $RG  -h gen0suasp07,gen0suasp08
scrgadm -c    -g $RG  -y Pathprefix=/global/MQHA/$RG
scrgadm -c    -g $RG  -y RG_description="Middleware SC Service group # 1"
scrgadm -a -L -g $RG  -l ngmwcell1 -y R_description="LogicalHostname resource for RG $RG"
scrgadm -a    -g $RG  -j cfs4$RG   -t SUNW.HAStoragePlus:2 -x GlobalDevicePaths=`GetGDev $RG` -y R_description="Failover C-Filesystem for RG $RG"
#
RG=MW2
scrgadm -a    -g $RG  -h gen0suasp08,gen0suasp07
scrgadm -c    -g $RG  -y Pathprefix=/global/MQHA/$RG
scrgadm -c    -g $RG  -y RG_description="Middleware SC Service group # 2"
scrgadm -a -L -g $RG  -l ngmwcell2 -y R_description="LogicalHostname resource for RG $RG"
scrgadm -a    -g $RG  -j cfs4$RG   -t SUNW.HAStoragePlus:2 -x GlobalDevicePaths=`GetGDev $RG` -y R_description="Failover C-Filesystem for RG $RG"
#
RG=DB
scrgadm -a    -g $RG  -h gen0suasp07,gen0suasp08
scrgadm -c    -g $RG  -y Pathprefix=/global/MQHA/$RG
scrgadm -c    -g $RG  -y RG_description="Database SC Service group"
scrgadm -a -L -g $RG  -l ngdbcell  -y R_description="LogicalHostname resource for RG $RG"
scrgadm -a    -g $RG  -j cfs4$RG   -t SUNW.HAStoragePlus:2 -x GlobalDevicePaths=`GetGDev $RG` -y R_description="Failover C-Filesystem for RG $RG"

#
#
# You may need to run the resource cleanup loop twice, to get rid of dependants
# it removes the data service resources only, not the network type ones.
# Use with care - it may remove resource that you wanted to keep,
# for instance, cfs4...
#
# Make sure you know what this loop does and how to modify it to remove
# only what you want to remove
#
#for i in `scrgadm -p | grep 'Res name:' | awk '$NF!~/cell/ {print $NF}'` ; do
#  echo $i
#  scswitch -n -j $i
#  scrgadm  -r -j $i
#done

#
# Location of StartStopCheck script, we'll need in in resource properties below.
#
S=/MQHA/SC/Scripts/StartStopCheck

#
# Define the resource definition function to save typing,
# and formalize the procedure as much as possible.
#
# RunC stands for "RunCommand"
#
# Note that we suggest the service to run "sh $S" instead of just "$S".
# No idea why, but on the Global Filesystem, executable shell scripts.. aren't executable.
# But they get just happily interpreted by shell.
#
RunC() {
  RGROUP=$1; RCLASS=$2; RNAME=$3
  C="
    scrgadm -a
	-j $RNAME
	-g $RGROUP
	-t SUNW.gds:5
	-y Scalable=false
	-y Port_list=1450/tcp
	-y R_description=\"$RCLASS $RNAME in $RGROUP\"
	-x Start_command=\"/bin/sh $S $RCLASS $RNAME start\"
	-x Stop_command=\"/bin/sh  $S $RCLASS $RNAME stop\"
	-x Probe_command=\"/bin/sh $S $RCLASS  $RNAME check\"
  "
  eval $C
}

RunC MW1 MQ MGENPH1GM1
RunC MW1 MQ MGENPH1BK1
RunC MW1 MB MPRDCFG1
RunC MW1 MB MPRDBRK1

RunC MW2 MQ MGENPH1GM2
RunC MW2 MQ MGENPH1BK2
RunC MW2 MB MPRDCFG2
RunC MW2 MB MPRDBRK2

RunC DB  DB db2inst1

#
# Define resource dependencies, as per IBM's document
#
scrgadm -c -j db2inst1 -y Resource_dependencies=cfs4DB
scrgadm -c -j MPRDBRK1 -y Resource_dependencies=MGENPH1BK1,cfs4MW1,db2inst1
scrgadm -c -j MPRDCFG1 -y Resource_dependencies=MGENPH1BK1,cfs4MW1
scrgadm -c -j MPRDBRK2 -y Resource_dependencies=MGENPH1BK2,cfs4MW2,db2inst1
scrgadm -c -j MPRDCFG2 -y Resource_dependencies=MGENPH1BK2,cfs4MW2

#
# Check that start/stop/check properties are set correctly
#
scrgadm -pvvv | grep Start_ | grep value

#
# The startup order is important
# Remember, the groups start on different nodes!
# No matter which node you run commands from
#
# Watch the consoles and enjoy
# Logs go to /var/adm/messages
#
scswitch   -Z -g DB
scswitch   -Z -g MW1
scswitch   -Z -g MW2
