Some good information on writing a script in Linux to restart frozen
game servers
can be viewed here:
http://forums.steampowered.com/forums/showthread.php?t=1379885

The author provides a German to English translated link for another
script that also uses qstat.
I found that the script syntax on the original German page works.
original full text here:
http://sourceserver.info/wiki/tutorial/server/response_check

Overall an elegant solution using qstat, lsof and a list of servers to check
I assume hlds_run/srcds was run to launch the game servers before
running this script,  watchdog_hl2.sh

example watchdog_servers

123.123.123:27015
123.123.123:27016

[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
[/code]

_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please 
visit:
https://list.valvesoftware.com/cgi-bin/mailman/listinfo/hlds_linux

Reply via email to