tomcatctl.sh 1.29 KB
#!/bin/bash
################################################################
#@Authro Lijian
#@Date 2015-10-22
################################################################

BASE_BIN_DIR=`dirname $0`
. $BASE_BIN_DIR/env.sh

export CATALINA_HOME=$SERVER_HOME
export CATALINA_BASE=$WEB_APP_HOME/.tomcat
CATALINA_BASE=$WEB_APP_HOME/.tomcat


################################################################
##check if started before
check_server(){
    java_pid=`ps  --no-heading -C java -f --width 1000 | grep "$$CATALINA_BASE" |awk '{print $2}'`
    if [ ! -z "$java_pid" ]; then
        echo "Tomcat server already started: pid=$java_pid"
        exit;
    fi
}

copy_server_home(){
    if [ -d "$CATALINA_BASE" ]; then
        rm -rf $CATALINA_BASE
    fi
    mkdir -p $CATALINA_BASE/conf
    mkdir -p $CATALINA_BASE/webapps
	mkdir -p $CATALINA_BASE/logs
	touch $CATALINA_BASE/logs/catalina.out
}

copy_tomcat_conf(){
    cp -rf $SERVER_HOME/conf/. $CATALINA_BASE/conf/.
    cp -rf $WEB_APP_HOME/conf/tomcat/server.xml $CATALINA_BASE/conf/server.xml
}

copy_war(){
    cp -rf $WEB_APP_HOME/*.war $CATALINA_BASE/webapps/
}

deploy(){
    check_server
    copy_server_home
    copy_tomcat_conf
    copy_war
    
}
    
###############################################################
deploy
$SERVER_HOME/bin/catalina.sh start