shell脚本tomca部署环境脚本

29次阅读

共计 2075 个字符,预计需要花费 6 分钟才能阅读完成。

 查看进程 jc
#!/bin/sh
export CATALINA_BASE=$(cd `dirname $0`; pwd)
. $CATALINA_BASE/setenv.sh $*
echo "进程信息:"
ps -ef|grep "^$ROOT_USER"|grep $JAVA_HOME|grep $CATALINA_HOME|grep "$CATALINA_BASE"|grep -v 'grep'
 
查看日志 rz
#!/bin/sh
CATALINA_BASE=$(cd `dirname $0`; pwd)
tail -n 100 -f $CATALINA_BASE/logs/catalina.out
设置环境变量 setenv.sh
#!/bin/sh
ROOT_USER=root
 
export JAVA_HOME=/usr/java/jdk1.7.0_80
export CATALINA_HOME=/usr/tomcat/apache-tomcat-8.0.50
export JAVA_OPTS="-server -XX:PermSize=128m -XX:MaxPermSize=256m -Xms512m -Xmx512m -Djava.awt.headless=true"
 
 
 
关闭 tomcat 实例:shutdown.sh
#!/bin/sh
export CATALINA_BASE=$(cd `dirname $0`; pwd)
. $CATALINA_BASE/setenv.sh $*
 
WHO=`whoami`
 
GetPid(){PS_ID=$(ps -ef|grep "^$WHO"|grep $JAVA_HOME|grep $CATALINA_HOME|grep "$CATALINA_BASE"|grep -v 'grep'|awk '{print $2}')
}
 
ShowPid(){
    echo "进程信息:"
    ps -ef|grep "^$WHO"|grep $JAVA_HOME|grep $CATALINA_HOME|grep "$CATALINA_BASE"|grep -v 'grep'
}
 
CountPid(){COUNT=$(ps -ef|grep "^$WHO"|grep $JAVA_HOME|grep $CATALINA_HOME|grep "$CATALINA_BASE"|grep -v 'grep'|wc -l)
}
 
StopTomcat(){STOP_RESULT=`$CATALINA_HOME/bin/catalina.sh stop >/dev/null 2>&1|grep "Connection Refused"|grep -v grep|wc -l`}
 
    CountPid
 
    if [[$COUNT == "0"]];then
        echo "服务没有启动."
    else
 
        ShowPid
        StopTomcat
 
        for((i=1;i<=30;i++));do
            for((j=1;j<=5;j++));do
                sleep 0.5
                printf "."
            done
            CountPid
            if [[$COUNT -gt 0]];then
                StopTomcat
            elif [[$COUNT -eq 0]];then
               break;
            fi
        done
        for((i=1;i<=120;i++));do
            if [[$COUNT -gt 0]];then
                sleep 0.5 
                printf ".."
                CountPid 
            fi
        done
        #如果超时,直接杀死
        if [[$COUNT -gt 0]];then
            GetPid
            kill -9 $PS_ID
        fi
        if [[$? == 0]];then
            echo "TOMCAT 服务已停止 @$CATALINA_BASE"
        fi
    fi
 
启动 tomcat 实例:startup.sh
#!/bin/sh
export CATALINA_BASE=$(cd `dirname $0`; pwd)
. $CATALINA_BASE/setenv.sh $*
 
WHO=`whoami`
COUNT=$(ps -ef|grep "^$WHO"|grep $JAVA_HOME|grep $CATALINA_HOME|grep "$CATALINA_BASE"|grep -v 'grep'|wc -l)
 
    echo "*******************************************************"
    echo "当前配置目录:$CATALINA_BASE"
    echo "*******************************************************"
    if [[$COUNT -ge 1]];then
        echo "服务正在运行,请先 shutdown."
    else
        $CATALINA_HOME/bin/catalina.sh start|awk '{printf"..."}END{print" 启动完毕 "}'
        if [[$? == 0]];then
            echo "TOMCAT 启动成功 @$CATALINA_BASE"
        fi
    fi
    echo "进程信息:"
    ps -ef|grep "^$WHO"|grep $JAVA_HOME|grep $CATALINA_HOME|grep "$CATALINA_BASE"|grep -v 'grep'

正文完
 0