#!/bin/ksh -p
#
# ident "@(#)utpkg-utwar-ctl.ksh	1.2 09/09/17 SMI"
#
# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

set -u

function disable {

   
# Trigger stop command just in case the web server is still running
    typeset PROCESS_PIDFILE=/var/opt/SUNWut/tmp/utwebadmin.pid
    if [ -f "$PROCESS_PIDFILE" ]; then
	typeset PID=`cat $PROCESS_PIDFILE`
	if [ -n "`/bin/ps -deaf | awk '{print $2}' | grep $PID`" ]; then
	    kill -9 $PID >/dev/null 2>&1
	fi
	rm -f $PROCESS_PIDFILE
    fi
    
# Remove temporary files from etc, log and work directory
    typeset LOG_FILES=/var/opt/SUNWut/log/utwebadmin.log*
    typeset SERVER_FILE=/etc/opt/SUNWut/webadmin/server.xml
    typeset WEB_FILE=/etc/opt/SUNWut/webadmin/web.xml
    typeset KEYSTORE_FILE=/etc/opt/SUNWut/webadmin/keystore
    typeset WORK_DIR=/var/opt/SUNWut/webadmin
    
    rm -f $LOG_FILES
    if [ -f "$SERVER_FILE" ]; then
	rm -f $SERVER_FILE
    fi
    if [ -f "$WEB_FILE" ]; then
	rm -f $WEB_FILE
    fi
    if [ -f "$KEYSTORE_FILE" ]; then
	rm -f $KEYSTORE_FILE
    fi
    
    if [ -d "$WORK_DIR" ]; then
	rm -rf $WORK_DIR
    fi
    
    typeset OS=`uname -s`
#
# For Linux only.  We need to remove the links to init.d files using
# chkconfig.  
    if [ $OS = "Linux" ]; then
	typeset INITFILE="utwadmin"
	chkconfig --del $INITFILE > /dev/null
	
    #
    # On SuSE/JDS, chkconfig (based on insserv) does not remove Kill links in
    # lower runlevels.  They must be removed manually.
    #
	if [ -f /etc/SuSE-release ]; then
	# we are installing on either SuSE or JDS
	    typeset ETCINIT=/etc/rc.d
	    rm -f $ETCINIT/rc4.d/K??$INITFILE
	    rm -f $ETCINIT/rc3.d/K??$INITFILE
	    rm -f $ETCINIT/rc2.d/K??$INITFILE
	    rm -f $ETCINIT/rc1.d/K??$INITFILE
	fi
    fi
    
    return 0
    

}

function enable {

    return 0

}


########################################################################
# Local Variables
# They must defined here to resolve some of the parameter resolution
# problem
########################################################################
local_variables() {
    return
}


########################################################################
#
# Configurable parameter
#
########################################################################
# NONE


########################################################################
#
# Variables used in the shared script utctl-shlib
#
########################################################################
DESCR="Kills any running web server. Cleans up generated files. For Linux only: removes rc scipts "


########################################################################
#
# Execution starts here
#
PROGPATH=`dirname $0`
. $PROGPATH/utctl-shlib
