• monitor_guiagent


    monitor_guiagent

     monitor_guiagent.sh

    #!/usr/bin/env bash
    #filename : monitor_guiagent.sh
    #Usage: /usr/bin/nohup /var/hgans/gui/ans_php_env/monitor_guiagent.sh >/dev/null 2>/dev/null &
    
    #
    # Append the following command to the rc.local for running monitor_guiagent.sh :
    # /bin/ps -waux | /usr/bin/grep "monitor_guiagent" | /usr/bin/grep -v grep | /usr/bin/awk '{print $2}' | /usr/bin/xargs /bin/kill -9
    # /bin/ps -waux | /usr/bin/grep "/var/hgans/gui/agent" | /usr/bin/grep -v grep | /usr/bin/awk '{print $2}' | /usr/bin/xargs /bin/kill -9
    # /usr/bin/nohup /var/hgans/gui/ans_php_env/monitor_guiagent.sh >/dev/null 2>/dev/null &
    #
    
    PS="/bin/ps"
    KILL="/bin/kill"
    GREP="/usr/bin/grep"
    AWK="/usr/bin/awk"
    WC="/usr/bin/wc"
    TAIL="/usr/bin/tail"
    HEAD="/usr/bin/head"
    XARGS="/usr/bin/xargs"
    ANSCLI="/hgans/anscli"
    DATE_EXEC="/bin/date"
    
    ANSLOG_FILE="/var/anslog/ans.log"
    USER_NAME="%%:ansroot:."
    SHOW_SYS_SESSION="show system session -summary"
    KILL_ALL_SYS_SESSION="kill system session -all"
    KILL_SID_SYS_SESSION="kill system session "
    CLEAR_SYS_SESSION_FLAG_FILE="/flash/anscfg/.clear_sys_session"
    MAX_SYS_SESSION=12
    
    GUI_HOME="/var/hgans/gui"
    HTTPD_DIR="ans_php_env"
    RC_CONF_NAME="rc.conf"
    RC_LOCAL_NAME="rc.local"
    AGENT_DIR="agent"
    ANSRAPI_EXEC_NAME="ansrapi_agent"
    HGCLOUD_EXEC_NAME="hgcloud_proxy"
    MANS_EXEC_NAME="mans_log"
    NOTIFYLOG_EXEC_NAME="NotifyLog"
    KILL_SIGNAL_NUMBER=9
    SLEEP_SECOND_NUMBER=3
    
    while true
    do
        arr_exec=($ANSRAPI_EXEC_NAME $HGCLOUD_EXEC_NAME $MANS_EXEC_NAME $NOTIFYLOG_EXEC_NAME)
        arr_column=${#arr_exec[@]}
        for (( i=0; i < ${arr_column}; i++ ))
        do
            exec_num=`$PS -waux | $GREP ${arr_exec[$i]} | $GREP -v grep | $WC -l`
            if [ $exec_num -eq 0 ]; then
                echo monitor_guiagent: `$DATE_EXEC +"%Y-%m-%d %H:%M:%S"`": Restart webgui agent process ${arr_exec[$i]} ..." >> $ANSLOG_FILE
                $PS -waux | $GREP ${arr_exec[$i]} | $GREP -v grep | $AWK '{print $2}' | $XARGS $KILL $KILL_SIGNAL_NUMBER
                ${GUI_HOME}/${AGENT_DIR}/${arr_exec[$i]} >/dev/null 2>/dev/null &
            fi
        done
        
        current_system_session_line=`$ANSCLI -U $USER_NAME -s "$SHOW_SYS_SESSION" | $WC -l`
        current_system_session_num=$((current_system_session_line-3))
        if [ -f $CLEAR_SYS_SESSION_FLAG_FILE -a $current_system_session_num -gt $MAX_SYS_SESSION ]; then
            arr_sid=(`$ANSCLI -U $USER_NAME -s "$SHOW_SYS_SESSION" | $TAIL -n $current_system_session_num | $AWK '{print $2}'`)
            arr_column=${#arr_sid[@]}
            for (( i=0; i < ${arr_column}; i++ ))
            do
                if [ $i -gt 3 ]; then
                    echo monitor_guiagent: `$DATE_EXEC +"%Y-%m-%d %H:%M:%S"`": Kill system session ${arr_sid[$i]} ..." >> $ANSLOG_FILE
                    $ANSCLI -U $USER_NAME -s "$KILL_SID_SYS_SESSION ${arr_sid[$i]}"
                else
                    echo monitor_guiagent: `$DATE_EXEC +"%Y-%m-%d %H:%M:%S"`": Keep system session ${arr_sid[$i]} ..." >> $ANSLOG_FILE
                fi
            done
        fi
        
        sleep $SLEEP_SECOND_NUMBER
    done

    rc.local

    # This script auto start ansrapi_agent for NewGUI
    /bin/ps -waux | /usr/bin/grep "monitor_guiagent" | /usr/bin/grep -v grep | /usr/bin/awk '{print $2}' | /usr/bin/xargs /bin/kill -9
    /bin/ps -waux | /usr/bin/grep "/var/hgans/gui/agent" | /usr/bin/grep -v grep | /usr/bin/awk '{print $2}' | /usr/bin/xargs /bin/kill -9
    /usr/bin/nohup /var/hgans/gui/ans_php_env/monitor_guiagent.sh >/dev/null 2>/dev/null &

    root@HGANS# cd /var/hgans/gui/ans_php_env
    
    root@HGANS# chmod +x monitor_guiagent.sh
    
    root@HGANS# ps -waux | grep agent | grep -v grep
    
    root@HGANS# ps -waux | grep agent | grep -v grep | awk '{print $2}'| xargs kill -9
    
    root@HGANS# ps -waux | grep agent | grep -v grep
    
    root@HGANS# /usr/bin/nohup /var/hgans/gui/ans_php_env/monitor_guiagent.sh >/dev/null 2>/dev/null &
    
    root@HGANS# ps -waux | grep agent | grep -v grep

    root@HGANS# ps -waux | grep agent | grep -v grep
    
    root@HGANS# ps -waux | grep ansrapi_agent | grep -v grep | awk '{print $2}'| xargs kill -9
    
    root@HGANS# ps -waux | grep agent | grep -v grep

    ========================== End

  • 相关阅读:
    书单
    [转载] 修改WIN10的DNS、以及操作系统和 Web 浏览器清除和刷新 DNS 缓存方法汇总
    【题解】 【集训队作业2018】喂鸽子 minmax容斥+期望dp+补集转化 UOJ449
    【题解】 CF809E Surprise me! 虚树+莫比乌斯反演+狄利克雷卷积
    【题解】 CF1478E Nezzar and Binary String 线段树+时间逆序
    如何处理调用EasyCVR地址集成通过EasyPlayer播放器不能播放的问题?
    智慧能源:智能安防监控技术EasyCVR在石油能源行业中的场景应用
    网络穿透/动态组网工具EasyNTS报错connect refused该如何处理?
    如何处理C++编译webrtc无法成功获取sdp的问题?
    硬核讲解:编译webrtc协议为什么需要turn服务器?
  • 原文地址:https://www.cnblogs.com/lsgxeva/p/9523957.html
Copyright © 2020-2023  润新知