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: www.mortall.ro/download/qstat2.tar