zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    线程唤醒
    以前、现在
    黑马程序员训练营基础测试
    流程图
    线程同步
    Thread联系
    Java线程
    Java中文件流笔记
    字符串习题
    匿名内部类
  • 原文地址:https://www.cnblogs.com/lsgxeva/p/9523957.html
Copyright © 2011-2022 走看看