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


    一、相关文件

    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 " TotalERROR: $numerror" >> /ylhb/log/html fi fi fi cat /ylhb/log/html


    五、功能实现

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

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


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







  • 相关阅读:
    https证书设置以及设置301跳转
    SVN服务器从windows迁移至Linux
    禅道从windows迁移到linux
    gitlab安装和迁移
    java 枚举类型enum 的使用
    java中的日期注意事项
    C# using 三种使用方式 zhuan
    设计路径测试覆盖率与代码测试覆盖率
    Selenium API (C#) 转
    Selenium 2.0 WebDriver with Visual Studio, C#, & IE
  • 原文地址:https://www.cnblogs.com/brucemengbm/p/7265107.html
Copyright © 2020-2023  润新知