zoukankan      html  css  js  c++  java
  • 基于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启动日志功能







  • 相关阅读:
    Codeforces 787D. Legacy 线段树优化建图+最短路
    Codeforces 1051E. Vasya and Big Integers
    BZOJ3261 最大异或和
    BZOJ3531 SDOI2014 旅行
    洛谷P2468 SDOI 2010 粟粟的书架
    2018 ICPC 焦作网络赛 E.Jiu Yuan Wants to Eat
    HDU6280 From Tree to Graph
    HDU5985 Lucky Coins 概率dp
    (HDU)1334 -- Perfect Cubes (完美立方)
    (HDU)1330 -- Deck (覆盖物)
  • 原文地址:https://www.cnblogs.com/brucemengbm/p/7265107.html
Copyright © 2011-2022 走看看