tomcat启动脚本

Posted 一条寻找快乐的咸鱼

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了tomcat启动脚本相关的知识,希望对你有一定的参考价值。

#!/bin/bash
#tomcat start.sh
NAME=tomcat
export JAVA_HOME=/usr/local/java/jdk1.8.0_181
Tomcat_Path=/data/tomcat/
Pid_List=`ps -ef |grep tomcat|grep -v "grep"| awk ‘{print $2}‘ |sed -n 1p`
Tomcat_Home=/data/tomcat
Tomcat_doc=/data/www/kstore
war=/htdocs/war/
module="boss mobile third"
Start_Scripts=/data/tomcat/bin/startup.sh
Shutdown_Scripts=/data/tomcat/bin/shutdown.sh
Log_Backup=/data/tomcat_log_backup
Remote_Host=192.168.1.110
if [ -d $Log_Backup ];then
    echo ""
else
    mkdir -p $Log_Backup
fi

#if [ -s /bin/ss ]; then
#    StatBin=/bin/ss
#else
#    StatBin=/bin/netstat
#fi

case $1 in
    start)
	echo "start run tomcat"
	if /bin/ps -ef | grep -q|grep -v grep tomcat;then
            echo "$NAME (pid:"$Pid_List") already running."
	    exit 1
        fi	
	$Start_Scripts
	if [ "$?" != 0 ] ; then
            echo "run faild"
            exit 1
        else
            echo -e "33[32m tomcat run done 33[0m"
        fi
        ;;
    stop)
	echo "stop tomcat service"
	if ! /bin/ps -ef  | grep -v grep | grep -q tomcat;then
            echo "$NAME is not running"
            exit 1
        fi
	$Shutdown_Scripts
#        Pid_List=`ps -ef |grep tomcat|grep -v "grep"| awk ‘{print $2}‘`
	kill -9 $Pid_List
	if [ "$?" != 0 ] ; then
            echo " $NAME stopping failed"
            exit 1
        else
            echo -e "33[32m tomcat service closed  33[0m"
#############清空缓存##################################################	    
	    sync
            echo 3 > /proc/sys/vm/drop_caches
#############清空日志###################################################
	    mv $Tomcat_Path/logs/* $Log_Backup
############输出本地日志到天津服务器####################################
	    cd $Log_Backup
	    tar -zcvf "`date +%F-%H%M%S`_tomcat_log.tar.gz" $Log_Backup/*
	    rsync -az "`date +%F-%H%M%S`_tomcat_log.tar.gz" [email protected]$Remote_Host:/tmp
		
        fi
        ;;
	
    *)
	echo "please input {start|stop|}"
	exit 1
	;;
esac

  

以上是关于tomcat启动脚本的主要内容,如果未能解决你的问题,请参考以下文章

tomcat启动脚本

sh Unbounce脚本片段,用于在零停机时间内重新启动HAProxy

linux下安装tomcat,并设置自动启动

tomcat启动脚本

shell脚本同时启动关闭多个tomcat

tomcat多实例启动和关闭脚本