Followers

Tag

Diberdayakan oleh Blogger.
Posted by : Alfarady Sabtu, 17 November 2012

General Information: This should be useful to about 100 people or maybe just one person. The Valve script hlds_run monitors the exit status of hlds. If the server crashes or you send an rcon quit hlds_run will restart the game server. What can you do when hlds does not crash it freezes with a segmentation fault? A watchdog timer - to ping hlds from time to time, when there is no reply kill the hung process. Let hlds_run restart hlds.

edit: some people like to use tmux for multiple virtual displays and they say it is better than screen.
Linux script to monitor and restart frozen game servers. Install the dedicated server files and the mod. Plus qstat, lsof and screen for mutiple virtual displays.
Some good information on writing a script in Linux to restart frozen game servers using qstat can be viewed here: http://forums.steampowered.com/forum....php?t=1379885
The author provides a link to another script that uses qstat. It is translated from German to English, I found that the script syntax on the original German page works.
original full text here: http://sourceserver.info/wiki/tutori...response_check

Overall a fairly elegant solution using qstat, lsof and a list of servers to check, I assume hlds_run was used to launch the game servers before running this script as a cron job. watchdog.sh

Code:
#!/bin/bash

function init {
       if [ -z "`which lsof`" ]; then echo "lsof isn't installed"; return 1; fi
       if [ ! -f ~/qstat ]; then echo "qstat isn't installed"; return 1; fi
       if [ ! -f ~/watchdog_servers ]; then echo "~/watchdog_servers
doesn't exists"; 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 ~/watchdog_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 "[Not Running]"
               [[ ! -z "$pid" ]] && kill $pid && echo "[Restarted]"
       else
       echo "[OK]"
       fi
}

init || exit
for server in `parse_list`; do
       kill_dead_server $server
done
Example to start a svencoop dedicated server (when it is released). First create a virtual display for access to the game console.
screen -AmdS firstserv
You will see a normal prompt like nothing happend. OK

cd ~hlserver
./hlds_run.sh -game svencoop -num_edicts 3072 +ip 123.123.123.123 +port 27015 +map osprey -pingboost 2 -autoupdate -timeout 6
Now disconnect from that screen with Ctrl-a d. To reconnect later, type: screen -r firstserv

Edit: The above steps can also be done like this. you will not see the game server start-up until you connect to it's screen.
cd ~hlserver
screen -AmdS firstserv ./hlds_run.sh -game svencoop -num_edicts 3072 +ip 123.123.123.123 +port 27015 +map osprey -pingboost 2 -autoupdate -timeout 6

Create a text file containing a list of servers to check. watchdog_servers
123.123.123.123:27015

Run the watchdog timer to see how it works ./watchdog.sh
Then you can setup the watchdog timer as a cron job.

Edit: run crontab -e add the task to be run, this one runs once per minute. Leave one blank line at the bottom.
*/1 * * * * ~/watchdog.sh &>/dev/null

---

Enjoy,

Leave a Reply

Subscribe to Posts | Subscribe to Comments

- Copyright © 2013 Alfarady Blog -Dekomori- Powered by Blogger - Designed by Johanes Djogan - ReDesigned by AlfaKun -

Gunakan Browser Google Chrome agar tampilan maksimal