#!/usr/bin/ksh
#
# Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

typeset opt

while getopts 'R:G:Q:P:B:U:' opt
do
	case "$opt" in
		R)      RESOURCE=$OPTARG;;
                G)	RESOURCEGROUP=$OPTARG;;
		Q)      QMGR=$OPTARG;;
		P)	PORT=$OPTARG;;
		B)	BACKLOG=$OPTARG;;
		U)	USERID=$OPTARG;;
                *)	logger -p daemon.err \
                        "ERROR: `basename $0` Option $OPTARG unknown"
                        exit 1;;
	esac
done
    
. `dirname $0`/../etc/config
. `dirname $0`/functions

validate_options

debug_message "Method: `basename $0` - Begin"
$SET_DEBUG

rm $LOGFILE

validate

if [ "$rc_validate" -ne 0 ]
then
        debug_message "Method: `basename $0` - End (Exit 1)"
        exit 1
fi

check_qmgr

# To accomodate multiple port entries and therefore multiple process trees
# we need to ensure that whenever the START method is called all the process
# ids associated with this resource are stopped, so that we can ensure they 
# are (re) started under the pmftag $RESOURCEGROUP,$RESOURCE,0

if pgrep -fl -u mqm runmqlsr | grep -w ${QMGR} > /dev/null
then
	stop_lsr
fi

for port in $PORT_LIST
do
	start_lsr $port

       	# runmqlsr will only ouput error messages, which is
       	# why log_message outputs with priority error.
       	# Function log_message only sends a message to syslog if
       	# $LOGFILE is not empty.

       	log_message error runmqlsr
done

debug_message "Method: `basename $0` - End (Exit 0)"
exit 0
