#!/bin/ksh # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # ####################################################################### # # This file contains system setup requirements for scm. # # For systems before Solaris 10 it should be located in /etc/init.d # directory with the following links: # # ln /etc/init.d/scm /etc/rc0.d/K84scm # ln /etc/init.d/scm /etc/rc2.d/S002scm # # For Solaris 10 or later systems this script is run as part of SVC by # svc.startd and should be located in /lib/svc/method # #USAGE="Usage: $0 { start | stop } # ####################################################################### setvar SVCS = '/usr/bin/svcs' setvar DSCFG_DEPEND_NOCHK = ""/tmp/.dscfgadm_pid"" setvar OS_MINOR = $(/usr/bin/uname -r | /usr/bin/cut -d '.' -f2) source /lib/svc/share/smf_include.sh # Make sure prior SMF dependents are not 'online' # $1 = name of SMF service to validate dependents # proc do_smf_depends { setvar times = '0' setvar count = '1' if test $OS_MINOR -ge 11 { return 0 } elif test -f $DSCFG_DEPEND_NOCHK { for pid in [$(pgrep dscfgadm)] { if test $(grep -c $pid $DSCFG_DEPEND_NOCHK) -gt 0 { return 0 } } } elif test $(ps -ef | grep preremove | grep -c SUNWscmu) -gt 0 { return 0 } while [ $count -ne 0 ] { setvar count = $($SVCS -o STATE -D $1 2>>/dev/null | grep "^online" | wc -l) if test $count -ne 0 { # Output banner after waiting first 5 seconds # if test $times -eq 1 { echo "Waiting for $1 dependents to be 'offline'" $SVCS -D $1 2>>/dev/null | grep "^online" } # Has it been longer then 5 minutes? (60 * 5 secs.) # if test $times -eq 60 { echo "Error: Failed waiting for $1 dependents to be 'offline'" $SVCS -D $1 2>>/dev/null | grep "^online" exit $SMF_EXIT_ERR_FATAL } # Now sleep, giving other services time to stop # sleep 5 setvar times = $(expr $times + 1) } } return 0 } proc set_system_type { setvar CLINFO = '/usr/sbin/clinfo' setvar ESMSBIN = '/usr/sbin' setvar SCMBIN = '/usr/sbin' setvar ESMSCMLIB = '/usr/lib' setvar SCMLIB = '/usr/lib' setvar DSCFG_LOCKDB = '/etc/dscfg_lockdb' } proc do_stopsdbc { if test ! -r /dev/sdbc { return } ${SCMBIN}/scmadm -d if test $Status -ne 0 { # If the disable failed that means we have pinned data. echo "Cache Not Deconfigured" } } proc do_stopnskernd { ps -e | grep -w nskernd > /dev/null 2>&1 if test $Status -eq 0 { # make sure that all data services are unloaded before stopping # nskernd - cannot stop nskernd when its threads could be in use # Note: sv is unloadable, but its threadset is shutdown in the # final close(9e) call. setvar stop = '1' for m in [ste rdc rdcsrv ii sdbc] { setvar mid = $(/usr/sbin/modinfo | grep -w $m | awk '{print $1}' -) if test -z $mid { continue # not loaded } /usr/sbin/modunload -i $mid > /dev/null 2>&1 if test $Status -ne 0 { setvar stop = '0' break } } # kill nskernd if we can setvar pid = $(ps -e | grep -w nskernd | sed -e 's/^ *//' -e 's/ .*//) if test $stop -eq 1 { if test -n $pid { kill -15 $pid } } } if test -r /dev/ncall -a -x $ESMSCMLIB/ncalladm { $ESMSCMLIB/ncalladm -d } } proc do_stopdscfglockd { setvar pid = $(ps -e | grep -w dscfgloc | sed -e 's/^ *//' -e 's/ .*//) if test -n $pid { kill -15 $pid } } proc do_stop { do_smf_depends "system/nws_scm" do_stopsdbc do_stopnskernd do_stopdscfglockd } proc do_nskernd { if test -x $ESMSCMLIB/ncalladm { $ESMSCMLIB/ncalladm -e } ps -e | grep -w nskernd > /dev/null 2>&1 if test $Status -ne 0 { ${SCMLIB}/nskernd if test $Status -ne 0 { echo "Error: Unable to start nskernd" exit $SMF_EXIT_ERR_FATAL } } } proc do_dscfglockd { ps -e | grep -w dscfgloc > /dev/null 2>&1 if test $Status -ne 0 { rm -f /var/tmp/.cfglockd.pid } else { # dscfglockd already running return } if ${CLINFO} { # # create or update the dscfg_lockdb file # # create clean tmpnodelist setvar NODELIST = "/tmp/$Pid.dscfg_nodelist" rm -f $NODELIST >/dev/null 2>&1 touch $NODELIST if test -x /usr/cluster/bin/scstat { # get valid names in cluster /usr/cluster/bin/scstat -n | grep node: | \ awk '{print $3}' >> $NODELIST if test ! -f $DSCFG_LOCKDB { printf "In clustered environment.\n" printf "creating per node dscfg_lockdb database" printf " with following nodenames:\n" cat $NODELIST cp $NODELIST $DSCFG_LOCKDB } else { # check if there are any changes diff $NODELIST $DSCFG_LOCKDB > /dev/null if test $Status != 0 { printf "The cluster node names have " printf "changed. Updating dscfg_lockdb " printf "database.\n" printf "Previous node names:\n" cat $DSCFG_LOCKDB printf "New node names:\n" cat $NODELIST rm -f $DSCFG_LOCKDB cp $NODELIST $DSCFG_LOCKDB } } } else { # we're in a cluster, but scstat is not available printf "In clustered environment.\n" printf "Required configuration file, $DSCFG_LOCKDB\n" printf "was not properly populated with the cluster " printf "nodenames.\nThis file needs to be manually" printf "updated with the cluster\nnodenames before " printf "reboot. Refer to Sun Storage Availability\n" printf "Suite Installation Guide for details.\n" } # clustered start of dscfglockd if test -f $DSCFG_LOCKDB { printf "Starting dscfglockd\n" ${SCMLIB}/dscfglockd -f $DSCFG_LOCKDB } else { printf "WARNING: Mis-Configuration of Availability " printf "Suite for Sun Cluster\n" printf "WARNING: Can't find configuration file for " printf "dscfglockd\n" } rm -f $NODELIST } } proc do_sdbc { ${SCMBIN}/scmadm -e } proc do_start { # do nothing if we do not have a dscfg if test ! -f /etc/dscfg_local { echo "Cannot find Availability Suite configuration location" exit $SMF_EXIT_ERR_NOSMF } # # Ordering: # dscfglockd -- locking must be present before any dscfg access # nskernd -- starts infrastructure (nskernd, ncall). # sdbc -- start the cache itself # do_dscfglockd do_nskernd do_sdbc } proc do_usage { echo "Usage: $0" echo " start" echo " stop" exit 1 } set_system_type setvar USED = '0' setvar ACTION = '' setvar CLUSTERTAG = '' match $Argc { with '0' do_usage with '1' setvar ACTION = "$1" setvar USED = '1' with '2' setvar ACTION = "$1" setvar CLUSTERTAG = "$2" setvar USED = '1' exit 0 with '*' do_usage } if test $USED = 0 { do_usage } if test $ACTION = "start" { do_start } elif test $ACTION = "stop" { do_stop } else { do_usage } exit $SMF_EXIT_OK