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

来源:互联网 发布:java与js字符串转码 编辑:程序博客网 时间:2024/06/03 22:57

一、相关文件

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        fificat /ylhb/log/html


五、功能实现

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

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


如上即可达到页面实时显示tomcat启动日志功能







0 0
原创粉丝点击