суббота, 2 июля 2011 г.

Увеличиваем отзывчивость системы при сильной нагрузки.

Метод работает на ядре 2.6.32.

1.)Выполняем скрипт через sudo:
#!/bin/bash

YELLOW="\033[1;33m"
RED="\033[0;31m"
ENDCOLOR="\033[0m"

#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
function PARCHEAR ()
{

FICHERO="$HOME/.bashrc"

echo ""
echo -e $YELLOW"Patching [${FICHERO}]..."$ENDCOLOR
echo ""


LINEAS=`cat $FICHERO | grep "/dev/cgroup/cpu/user" | wc -l`
if [ "$LINEAS" == "0" ];
then
    echo "Adding the patch..."
    echo "if [ \"\$PS1\" ] ; then" | tee -a $FICHERO
    echo "mkdir -p -m 0700 /dev/cgroup/cpu/user/\$\$ > /dev/null 2>&1" | tee -a $FICHERO
    echo "echo \$\$ > /dev/cgroup/cpu/user/\$\$/tasks" | tee -a $FICHERO
    echo "echo \"1\" > /dev/cgroup/cpu/user/\$\$/notify_on_release" | tee -a $FICHERO
    echo "fi" | tee -a $FICHERO
else
    echo "It seems the patch is already included in $FICHERO"
fi

FICHERO="/etc/rc.local"
echo ""
echo -e $YELLOW"Patching [${FICHERO}]..."$ENDCOLOR
echo ""

LINEAS=`cat $FICHERO | grep "/dev/cgroup/cpu/release_agent" | wc -l`
if [ "$LINEAS" == "0" ];
then

    echo "Adding the patch..."
    POSI=`cat $FICHERO | grep -n "exit 0" | sort -nr | head -n 1 | awk -F: '{print $1}'`
    #echo "Posi es [$POSI]"
    echo "Making backup of $FICHERO in /etc/rc.local.backup.txt"
    cp /etc/rc.local /etc/rc.local.backup.txt
    sed "${POSI}imkdir -p /dev/cgroup/cpu\nmount -t cgroup cgroup /dev/cgroup/cpu -o cpu\nmkdir -m 0777 /dev/cgroup/cpu/user\necho \"/usr/local/sbin/cgroup_clean\" > /dev/cgroup/cpu/release_agent" /etc/rc.local | tee /etc/rc.new.local
    mv /etc/rc.new.local /etc/rc.local

    #echo "#========== 200 lines kernel patch alternative ============" | tee -a $FICHERO
    #echo "mkdir -p /dev/cgroup/cpu" | tee -a $FICHERO
    #echo "mount -t cgroup cgroup /dev/cgroup/cpu -o cpu" | tee -a $FICHERO
    #echo "mkdir -m 0777 /dev/cgroup/cpu/user" | tee -a $FICHERO
    #echo "echo \"/usr/local/sbin/cgroup_clean\" > /dev/cgroup/cpu/release_agent" | tee -a $FICHERO
    #echo "#====================================" | tee -a $FICHERO
else
    echo "It seems the patch is already included in $FICHERO"
fi

echo ""
echo -e $YELLOW"Making [${FICHERO}] executable"$ENDCOLOR
echo ""
sudo chmod +x $FICHERO

FICHERO="/usr/local/sbin/cgroup_clean"
echo ""
echo -e $YELLOW"Creating [${FICHERO}]..."$ENDCOLOR
echo ""
if [ ! -e $FICHERO ];
then
    echo "#!/bin/sh" | tee $FICHERO
    echo "if [ \"\$*\" != \"/user\" ]; then" | tee -a $FICHERO
    echo "rmdir /dev/cgroup/cpu/\$*" | tee -a $FICHERO
    echo "fi" | tee -a $FICHERO

else
    echo "File $FICHERO already exists."
fi;

echo ""
echo -e $YELLOW"Making [${FICHERO}] executable"$ENDCOLOR
echo ""
sudo chmod +x $FICHERO

echo "DONE. The patch has been applied. Restart your computer..."

}
#-----------------------------------------------------------------------------

if [ $USER != root ]; then
  echo -e $RED"Error: you need to run this script as root."
  echo -e $YELLOW"Exiting..."$ENDCOLOR
  exit 0
fi

PARCHEAR

# end

2.) Перезагружаем систему.

Комментариев нет:

Отправить комментарий