[phpBB Debug] PHP Warning: in file [ROOT]/ext/spaceace/ajaxchat/controller/chat.php on line 220: Trying to access array offset on value of type bool
Mortall Forum • Tutoriale Counter Strike | Server CS - Resurse - Pluginuri - Download | TeamSpeak3 | Muzica - Bolby Digital | Filme Online - BluRay TrueHD • Auto restart server - Hlds Linux
Pagina 1 din 1

Auto restart server - Hlds Linux

Scris: Noiembrie 18, 2020, 1:20 am
de [RGK]*Kent
Imagine
Daca aveti un server de Conter-Strike pe linux, mai mult ca sigur cel putin odata sa intamplat ca serverul vostru sa se blocheze si sa nu mai vrea sa porneasca.
Ce poti face atunci cand serverul hlds se blocheaza, cu o eroare de segmentare?
Un timer-watch - care da ping la serverul hlds din cand in cand iar atunci cand nu primeste nici un raspuns inchide procesele blocate apoi reporneste serverul hlds.

O solutie destul de simpla si eleganta: folosim qstat, lsof si bineinteles o lista cu serverele pe care vrem sa le verificam.

INFO!
Instalati qstat inainte de a rula timer-watch
* instalare qstat

Pentru inceput deschidem un document nou cu numele watch_hlds.sh in care vom adauga urmatoarele:

#!/bin/bash

function init {
if [ -z "`which lsof`" ]; then echo "lsof nu este instalat"; return 1; fi
if [ ! -f ~/qstat ]; then echo "qstat nu este instalat"; return 1; fi
if [ ! -f ~/watch_servers ]; then echo "~/watch_servers nu exista"; return 1; fi
return 0
}

function not_response {
~/qstat -a2s $1 -nh -timeout 20 | egrep -q 'no response|DOWN'
}

function get_pid {
lsof -i 4udp@${1} | cut -d ' ' -f2 | tail -n 1
}

function parse_list {
cat ~/watch_servers | tr -d \r
}

function kill_dead_server {
echo -en "Testing -> $1\t\t\t"
if not_response $1; then
pid=`get_pid $1`
[[ -z "$pid" ]] && echo "status: [Not Running]"
[[ ! -z "$pid" ]] && kill $pid && echo "[Restarted]"
else
echo "status:[OK]"
fi
}

init || exit
for server in `parse_list`; do
kill_dead_server $server
done


Deschidem inca un document nou pe care in numim watch_servers in care adaugam serverele care vrem sa le verificam:

123.123.123.123:27015


Acum pornim timer-watch sa vedem daca functioneaza:

./watch_hlds.sh


Vom adauga timer-watch in crontab, acesta va rula odata pe minut.
Deschidem crontab: crontab -e
si adaugam linia:

*/1 * * * * ~/watch_hlds.sh &>/dev/null


* Cam asta a fost.

Si ca sa fim si mai siguri ca scriptul functioneaza si ca serverele HLDS adaugate in watch_servers sunt pornite sau nu, vom incerca sa citim PID-ul acestora in watch_hlds.sh:

#!/bin/bash

function init {
if [ -z "`which lsof`" ]; then echo "lsof nu este instalat"; return 1; fi
if [ ! -f ~/qstat ]; then echo "qstat nu este instalat"; return 1; fi
if [ ! -f ~/watch_servers ]; then echo "~/watch_servers nu exista"; return 1; fi
return 0
}

function not_response {
~/qstat -a2s $1 -nh -timeout 20 | egrep -q 'no response|DOWN'
}

function get_pid {
lsof -i 4udp@${1} | cut -d ' ' -f2 | tail -n 1
}

function parse_list {
cat ~/watch_servers | tr -d \r
}

function kill_dead_server {
echo -en "Testing -> $1\t\t\t"
if not_response $1; then
pid=`get_pid $1`
[[ -z "$pid" ]] && echo "status: [Not Running]"
[[ ! -z "$pid" ]] && kill $pid && echo "[Restarted]"
else
pid=`get_pid $1`
echo "pid:[$pid] status:[OK]"
fi
}

init || exit
for server in `parse_list`; do
kill_dead_server $server
done


* Statistici Live

Deschideti un document nou pe care in numim liveserver.sh in care adaugati urmatoarele:

echo""
./qstat -a2s 123.123.123.123:27015
echo""


salvati si inchideti fisierul apoi rulati comanda:

./liveserver.sh


* Instalare qstat



extragem fisierele:
tar -xzf qstat2.tar.gz


schimbam directorul si pornim instalarea:

cd qstat2/trunk/qstat2
./autogen.sh


*** daca va apare un mesaj de genul:./autogen.sh: 66: aclocal: not found
va trebuii sa instalati automake:

sudo apt-get install automake


apoi executati din nou comanda:
./autogen.sh


finalizam instalare prin:
./configure && make


ultimul pas, copiem qstat in directorul nostru:
cp ./qstat ~/


Download: Daca nu te descurci ai fisierele doar trebuiesc adaugate si editate cu ip:port
Download 1:
Download-link
qstat2.tar
[/b]