<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Linux Forum &mdash; Привязка к ядру ( баг )]]></title>
		<link>https://linuxforum.ru/viewtopic.php?id=29917</link>
		<atom:link href="https://linuxforum.ru/extern.php?action=feed&amp;tid=29917&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «Привязка к ядру ( баг )».]]></description>
		<lastBuildDate>Tue, 27 Aug 2013 12:16:48 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Привязка к ядру ( баг )]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=360532#p360532</link>
			<description><![CDATA[<div class="codebox"><pre><code>server_name=&quot;GAME#1&quot;  #Название сервера
screen_name=&quot;game&quot;  #Название screen-сессии
use_user=&quot;root&quot;  #Имя юзера от которого запускается сервер
path=&quot;/home/hlds/game&quot;  #Путь до ROOT-директории сервера (без /в конце)
hlds_ip=&quot;&quot;  #IP сервера ,не ставить 0.0.0.0
hlds_port=&quot;&quot;  #Порт сервера
hlds_players=&quot;32&quot;  #Максимальное количество игроков на сервере
hlds_map=&quot;oldstreet3&quot;  #Имя первоначальной карты при запуске
hlds_options=&quot;-insecure +sys_ticrate 1200 -pingboost 2 -noipx&quot;  #Дополнительные параметры запуска
priority=&quot;-20&quot;  #Приоритет для сервера (-20 - Высокий ;20 - Низкий)
usecore=&quot;1&quot;  #Привязка к ядрам (0, 1, 2, 3)
hlds_pid=&quot;${screen_name}.pid&quot;  #Имя pid файла сервера
clear_logs=&quot;1&quot;  # очишать лог файлы при запуске сервера через скрипт?
clear_cache=&quot;1&quot;  # очишать кэши системы перед запуском сервера? # работает только под рутом

checker_cmd=&quot;/bin/qstat&quot; #Команда пакета qStat отвечающего за проверку сервера

#####################################################
# End of configuration
#####################################################

if [ ! -x $path/hlds_run ]; then
    printf &quot;${title}${txtred} Set permissions 777 for hlds_run\n&quot;
    chmod -R 777 $path
fi

if [ $use_user == &quot;root&quot; ]; then
    start1=&quot;&quot;
else
    start1=&quot;sudo -u ${use_user}&quot;
fi

txtwht=&#039;\e[0;37m&#039; # White
txtgrn=&#039;\e[0;32m&#039; # Green
txtylw=&#039;\e[0;33m&#039; # Yellow
txtred=&#039;\e[0;31m&#039; # Red
title=&quot;${txtwht}[${txtgrn}${hlds_ip}:${hlds_port}${txtwht}]&quot;

# check screen pid: ps -ef | grep SCREEN | grep ${screen_name} | grep ${hlds_ip} | grep ${hlds_port} | grep -v grep | awk &#039;{print $2}&#039;
# check hlds pid: ps -ef | grep hlds_ | grep -v hlds_run | grep ${hlds_ip} | grep ${hlds_port} | grep -v grep | awk &#039;{print $2}&#039;

start() {
    if [ &quot;`ps -ef | grep SCREEN | grep $screen_name | grep $hlds_ip | grep $hlds_port | grep -v grep | wc -l`&quot; -gt 0 ]; then
        if [ &quot;`ps -ef | grep hlds_ | grep -v hlds_run | grep $hlds_ip | grep $hlds_port | grep -v grep | wc -l`&quot; -gt 0 ]; then
            printf &quot;${title} Server ${server_name} already started\n&quot;
            exit 1
        fi
    fi
    cd ${path}
    if [ ${clear_logs} == 1 ]; then
        ${start1} rm -f ${path}/debug.log
        ${start1} rm -f ${path}/cstrike/qconsole.log
        ${start1} rm -fr ${path}/cstrike/logs/*.log
        ${start1} rm -fr ${path}/cstrike/addons/amxmodx/logs/*.log
        printf &quot;${title} Server logs cleared\n&quot;
    fi
    if [ ${clear_cache} == 1 ] &amp;&amp; [ ${use_user} == &quot;root&quot; ]; then
        echo 3 &gt; /proc/sys/vm/drop_caches
        printf &quot;${title} Cache &amp;&amp; buffers cleared\n&quot;
    fi
    printf &quot;${title} Starting ${server_name}\n&quot;
    /usr/bin/screen -AmdS ${screen_name} ${start1} ./hlds_run -game cstrike +ip ${hlds_ip} +port ${hlds_port} +map ${hlds_map} +maxplayers ${hlds_players} ${hlds_options} -pidfile ${hlds_pid}
    sleep 3
    ${start1} taskset -pc ${usecore} `cat ${path}/${hlds_pid}` &gt; /dev/null
    ${start1} renice -n ${priority} -p `cat ${path}/${hlds_pid}` &gt; /dev/null
    if [ &quot;`ps -ef | grep hlds_ | grep -v hlds_run | grep ${hlds_ip} | grep ${hlds_port} | grep -v grep | awk &#039;{print $2}&#039;`&quot; = &quot;`cat $path/$hlds_pid`&quot; ]; then
        printf &quot;${title} Server successfully started! :)\n&quot;
    else
        printf &quot;${title}${txtred} Server crashed on start :(\n&quot;
    fi
}

kill_process() {
    if [ &quot;`ps -ef | grep hlds_ | grep -v hlds_run | grep ${hlds_ip} | grep ${hlds_port} | grep -v grep | wc -l`&quot; -gt 0 ]; then
        printf &quot;${title} Kill: `ps -ef | grep SCREEN | grep ${screen_name} | grep ${hlds_ip} | grep ${hlds_port} | grep -v grep`\n&quot;
        ${start1} kill -9 &quot;`ps -ef | grep SCREEN | grep ${screen_name} | grep ${hlds_ip} | grep ${hlds_port} | grep -v grep | awk &#039;{print $2}&#039;`&quot;
        ${start1} rm -f ${path}/${hlds_pid}
    else
        printf &quot;${title}${txtylw} Cannot kill hlds process of ${server_name} server\n&quot;
    fi
}

stop() {
    if [ &quot;`ps -ef | grep SCREEN | grep ${screen_name} | grep ${hlds_ip} | grep ${hlds_port} | grep -v grep | awk &#039;{print $2}&#039; | wc -l`&quot; -eq 1 ]; then
        /usr/bin/screen -dr `ps -ef | grep SCREEN | grep ${screen_name} | grep ${hlds_ip} | grep ${hlds_port} | grep -v grep | awk &#039;{print $2}&#039;`.${screen_name} -p 0 -X eval &quot;stuff &quot;quit&quot;&quot;
        /usr/bin/screen -dr `ps -ef | grep SCREEN | grep ${screen_name} | grep ${hlds_ip} | grep ${hlds_port} | grep -v grep | awk &#039;{print $2}&#039;`.${screen_name} -p 0 -X eval &quot;stuff &quot;$(printf \\r)&quot;&quot;
        sleep 1
        ${start1} rm -rf ${path}/${hlds_pid}
        
        if [ &quot;`ps -ef | grep hlds_ | grep -v hlds_run | grep ${hlds_ip} | grep ${hlds_port} | grep -v grep | wc -l`&quot; -gt 0 ]; then
            printf &quot;${title}${txtred} Server not stopped!\n&quot;
        else
            printf &quot;${title} Server has been stopped\n&quot;
        fi
    else
        printf &quot;${title}${txtylw} Cannot stop server ${server_name}, screen session not found!\n&quot;
    fi
}

status() {
    printf &quot;${title} Get status of server ${server_name}\n&quot;
    ${start1} ${checker_cmd} -retry 3 -interval 2 -a2s ${hlds_ip}:${hlds_port} | grep ${hlds_ip}
    exit 1
}

console() {
    if [ &quot;`ps -ef | grep SCREEN | grep ${screen_name} | grep ${hlds_ip} | grep ${hlds_port} | grep -v grep | wc -l`&quot; -gt 0 ] &amp;&amp; [ &quot;`ps -ef | grep hlds_ | grep -v hlds_run | grep ${hlds_ip} | grep ${hlds_port} | grep -v grep | awk &#039;{print $2}&#039;`&quot; = &quot;`cat ${path}/${hlds_pid}`&quot; ]; then
        printf &quot;${title} Connecting to ${server_name} server console\n&quot;
        printf &quot;${title}${txtylw} For exit from console press Ctrl+A,D\n&quot;
        printf &quot;${title}${txtylw} Don&#039;t press Ctrl+C\n&quot;
        sleep 1
        /usr/bin/screen -wipe &gt; /dev/null
        /usr/bin/screen -dr `ps -ef | grep SCREEN | grep ${screen_name} | grep ${hlds_ip} | grep ${hlds_port} | grep -v grep | awk &#039;{print $2}&#039;`.${screen_name}
    else
        printf &quot;${title}${txtred} Cannot connect to ${server_name} server console, server not started!\n&quot;
    fi
}

checker() {
    time=`date +%X`
    date=`date +%D`
    
    if [ -f ${checker_cmd} ]; then
        if [ ! -x ${checker_cmd} ]; then
            printf &quot;${title}${txtred} Check run privileges of ${checker_cmd}\n&quot;
            exit 1
        fi
    else
        printf &quot;${title}${txtred} Check qstat/quakestat binar\n&quot;
    fi
    
    checknoresp=`${checker_cmd} -retry 5 -interval 2 -a2s ${hlds_ip}:${hlds_port} | grep response`
    if [ -n &quot;${checknoresp}&quot; ]; then
        printf &quot;${title} ${server_name} server is: ${txtred}[NO RESPONSE]\n&quot;
        printf &quot;[${time} - ${date}] *[NO RESPONSE]* ${checknoresp}\n&quot; &gt;&gt; $path/checker.log
        kill_process
        sleep 1
        start
        sleep 1
        printf &quot;StartUP ${title}:&quot; &gt;&gt; ${path}/checker.log
        if [ &quot;`ps -ef | grep hlds_ | grep -v hlds_run | grep ${hlds_ip} | grep ${hlds_port} | grep -v grep | awk &#039;{print $2}&#039;`&quot; = &quot;`cat $path/$hlds_pid`&quot; ]; then
            printf &quot; *[OK]* \n&quot; &gt;&gt; ${path}/checker.log
        else
            printf &quot; *[FAILED]* \n&quot; &gt;&gt; ${path}/checker.log
        fi
        exit 1
    fi
    
    checkdown=`${checker_cmd} -retry 5 -interval 2 -a2s ${hlds_ip}:${hlds_port} | grep DOWN`
    if [ -n &quot;${checkdown}&quot; ]; then
        printf &quot;${title} ${server_name} server is: ${txtred}[DOWN]\n&quot;
        printf &quot;[{$time} - ${date}] *[DOWN]* ${checkdown}\n&quot; &gt;&gt; ${path}/checker.log
        start
        sleep 1
        printf &quot;StartUP ${title}:&quot; &gt;&gt; ${path}/checker.log
        if [ &quot;`ps -ef | grep hlds_ | grep -v hlds_run | grep ${hlds_ip} | grep ${hlds_port} | grep -v grep | awk &#039;{print $2}&#039;`&quot; = &quot;`cat $path/$hlds_pid`&quot; ]; then
            printf &quot; *[OK]* \n&quot; &gt;&gt; ${path}/checker.log
        else
            printf &quot; *[FAILED]* \n&quot; &gt;&gt; ${path}/checker.log
        fi
        exit 1
    fi
    
    checkup=`${checker_cmd} -retry 5 -interval 2 -a2s ${hlds_ip}:${hlds_port} | grep cstrike`
    if [ -n &quot;${checkup}&quot; ]; then
        printf &quot;${title} ${server_name} server is: ${txtgrn}[OK]\n&quot;
        printf &quot;[${time} - ${date}] *[OK]* ${checkup}\n&quot; &gt;&gt; ${path}/checker.log
    fi
    if [ &quot;`ps -e -o pid,cpuid,nice,cmd | grep hlds_ | grep -v SCREEN | grep -v grep | grep -v sh | grep -v hlds_run | grep ${hlds_ip} | grep ${hlds_port} | awk &#039;{print $3}&#039;`&quot; != ${priority} ]; then
        if [ &quot;`ps -ef | grep hlds_ | grep -v hlds_run | grep ${hlds_ip} | grep ${hlds_port} | grep -v grep | awk &#039;{print $2}&#039;`&quot; = &quot;`cat $path/$hlds_pid`&quot; ]; then
            printf &quot;${title}${txtylw} ${server_name} server priority is changed because server is crashed\n&quot;
            ${start1} taskset -pc ${usecore} &quot;`cat ${path}/${hlds_pid}`&quot; &gt; /dev/null
            ${start1} renice -n ${priority} -p &quot;`cat ${path}/${hlds_pid}`&quot; &gt; /dev/null
        else
            printf &quot;${title}${txtylw} ${server_name} server priority cant be restore because not found pidfile!\n&quot;
        fi
    else
        printf &quot;${title} ${server_name} server priority is good!\n&quot;
    fi
}

case &quot;$1&quot; in
    start)
        start
    ;;
    stop)
        stop
    ;;
    restart)
        stop
        kill_process
        sleep 2
        start
    ;;
    status)
        status
    ;;
    console)
        console
    ;;
    checker)
        checker
    ;;
    *)
    printf &quot;${title} How to use: ${txtgrn}$0 {start|stop|restart|status|console|checker}${txtwht}\n&quot;
    exit 1
esac</code></pre></div><p>Смысл таков, после поднятия процесса &quot;после падения&quot; ядро не присваивается и приоритет тоже. Как исправить?<br />То есть после перезапуска нагрузка прыгает по всем ядрам и приоритет становится 0 по дефолту скрипта</p>]]></description>
			<author><![CDATA[null@example.com (Gentoos)]]></author>
			<pubDate>Tue, 27 Aug 2013 12:16:48 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=360532#p360532</guid>
		</item>
	</channel>
</rss>
