您的位置:首页 > 运维架构 > Tomcat

基于Saltstatck实现页面实时显示tomcat启动日志(17)

2017-07-31 19:33 771 查看

一、相关文件

master端:

/srv/salt/tomcat/start.sls #tomcat启动服务state.sls,须要自己创建

/srv/salt/tomcat/log.sls #页面实时显示tomcat启动日志state.sls,须要自己创建

/srv/salt/scripts/checklog.sh #/srv/salt/tomcat/log.sls中用到脚本,须要自己创建

minion端:

/ylhb/log/html #记录tomcat实时启动日志,自己主动生成,无需创建

/ylhb/log/tomcat-nohup/nohup.out #tomcat日志文件

/ylhb/log/num.txt #当前tomcat日志文件行数,自己主动生成,无需创建

二、/srv/salt/tomcat/start.sls文件内容

tomcat_start:
cmd.run:
- name: echo " " > /ylhb/log/html ;wc -l /ylhb/log/tomcat-nohup/nohup.out | awk '{ print $1 }'  > /ylhb/log/num.txt;sh /ylhb/product/tomcat/bin/startup.sh
- env:
- LC_ALL: ""
- user: ylhb

三、/srv/salt/tomcat/log.sls文件内容

tomcat_checklog:
cmd.script:
- name: salt://scripts/checklog.sh
- env:
- LC_ALL: ""
- user: ylhb

四、/srv/salt/scripts/checklog.sh文件内容

#!/bin/sh
#
num1=`wc -l /ylhb/log/tomcat-nohup/nohup.out | awk '{ print $1 }'`
num2=`cat /ylhb/log/num.txt`
if [ "$num1" -gt "$num2" ]; then
grep "Server startup in" /ylhb/log/html
if [ "$?

" != "0" ];then
echo $num1 > /ylhb/log/num.txt
sed -n `expr $num2 + 1`,`wc -l /ylhb/log/tomcat-nohup/nohup.out | awk '{ print $1 }'`p /ylhb/log/tomcat-nohup/nohup.out >> /ylhb/log/html
else
grep "TotalERROR:"  /ylhb/log/html
if [ "$?" != "0" ];then
numerror=`grep -w "Error" /ylhb/log/html | wc -l`
echo -e "\n\nTotalERROR: $numerror" >> /ylhb/log/html
fi
fi
fi
cat /ylhb/log/html


五、功能实现

1.在WEB页面操作启动tomcat服务,调用salt-api接口操作start.sls,同一时候打开新的页面

2.新打开的页面调用salt-api接口操作log.sls,且自己主动刷新页面

如上就可以达到页面实时显示tomcat启动日志功能
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: