返回首页DA系统C#IDE文件同步服务屏保 今天是: 2026-05-05    "立夏"  夏季的第一个节气,表示盛夏时节的正式开始

搜索
热搜: linux 技术
Hi~登录注册
查看: 1629|回复: 0

[原创] 【原创】自制Tomcat快速重启、停止进程脚本

[复制链接]
发表于 2021-2-8 14:25:55 | 显示全部楼层 |阅读模式

少侠不来段修仙之旅吗~

您需要 登录 才可以下载或查看,没有帐号?注册成为修仙之旅的少年~

x
因Tomcat自带的停止进程太不稳定了,有时还会无法停止,但是因为没有确认导致开启了两个tomcat,特此配合alias别名创建此脚本

创建脚本statusTomcat.sh

#! /bin/bash
#默认位置参数不输入则默认查看进程
if [ -z $1 ];then
        ps -ef | grep tomcat | grep -v grep
        pd2=`ps -ef | grep tomcat | grep -v grep`
        if [ -z $pd2 ];then
                echo "tomcat is no start!"
        fi
        exit
fi

#关闭tomcat进程
if [ $1 == "1" ];then
        ps -ef | grep tomcat| grep -v grep
        kill -9 `ps -ef | grep tomcat | grep -v 'grep' | awk '{print $2}' `
        pd1=`ps -ef | grep tomcat | grep -v 'grep' | awk '{print $2}' `
        echo $pd1
        if [ -z $pd1 ];then
                echo "tomcat is kill"
        fi

        ps -ef | grep tomcat| grep -v grep
fi

#重启tomcat进程
if [ $1 == "2" ];then
        ps -ef | grep tomcat| grep -v grep
        kill -9 `ps -ef | grep tomcat | grep -v 'grep' | awk '{print $2}' `
        pd1=`ps -ef | grep tomcat | grep -v 'grep' | awk '{print $2}' `
        echo $pd1
        if [ -z $pd1 ];then
                echo "tomcat is kill"
        fi

        sh ~/apache-tomcat-8.5.60/bin/startup.sh

        pd1=`ps -ef | grep tomcat | grep -v 'grep' | awk '{print $2}' `
        echo $pd1
        if [ -n $pd1 ];then
                echo "tomcat is start"
        fi

        ps -ef | grep tomcat| grep -v grep
fi


=====脚本END

配合alias语句使用

vim ~/.bashrc

alias pstomcat="sh ~/statusTomcat.sh"
alias showdowntomcat="sh ~/statusTomcat.sh 1"
alias restarttomcat="sh ~/statusTomcat.sh 2"


游客
回复
*滑块验证:

DA论坛飞机票来了~
快速回复 返回顶部 返回列表