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日志文件行数,自动生成,无需创建
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
tomcat_checklog: cmd.script: - name: salt://scripts/checklog.sh - env: - LC_ALL: "" - user: ylhb
#!/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启动日志功能