shell尝试-tomcat

本文介绍了一款用于自动化管理Tomcat服务器的Shell脚本,包括启动、停止、检查进程等核心功能,并通过输出0或1来反馈操作状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#!/usr/bin/ksh 
################################################################################ 
#The script is called by java. 
#The script just can output 0 or 1, please don't echo other information out. 
#If you do so, the script will be failed in testing the result of it. 
################################################################################ 
check_tomcat_proc_exist() 
{ 
sso_user=`whoami` 
sso_pro=`ps -fu ${sso_user} | grep ${process_name} |grep -v 'grep' | awk '{print $2}'` 
if [ "X${sso_pro}" = "X" ];then 
echo 1 
return 1 
else 
echo 0 
fi 
return 0 
} 

stop_tomcat() 
{ 
check_tomcat_proc_exist 1>/dev/null 2>&1 
if [ $? -ne 0 ];then 
                echo 1 
                return 0 
        fi 
cd ${tomcat_home}/bin 
shutdown.sh 1>/dev/null 2>&1 
if [ $? -ne 0 ]; then 
echo 1 
fi 
echo 0 
return 0 
} 

kill_tomcat() 
{ 
sso_user=`whoami` 
sso_pro=`ps -fu ${sso_user} | grep ${process_name} |grep -v 'grep' | awk '{print $2}'` 
if [ "X${sso_pro}" = "X" ];then 
echo 1 
else 
kill -9 $sso_pro 
echo 0 
fi 
return 0 
} 

start_tomcat() 
{ 
check_tomcat_proc_exist 1>/dev/null 2>&1 
if [ $? -eq 0 ];then 
echo 1 
return 0 
fi 
if [ -f ${tomcat_home}/logs/catalina.out ];then 
mv -f ${tomcat_home}/logs/catalina.out ${tomcat_home}/logs/catalina.out.old 
fi 
if [ -f ${tomcat_home}/bin/logs/ssoserver.log ];then 
mv -f ${tomcat_home}/bin/logs/ssoserver.log ${tomcat_home}/bin/logs/ssoserver.log.old 
fi 
cd ${tomcat_home}/bin 
nohup startup.sh >/dev/null 2>&1 & 
if [ $? -ne 0 ]; then 
echo 1 
return 1 
fi 
typeset idx=0 
typeset expire_times=180 
while [ ${idx} -lt ${expire_times} ] 
do 
grep -i "Server startup" "${tomcat_home}/logs/catalina.out" 1>/dev/null 2>&1 
if [ $? -eq 0 ];then 
grep -i "ERROR" "${tomcat_home}/bin/logs/ssoserver.log" 1>/dev/null 2>&1 
if [ $? -ne 0 ];then 
echo 0 
else 
kill_tomcat >/dev/null 2>&1 & 
fi 
return 0 
fi 
((idx=idx+1)) 
sleep 1 
done 
} 

typeset process_name="org.apache.catalina" 
typeset tomcat_home=$HOME/tomcat 
if  [ "X$1" = "Xproc" ]; then 
check_tomcat_proc_exist 
elif  [ "X$1" = "Xstart" ]; then 
start_tomcat 
elif  [ "X$1" = "Xstop" ]; then 
stop_tomcat 
elif  [ "X$1" = "Xkill" ]; then 
kill_tomcat 
else 
echo "please input parameter." 
fi

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值