• 03-11-2017, 22:01:34
    #1
    :Arkadaşlar selamlar
    Linux sunucularınızda belli bir load seviyesine geldiğinde istediğiniz servisleri resetleyerek load düşürmeye yarayan script, farklı servisleri ekleyerek sunucuyu kontrol edemediğiniz vakit load düşürmenize yarayacaktır.
    Tabi servisi resetlerken sayfada bulunan kullanıcılar kısa süreliğine erişim sağlayamaz. Sunucunun kilitlenmesinden iyidir
    #!/bin/sh
    max_cpu="3" # Set to max cpu. This is the max % you will allow no decimals.
    apache_name="httpd" # Set to the name that apache runs as. Usually apache but sometimes it may be httpd.
    log_file=/var/log/xxx # Log File path.
    ################## DONT TOUCH ##################
    time=$(date "+%y:%m %p on %D")
    date=$(date "+%h %d %T")
    cpu_usage_apache=$(ps xua | grep -iw $apache_name | grep -v grep | awk '{print $3}' | sed -e 's/..$//' | awk '!L[$0]++' | sort -nr)
    if [ -z "$cpu_usage_apache" ]; then
    echo "not running"
    exit 1
    fi
    for i in $cpu_usage_apache; do
    if [ "$i" -gt "$max_cpu" ]; then
    ps xua | grep -iw $apache_name | grep -v grep | awk '{print $2}' | xargs kill
    echo "$date httpd reset: Httpd server shutdown at $time by script." >> $log_file
    exit 0
    else
    echo >/dev/null
    fi
    done
    exit 0
  • 03-11-2017, 22:20:42
    #2
    Harikasın kardeşim