xref: /titanic_51/usr/src/cmd/avs/sdbc/etc/dscfg_reconfigure.cluster.sh (revision fcf3ce441efd61da9bb2884968af01cb7c1452cc)
1*fcf3ce44SJohn Forte#!/usr/bin/ksh
2*fcf3ce44SJohn Forte# CDDL HEADER START
3*fcf3ce44SJohn Forte#
4*fcf3ce44SJohn Forte# The contents of this file are subject to the terms of the
5*fcf3ce44SJohn Forte# Common Development and Distribution License (the "License").
6*fcf3ce44SJohn Forte# You may not use this file except in compliance with the License.
7*fcf3ce44SJohn Forte#
8*fcf3ce44SJohn Forte# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*fcf3ce44SJohn Forte# or http://www.opensolaris.org/os/licensing.
10*fcf3ce44SJohn Forte# See the License for the specific language governing permissions
11*fcf3ce44SJohn Forte# and limitations under the License.
12*fcf3ce44SJohn Forte#
13*fcf3ce44SJohn Forte# When distributing Covered Code, include this CDDL HEADER in each
14*fcf3ce44SJohn Forte# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*fcf3ce44SJohn Forte# If applicable, add the following below this CDDL HEADER, with the
16*fcf3ce44SJohn Forte# fields enclosed by brackets "[]" replaced with your own identifying
17*fcf3ce44SJohn Forte# information: Portions Copyright [yyyy] [name of copyright owner]
18*fcf3ce44SJohn Forte#
19*fcf3ce44SJohn Forte# CDDL HEADER END
20*fcf3ce44SJohn Forte#
21*fcf3ce44SJohn Forte#
22*fcf3ce44SJohn Forte# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23*fcf3ce44SJohn Forte# Use is subject to license terms.
24*fcf3ce44SJohn Forte#
25*fcf3ce44SJohn Forte# NWS DataServices within SunCluster reconfiguration script.
26*fcf3ce44SJohn Forte#
27*fcf3ce44SJohn Forte# Description:
28*fcf3ce44SJohn Forte#
29*fcf3ce44SJohn Forte# This script is called from /usr/cluster/lib/sc/run_reserve at
30*fcf3ce44SJohn Forte# appropriate times to start and stop the NWS DataServices as SunCluster
31*fcf3ce44SJohn Forte# disk device groups are brought online or taken offline.
32*fcf3ce44SJohn Forte#
33*fcf3ce44SJohn Forte# SNDR configuration requires that a resource group to be configured.
34*fcf3ce44SJohn Forte# 1. The resource group name should be same as device group name with -stor-rg
35*fcf3ce44SJohn Forte#    added. e.g. if device group name is abc-dg then resource group name
36*fcf3ce44SJohn Forte#    would be abc-dg-stor-rg.
37*fcf3ce44SJohn Forte# 2. It should have 2 resources in it, unless one of the resource types is the
38*fcf3ce44SJohn Forte#    SUNW.GeoCtlAVS. One of type SUNW.LogicalHostname and either SUNW.HAStorage
39*fcf3ce44SJohn Forte#    or SUNW.HAStoragePlus types. Resource type versioning is ignored.
40*fcf3ce44SJohn Forte#    HAStorage type resource, should have ServicePaths property set to
41*fcf3ce44SJohn Forte#    device group name. HAStoragePlus type resource, should have either the
42*fcf3ce44SJohn Forte#    FilesystemMountPoints pointing to a files system associated with the
43*fcf3ce44SJohn Forte#    device group name, or GlobalDevicePaths property set to device group name.
44*fcf3ce44SJohn Forte#    LogicalHostname type resource should have a failoverIP address in it and
45*fcf3ce44SJohn Forte#    it will be used by SNDR to communicate with the secondary side.
46*fcf3ce44SJohn Forte#
47*fcf3ce44SJohn Forte# As SNDR requires that the LogicalHost (failover) IP address which is a
48*fcf3ce44SJohn Forte# part of resource group for SNDR, to be hosted on the same node where the
49*fcf3ce44SJohn Forte# device group is, it tries to move the resource group also alongwith the
50*fcf3ce44SJohn Forte# device group, in become_primary case of run_reserve script. While
51*fcf3ce44SJohn Forte# in primary_to_secondary case, it will try to kill the switchover function
52*fcf3ce44SJohn Forte# if it is still running in background, after stopping NWS data services.
53*fcf3ce44SJohn Forte#
54*fcf3ce44SJohn Forte# Usage:
55*fcf3ce44SJohn Forte#
56*fcf3ce44SJohn Forte# /usr/cluster/sbin/dscfg_reconfigure { start | stop } diskgroup
57*fcf3ce44SJohn Forte#
58*fcf3ce44SJohn Forte# Configuration:
59*fcf3ce44SJohn Forte#
60*fcf3ce44SJohn Forte# Scripts to be run should have been symlinked into $NWS_START_DIR and
61*fcf3ce44SJohn Forte# $NWS_STOP_DIR.  Note that the scripts are processed in lexical order,
62*fcf3ce44SJohn Forte# and that unlike /etc/rc?.d/ there is no leading S or K character.
63*fcf3ce44SJohn Forte#
64*fcf3ce44SJohn Forte# Exit status:
65*fcf3ce44SJohn Forte#
66*fcf3ce44SJohn Forte# 0 - success
67*fcf3ce44SJohn Forte# 1 - error
68*fcf3ce44SJohn Forte#
69*fcf3ce44SJohn Forte
70*fcf3ce44SJohn Forte#
71*fcf3ce44SJohn Forte# Global variables
72*fcf3ce44SJohn Forte#
73*fcf3ce44SJohn Forte
74*fcf3ce44SJohn Forte# this program
75*fcf3ce44SJohn Fortetypeset -r ARGV0=$(basename $0)
76*fcf3ce44SJohn Forte
77*fcf3ce44SJohn Forte# directory full of start scripts
78*fcf3ce44SJohn Fortetypeset -r NWS_START_DIR=/usr/cluster/lib/dscfg/start
79*fcf3ce44SJohn Forte
80*fcf3ce44SJohn Forte# directory full of stop scripts
81*fcf3ce44SJohn Fortetypeset -r NWS_STOP_DIR=/usr/cluster/lib/dscfg/stop
82*fcf3ce44SJohn Forte
83*fcf3ce44SJohn Forte# the syslog facility to use.
84*fcf3ce44SJohn Forte# - conceptually this should be based on the output of
85*fcf3ce44SJohn Forte#   "scha_cluster_get -O SYSLOG_FACILITY", but that won't work early
86*fcf3ce44SJohn Forte#   during boot.
87*fcf3ce44SJohn Fortetypeset -r SYSLOG_FACILITY=daemon
88*fcf3ce44SJohn Forte
89*fcf3ce44SJohn FortePATH=$PATH:/usr/cluster/bin:/etc
90*fcf3ce44SJohn Forte
91*fcf3ce44SJohn Forte# Variables for retrying scswitch of Resource group for SNDR
92*fcf3ce44SJohn Forteretry_num=12
93*fcf3ce44SJohn Forteretry_interval=10
94*fcf3ce44SJohn Fortergname=
95*fcf3ce44SJohn Fortergstat=
96*fcf3ce44SJohn Forteskip_resource=0
97*fcf3ce44SJohn Fortecount_LogicalHostname=0
98*fcf3ce44SJohn Fortecount_HAStoragePlus=0
99*fcf3ce44SJohn Forte
100*fcf3ce44SJohn Forte# Since the switchover of the resource group is called in background,
101*fcf3ce44SJohn Forte# the stop action of the reconfig script will kill the background switchover
102*fcf3ce44SJohn Forte# if it is running. Since we are stopping the NWS services on the node, there
103*fcf3ce44SJohn Forte# is no need to switch the resource group, so  it is killed.
104*fcf3ce44SJohn Forte# The pid of the process is kept in file /var/run/scnws/$dg.pid.
105*fcf3ce44SJohn Forte# Input:  dg - device group
106*fcf3ce44SJohn Forte# Output: Nothing, kills the process
107*fcf3ce44SJohn Forte
108*fcf3ce44SJohn Fortefunction kill_scswitch
109*fcf3ce44SJohn Forte{
110*fcf3ce44SJohn Forte        dg=$1
111*fcf3ce44SJohn Forte        if [ -f /var/run/scnws/$dg.pid ]
112*fcf3ce44SJohn Forte        then
113*fcf3ce44SJohn Forte                for i in `cat /var/run/scnws/$dg.pid`
114*fcf3ce44SJohn Forte                do
115*fcf3ce44SJohn Forte                        pid=$i
116*fcf3ce44SJohn Forte                        kill -9 $pid
117*fcf3ce44SJohn Forte                done
118*fcf3ce44SJohn Forte                rm -f /var/run/scnws/$dg.pid
119*fcf3ce44SJohn Forte        fi
120*fcf3ce44SJohn Forte}
121*fcf3ce44SJohn Forte
122*fcf3ce44SJohn Forte# Get the status of the resource group on this node, using scha commands.
123*fcf3ce44SJohn Forte# Input: resource group - $1
124*fcf3ce44SJohn Forte# Output: Status
125*fcf3ce44SJohn Forte
126*fcf3ce44SJohn Fortefunction get_rgstat
127*fcf3ce44SJohn Forte{
128*fcf3ce44SJohn Forte	rg=$1
129*fcf3ce44SJohn Forte	rgstat=`scha_resourcegroup_get -O RG_STATE -G $rg`
130*fcf3ce44SJohn Forte}
131*fcf3ce44SJohn Forte
132*fcf3ce44SJohn Forte# This function is called in background from do_scswitch function, to
133*fcf3ce44SJohn Forte# switch the resource group to this node, which is becoming primary for
134*fcf3ce44SJohn Forte# the diskgroup. If the status of resource group is Offline, it will use
135*fcf3ce44SJohn Forte# scswitch command to switch the resource group to this node. If it has
136*fcf3ce44SJohn Forte# become Online, cleanup pid file. If it is Pending, the resource group
137*fcf3ce44SJohn Forte# is in the state of becoming online, so wait for sometime to become Online..
138*fcf3ce44SJohn Forte# scswitch may fail, so the function retries $retry_num times, waiting for
139*fcf3ce44SJohn Forte# $retry_interval seconds.
140*fcf3ce44SJohn Forte# Input: resource group - $1, Diskgroup/Diskset - $2
141*fcf3ce44SJohn Forte# Output: 0 - success, 1 - failure
142*fcf3ce44SJohn Forte
143*fcf3ce44SJohn Fortefunction switchfunc
144*fcf3ce44SJohn Forte{
145*fcf3ce44SJohn Forte        rg=$1
146*fcf3ce44SJohn Forte        dg=$2
147*fcf3ce44SJohn Forte	how_many=0
148*fcf3ce44SJohn Forte	sleep 2
149*fcf3ce44SJohn Forte	while [ $how_many != $retry_num ]
150*fcf3ce44SJohn Forte	do
151*fcf3ce44SJohn Forte		get_rgstat $rg
152*fcf3ce44SJohn Forte		case "$rgstat" in
153*fcf3ce44SJohn Forte		"ONLINE")
154*fcf3ce44SJohn Forte		 	rm -f /var/run/scnws/$dg.pid
155*fcf3ce44SJohn Forte			return 0
156*fcf3ce44SJohn Forte			;;
157*fcf3ce44SJohn Forte
158*fcf3ce44SJohn Forte		"OFFLINE")
159*fcf3ce44SJohn Forte			logger -p ${SYSLOG_FACILITY}.notice \
160*fcf3ce44SJohn Forte			-t "NWS.[$ARGV0]" `gettext "scswitch of resource group"` "$rg"
161*fcf3ce44SJohn Forte
162*fcf3ce44SJohn Forte			scswitch -z -g $rg -h $(hostname)
163*fcf3ce44SJohn Forte			retval=$?
164*fcf3ce44SJohn Forte			if [ $retval != 0 ]
165*fcf3ce44SJohn Forte			then
166*fcf3ce44SJohn Forte				sleep $retry_interval
167*fcf3ce44SJohn Forte				how_many=$(($how_many + 1))
168*fcf3ce44SJohn Forte			fi
169*fcf3ce44SJohn Forte			;;
170*fcf3ce44SJohn Forte
171*fcf3ce44SJohn Forte		"PENDING_ONLINE")
172*fcf3ce44SJohn Forte			logger -p ${SYSLOG_FACILITY}.notice \
173*fcf3ce44SJohn Forte			-t "NWS.[$ARGV0]" `gettext "pending online of resource group"` "$rg"
174*fcf3ce44SJohn Forte			sleep $retry_interval
175*fcf3ce44SJohn Forte			how_many=$(($how_many + 1))
176*fcf3ce44SJohn Forte			;;
177*fcf3ce44SJohn Forte
178*fcf3ce44SJohn Forte		*)
179*fcf3ce44SJohn Forte			logger -p ${SYSLOG_FACILITY}.notice \
180*fcf3ce44SJohn Forte			-t "NWS.[$ARGV0]" `gettext "Improper resource group status for Remote Mirror"` "$rgstat"
181*fcf3ce44SJohn Forte		 	rm -f /var/run/scnws/$dg.pid
182*fcf3ce44SJohn Forte			return 1
183*fcf3ce44SJohn Forte			;;
184*fcf3ce44SJohn Forte		esac
185*fcf3ce44SJohn Forte	done
186*fcf3ce44SJohn Forte	logger -p ${SYSLOG_FACILITY}.err \
187*fcf3ce44SJohn Forte	-t "NWS.[$ARGV0]" "Did not switch resource group for Remote Mirror. System Administrator intervention required"
188*fcf3ce44SJohn Forte 	rm -f /var/run/scnws/$dg.pid
189*fcf3ce44SJohn Forte	return 1
190*fcf3ce44SJohn Forte}
191*fcf3ce44SJohn Forte
192*fcf3ce44SJohn Forte
193*fcf3ce44SJohn Forte# This function calls switchfunc function in background, to switch the
194*fcf3ce44SJohn Forte# resource group for SNDR. It validates the diskgroup/diskset is configured
195*fcf3ce44SJohn Forte# for SNDR, checks if the resource group is in Managed state etc.
196*fcf3ce44SJohn Forte# If it detects a mis-configuration, it will disable SNDR for the
197*fcf3ce44SJohn Forte# device group being processed. This is to prevent cluster hangs and panics.
198*fcf3ce44SJohn Forte#
199*fcf3ce44SJohn Forte# The ServicePaths extension property of HAStorage type resource or the
200*fcf3ce44SJohn Forte# GlobalDevicePaths extension property of HAStoragePlus, both of which
201*fcf3ce44SJohn Forte# specify the device group, serve as a link or mapping to retrieve the
202*fcf3ce44SJohn Forte# resource group associated with the SNDR configured device group.
203*fcf3ce44SJohn Forte# Switchfunc is called in the background to avoid the deadlock situation arising
204*fcf3ce44SJohn Forte# out of switchover of resource group from within device group switchover.
205*fcf3ce44SJohn Forte#
206*fcf3ce44SJohn Forte# In run_reserve context, we are doing the device group switchover, trying to
207*fcf3ce44SJohn Forte# bring it online on the node. Device group is not completely switched online,
208*fcf3ce44SJohn Forte# until the calling script run_reserve returns. In the process, we are calling
209*fcf3ce44SJohn Forte# the associated SNDR resource group switchover using scswitch command.
210*fcf3ce44SJohn Forte# Resource group switchover will trigger the switchover of device group also.
211*fcf3ce44SJohn Forte#
212*fcf3ce44SJohn Forte# If resource group switchover is called in foreground, before the device
213*fcf3ce44SJohn Forte# group has become online, then it will result in switching the device group
214*fcf3ce44SJohn Forte# again, resulting in deadlock. Resource group can not become online until
215*fcf3ce44SJohn Forte# the device group is online and the device group can not become online until the
216*fcf3ce44SJohn Forte# script returns, causing this circular dependency resulting in deadlock.
217*fcf3ce44SJohn Forte#
218*fcf3ce44SJohn Forte# Calling the resource group switch in background allows current run_reserve
219*fcf3ce44SJohn Forte# script to return immediately, allowing device group to become online.
220*fcf3ce44SJohn Forte# If the device group is already online on the node, then the resource group
221*fcf3ce44SJohn Forte# does not cause the device group switchover again.
222*fcf3ce44SJohn Forte#
223*fcf3ce44SJohn Forte# Input: Device group dg - $1
224*fcf3ce44SJohn Forte# Output: 0 - success
225*fcf3ce44SJohn Forte#	  1 - either dg not applicable for SNDR or error
226*fcf3ce44SJohn Forte#	  2 - SNDR mis-configuration
227*fcf3ce44SJohn Forte
228*fcf3ce44SJohn Fortefunction do_scswitch
229*fcf3ce44SJohn Forte{
230*fcf3ce44SJohn Forte	dg=$1
231*fcf3ce44SJohn Forte
232*fcf3ce44SJohn Forte        if [ ! -x /usr/cluster/bin/scha_resource_get \
233*fcf3ce44SJohn Forte		-o ! -x /usr/cluster/bin/scha_resourcegroup_get ]
234*fcf3ce44SJohn Forte        then
235*fcf3ce44SJohn Forte                return 1
236*fcf3ce44SJohn Forte        fi
237*fcf3ce44SJohn Forte
238*fcf3ce44SJohn Forte# hard coded rg name from dg
239*fcf3ce44SJohn Forte	rgname="$dg-stor-rg"
240*fcf3ce44SJohn Forte	scha_resourcegroup_get -O rg_description -G $rgname > /dev/null
241*fcf3ce44SJohn Forte	if [ $? != 0 ]
242*fcf3ce44SJohn Forte	then
243*fcf3ce44SJohn Forte# There is no device group configured in cluster for SNDR with this cluster tag
244*fcf3ce44SJohn Forte		return 1
245*fcf3ce44SJohn Forte	fi
246*fcf3ce44SJohn Forte
247*fcf3ce44SJohn Forte# Check the state of resource group
248*fcf3ce44SJohn Forte
249*fcf3ce44SJohn Forte	get_rgstat $rgname
250*fcf3ce44SJohn Forte	if [ -z "$rgstat" \
251*fcf3ce44SJohn Forte		-o "$rgstat" = "UNMANAGED" -o "$rgstat" = "ERROR_STOP_FAILED" ]
252*fcf3ce44SJohn Forte	then
253*fcf3ce44SJohn Forte		logger -p ${SYSLOG_FACILITY}.notice \
254*fcf3ce44SJohn Forte		-t "NWS.[$ARGV0]" \
255*fcf3ce44SJohn Forte		`gettext "Improper Remote Mirror resource group state"` "$rgstat"
256*fcf3ce44SJohn Forte        	return 2
257*fcf3ce44SJohn Forte	fi
258*fcf3ce44SJohn Forte
259*fcf3ce44SJohn Forte# Check whether resources are of proper type and they are enabled
260*fcf3ce44SJohn Forte
261*fcf3ce44SJohn Forte	rs_list=`scha_resourcegroup_get -O resource_list -G $rgname`
262*fcf3ce44SJohn Forte	if [ -z "$rs_list" ]
263*fcf3ce44SJohn Forte	then
264*fcf3ce44SJohn Forte		logger -p ${SYSLOG_FACILITY}.notice \
265*fcf3ce44SJohn Forte		-t "NWS.[$ARGV0]" \
266*fcf3ce44SJohn Forte		`gettext "No resources in Remote Mirror resource group <$rgname>"`
267*fcf3ce44SJohn Forte		return 2
268*fcf3ce44SJohn Forte	fi
269*fcf3ce44SJohn Forte	for rs in $rs_list
270*fcf3ce44SJohn Forte	do
271*fcf3ce44SJohn Forte		rs_type=`scha_resource_get -O type -R $rs -G $rgname  | cut -d':' -f1`
272*fcf3ce44SJohn Forte		case "$rs_type" in
273*fcf3ce44SJohn Forte		SUNW.LogicalHostname)
274*fcf3ce44SJohn Forte			rs_enb=`scha_resource_get -O ON_OFF_SWITCH -R $rs -G $rgname`
275*fcf3ce44SJohn Forte			if [ "$rs_enb" = "ENABLED" ]
276*fcf3ce44SJohn Forte			then
277*fcf3ce44SJohn Forte			count_LogicalHostname=$(($count_LogicalHostname + 1))
278*fcf3ce44SJohn Forte			fi
279*fcf3ce44SJohn Forte			;;
280*fcf3ce44SJohn Forte		SUNW.HAStoragePlus)
281*fcf3ce44SJohn Forte			rs_enb=`scha_resource_get -O ON_OFF_SWITCH -R $rs -G $rgname`
282*fcf3ce44SJohn Forte			if [ "$rs_enb" = "ENABLED" ]
283*fcf3ce44SJohn Forte			then
284*fcf3ce44SJohn Forte			count_HAStoragePlus=$(($count_HAStoragePlus + 1))
285*fcf3ce44SJohn Forte			fi
286*fcf3ce44SJohn Forte			;;
287*fcf3ce44SJohn Forte		esac
288*fcf3ce44SJohn Forte	done
289*fcf3ce44SJohn Forte	if [ $count_LogicalHostname -lt 1 ]
290*fcf3ce44SJohn Forte	then
291*fcf3ce44SJohn Forte		logger -p ${SYSLOG_FACILITY}.notice \
292*fcf3ce44SJohn Forte		-t "NWS.[$ARGV0]" `gettext "Missing Enabled Logical Host in resource group <$rgname> for Remote Mirror"`
293*fcf3ce44SJohn Forte		return 2
294*fcf3ce44SJohn Forte	elif [ $count_LogicalHostname -gt 1 ]
295*fcf3ce44SJohn Forte        then
296*fcf3ce44SJohn Forte		logger -p ${SYSLOG_FACILITY}.notice \
297*fcf3ce44SJohn Forte		-t "NWS.[$ARGV0]" `gettext "Too Many Enabled Logical Host in resource group <$rgname> for Remote Mirror"`
298*fcf3ce44SJohn Forte		return 2
299*fcf3ce44SJohn Forte	fi
300*fcf3ce44SJohn Forte
301*fcf3ce44SJohn Forte	if [ $count_HAStoragePlus -lt 1 ]
302*fcf3ce44SJohn Forte	then
303*fcf3ce44SJohn Forte		logger -p ${SYSLOG_FACILITY}.notice \
304*fcf3ce44SJohn Forte		-t "NWS.[$ARGV0]" `gettext "Missing Enabled HAStoragePlus in resource group <$rgname> for Remote Mirror"`
305*fcf3ce44SJohn Forte		return 2
306*fcf3ce44SJohn Forte	elif [ $count_HAStoragePlus -gt 1 ]
307*fcf3ce44SJohn Forte	then
308*fcf3ce44SJohn Forte		logger -p ${SYSLOG_FACILITY}.notice \
309*fcf3ce44SJohn Forte		-t "NWS.[$ARGV0]" `gettext "Too Many Enabled HAStoragePlus in resource group <$rgname> for Remote Mirror"`
310*fcf3ce44SJohn Forte		return 2
311*fcf3ce44SJohn Forte	fi
312*fcf3ce44SJohn Forte
313*fcf3ce44SJohn Forte# Invoke switchfunc to switch the resource group.
314*fcf3ce44SJohn Forte
315*fcf3ce44SJohn Forte	switchfunc $rgname $dg &
316*fcf3ce44SJohn Forte	pid=$!
317*fcf3ce44SJohn Forte	mkdir -p /var/run/scnws/
318*fcf3ce44SJohn Forte	rm -f /var/run/scnws/$dg.pid
319*fcf3ce44SJohn Forte	echo $pid > /var/run/scnws/$dg.pid
320*fcf3ce44SJohn Forte
321*fcf3ce44SJohn Forte	return 0
322*fcf3ce44SJohn Forte}
323*fcf3ce44SJohn Forte
324*fcf3ce44SJohn Forte
325*fcf3ce44SJohn Forte#
326*fcf3ce44SJohn Forte# Functions
327*fcf3ce44SJohn Forte#
328*fcf3ce44SJohn Forte
329*fcf3ce44SJohn Forteusage()
330*fcf3ce44SJohn Forte{
331*fcf3ce44SJohn Forte	logger -p ${SYSLOG_FACILITY}.err \
332*fcf3ce44SJohn Forte	    -t "NWS.[$ARGV0]" "usage: $ARGV0 { start | stop } diskgroup"
333*fcf3ce44SJohn Forte	exit 1
334*fcf3ce44SJohn Forte}
335*fcf3ce44SJohn Forte
336*fcf3ce44SJohn Forte
337*fcf3ce44SJohn Forte# Input: arg1) $NWS_START_DIR - location of NWS scripts
338*fcf3ce44SJohn Forte#	 arg2) start / stop
339*fcf3ce44SJohn Forte#	 arg3 ) device group - $2
340*fcf3ce44SJohn Forte#	 arg4) sndr_ena / sndr_dis
341*fcf3ce44SJohn Forte# Output: Nothing. Log error if seen
342*fcf3ce44SJohn Forte
343*fcf3ce44SJohn Forteprocess_dir()
344*fcf3ce44SJohn Forte{
345*fcf3ce44SJohn Forte	typeset dir=$1
346*fcf3ce44SJohn Forte	typeset arg1=$2
347*fcf3ce44SJohn Forte	typeset dg=$3
348*fcf3ce44SJohn Forte	typeset arg2=$4
349*fcf3ce44SJohn Forte	typeset RDC=$dir/10rdc
350*fcf3ce44SJohn Forte
351*fcf3ce44SJohn Forte	if [[ -d $dir ]]
352*fcf3ce44SJohn Forte	then
353*fcf3ce44SJohn Forte		for f in $dir/*
354*fcf3ce44SJohn Forte		do
355*fcf3ce44SJohn Forte			# process scripts in the directories in lexical order
356*fcf3ce44SJohn Forte			# note - no leading S or K unlike /etc/rc?.d/
357*fcf3ce44SJohn Forte
358*fcf3ce44SJohn Forte			if [ -s $f ] && [ $arg2 != "sndr_dis" ]
359*fcf3ce44SJohn Forte			then
360*fcf3ce44SJohn Forte				# run script and pipe output through
361*fcf3ce44SJohn Forte				# logger into syslog
362*fcf3ce44SJohn Forte
363*fcf3ce44SJohn Forte				/usr/bin/ksh $f $arg1 $dg 2>&1 |
364*fcf3ce44SJohn Forte				    logger -p ${SYSLOG_FACILITY}.notice \
365*fcf3ce44SJohn Forte					-t "NWS.[${ARGV0}:$(basename $f)]"
366*fcf3ce44SJohn Forte			else
367*fcf3ce44SJohn Forte			# SNDR misconfigured - prevent start
368*fcf3ce44SJohn Forte                            if [ -s $f ] && [ $f != $RDC ]
369*fcf3ce44SJohn Forte                            then
370*fcf3ce44SJohn Forte                                # run script and pipe output through
371*fcf3ce44SJohn Forte                                # logger into syslog
372*fcf3ce44SJohn Forte                                /usr/bin/ksh $f $arg1 $dg 2>&1 |
373*fcf3ce44SJohn Forte                                    logger -p ${SYSLOG_FACILITY}.notice \
374*fcf3ce44SJohn Forte                                        -t "NWS.[${ARGV0}:$(basename $f)]"
375*fcf3ce44SJohn Forte			    fi
376*fcf3ce44SJohn Forte			fi
377*fcf3ce44SJohn Forte		done
378*fcf3ce44SJohn Forte	else
379*fcf3ce44SJohn Forte		logger -p ${SYSLOG_FACILITY}.err \
380*fcf3ce44SJohn Forte		    -t "NWS.[$ARGV0]" "no directory: $dir"
381*fcf3ce44SJohn Forte	fi
382*fcf3ce44SJohn Forte}
383*fcf3ce44SJohn Forte
384*fcf3ce44SJohn Forte
385*fcf3ce44SJohn Forte#
386*fcf3ce44SJohn Forte# main
387*fcf3ce44SJohn Forte#
388*fcf3ce44SJohn Forte
389*fcf3ce44SJohn Forteif [ $# -ne 2 ]
390*fcf3ce44SJohn Fortethen
391*fcf3ce44SJohn Forte	usage
392*fcf3ce44SJohn Forte	# not reached
393*fcf3ce44SJohn Fortefi
394*fcf3ce44SJohn Forte
395*fcf3ce44SJohn Forte
396*fcf3ce44SJohn Fortecase "$1" in
397*fcf3ce44SJohn Fortestart)
398*fcf3ce44SJohn Forte	logger -p ${SYSLOG_FACILITY}.notice -t "NWS.[$ARGV0]" "starting: $ARGV0 $*"
399*fcf3ce44SJohn Forte	do_scswitch $2
400*fcf3ce44SJohn Forte	retval=$?
401*fcf3ce44SJohn Forte	if [ $retval == 2 ]
402*fcf3ce44SJohn Forte	then
403*fcf3ce44SJohn Forte		logger -p ${SYSLOG_FACILITY}.err \
404*fcf3ce44SJohn Forte		    -t "NWS.[$ARGV0]" "**FATAL ERROR** Remote Mirror is mis-configured and DISABLED for devicegroup <"$2"> "
405*fcf3ce44SJohn Forte		# Disable SNDR
406*fcf3ce44SJohn Forte		process_dir $NWS_START_DIR start "$2" sndr_dis
407*fcf3ce44SJohn Forte	else
408*fcf3ce44SJohn Forte		process_dir $NWS_START_DIR start "$2" sndr_ena
409*fcf3ce44SJohn Forte	fi
410*fcf3ce44SJohn Forte	;;
411*fcf3ce44SJohn Fortestop)
412*fcf3ce44SJohn Forte	logger -p ${SYSLOG_FACILITY}.notice -t "NWS.[$ARGV0]" "stopping: $ARGV0 $*"
413*fcf3ce44SJohn Forte	process_dir $NWS_STOP_DIR stop "$2" sndr_ena
414*fcf3ce44SJohn Forte	kill_scswitch $2
415*fcf3ce44SJohn Forte	;;
416*fcf3ce44SJohn Forte
417*fcf3ce44SJohn Forte*)
418*fcf3ce44SJohn Forte	usage
419*fcf3ce44SJohn Forte	# not reached
420*fcf3ce44SJohn Forte	;;
421*fcf3ce44SJohn Forteesac
422*fcf3ce44SJohn Forte
423*fcf3ce44SJohn Fortelogger -p ${SYSLOG_FACILITY}.notice -t "NWS.[$ARGV0]" "completed: $ARGV0 $*"
424*fcf3ce44SJohn Forte
425*fcf3ce44SJohn Forteexit 0
426