#!/usr/bin/ksh93
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/usr/sbin/cluster/sa/ihs/sbin/cl_configihs.sh 1.1 
#  
# Licensed Materials - Property of IBM 
#  
# Restricted Materials of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2009,2010 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)54	1.1  src/43haes/usr/sbin/cluster/sa/ihs/sbin/cl_configihs.sh, hacmp, 61haes_r714 11/28/11 15:24:10
###################################################################
##
## NAME:	cl_configihs
##
## DESCRIPTION:	
##    Modify the LISTEN directive in the httpd.conf file.  This
##    utility will varyon the volume group and mount the file
##    system if necessary to gain access to the httpd.conf file.
##    It will also stop the HTTP server by calling "apachectl stop"
##    and will leave it in a stopped state.
##
##    This utility is meant to be called remotely from 
##    cl_ihsimport and execute on the node where the IBM Http 
##    Server was originally installed.
##
## ARGUMENTS:	
##    Volume Group
##    Install Path
##    New Listen Directive
##
## OUTPUT:	
##    None
##
## EXIT CODES:	
##    0 - success
##    1 - failure
##
## KLIB Functions:
##    KLIB_IHS_log_message
##    KLIB_IHS_ch_httpd_directive
##
###################################################################


##########
# MAIN
##########

# Read in the db2 definitions
#. /usr/es/sbin/cluster/sa/db2/etc/db2_definitions

# Read in the message catalog entries
#. /usr/es/sbin/cluster/sa/db2/cat/cl_db2discovery

# Load the common klib functions, abort, logmsg, dbgmsg, etc.
. /usr/es/lib/ksh93/common_functions.ksh93

# Set the FPATH for all DB2 / HACMP functions
FLIB=/usr/es/lib/ksh93
FPATH=$FLIB/utils:$FLIB/hacmp:$FLIB/ihs:$FLIB/util:$FLIB/util/list:$FLIB/aix/:$FLIB/aix/odm/:$FLIB/db2/vg

umask -S u=rw,g=,o=
PATH=$PATH:/usr/es/sbin/cluster/utilities:/usr/es/sbin/cluster/sa/ihs/sbin/

[[ "$VERBOSE_LOGGING" == "high" ]] && set -x

IHSSA_HOME="/usr/es/sbin/cluster/sa/ihs"
IHSSA_SBIN_DIR="$IHSSA_HOME/sbin"

KLIB_DEFAULT_LOGFILE=/var/hacmp/log/ihssa.log
KLIB_HACMPLOG_ENTRY=ihssa.log
KLIB_OUTPUT_CONSOLE=false

typeset vg=$1
typeset install_path=$2
typeset new_value=$3

typeset HTTPD_CONF="${install_path}/conf/httpd.conf"

KLIB_IHS_log_message "IHS INFO: Modifying LISTEN directive in $HTTPD_CONF"


# Make sure the VG is varied on and the file system is mounted
KLIB_IHS_mount_fs_for_directory $vg $install_path
if (( $? != 0 )) ; then
    KLIB_IHS_log_message "WAS ERROR: Could not mount the file system for the directory ${install_path}"
    exit 1
fi

#Make sure the IBM Http Server is stopped.
typeset stop_script="${install_path}/bin/apachectl stop"
KLIB_IHS_log_message "IHS INFO: Stopping IBM Http Server ($stop_script)."
$stop_script > /dev/null
if (( $? != 0 )) ; then
    KLIB_IHS_log_message "WAS ERROR: Failed stopping IBM Http Server."
    exit 1
fi

KLIB_IHS_log_message "IHS INFO: Setting LISTEN directive."
KLIB_IHS_ch_httpd_directive $HTTPD_CONF "Listen" $new_value

typeset ch_count=$?

KLIB_IHS_log_message "IHS INFO: Changed $ch_count LISTEN directives in $HTTPD_CONF"

exit 0