Robert E. Schaefer wrote:
> I'm trying to set up a game server that runs a game called half-life.
> I have no problems getting the server to start but I'm not much of the
> script artist. I start the program with the command ./hlds_run from
> users home directories where the instances are installedwith options
> after it. What I looking for is a way to autostart 6 different
> instances of this at runlevel 3 and way of checking to make sure that
> all the servers are running and restart any that have crashed. Any
> help would be great thanks
When running game servers, I've found it best to use a script wrapper
with an infinite loop (also, run it as a user like "halflife", NOT AS
ROOT, it's just a smart thing to do):
#!/bin/bash
# Create this as "restartscript.sh" in your path
while /bin/true; do
echo $$ > /var/run/restartscript.pid
su - halflife -c ./hlds_run
done
As these game servers usually need consoles as well, I recommend using
screen:
screen -S halflife -t halflife -h 10000 -d -m -l -fn restartscript.sh
You will want 6 of those restartscripts, one to start up each server.
Put this in a system startup script in /etc/init.d (or /etc/rc.d/init.d
on redhat):
#!/bin/bash
# Put this in /etc/init.d/halflife
case "$1" in
start)
screen -S halflife1 -h 10000 -d -m -l -fn restartscript1.sh
screen -S halflife2 -h 10000 -d -m -l -fn restartscript2.sh
screen -S halflife3 -h 10000 -d -m -l -fn restartscript3.sh
screen -S halflife4 -h 10000 -d -m -l -fn restartscript4.sh
screen -S halflife5 -h 10000 -d -m -l -fn restartscript5.sh
screen -S halflife6 -h 10000 -d -m -l -fn restartscript6.sh
;;
stop)
kill `cat /var/run/restartscript1.pid`
kill `cat /var/run/restartscript2.pid`
kill `cat /var/run/restartscript3.pid`
kill `cat /var/run/restartscript4.pid`
kill `cat /var/run/restartscript5.pid`
kill `cat /var/run/restartscript6.pid`
;;
esac
Now add it to your default runlevel (ie, 2 for Debian, 3 for RedHat):
Debian:
ln -s /etc/init.d/halflife /etc/rc2.d/S99halflife
ln -s /etc/init.d/halflife /etc/rc0.d/K00halflife
RedHat:
ln -s /etc/rc.d/init.d/halflife /etc/rc3.d/S99halflife
ln -s /etc/rc.d/init.d/halflife /etc/rc0.d/K00halflife
When the machine boots, it will run the halflife init script, which will
spawn off 6 screen sessions that in turn spawn off the restartscript for
each halflife server. If a server dies, the restartscript will restart
that hlds_run server binary.
If you wish to list the running screen consoles, use:
screen -ls
If you wish to attach to a running screen console, refer to it by name:
screen -x halflife1
You can have multiple sessions open with "screen -x", but the screen
geometry may be wrong. If so, attach forcefully and disconnect all other
screen sessions:
screen -r -d halflife1
Either way works.
Hope this helps.
-- - Ian C. Blenke <icblenke@nks.net> (This message bound by the following: http://www.nks.net/email_disclaimer.html)----------------------------------------------------------------------- This list is provided as an unmoderated internet service by Networked Knowledge Systems (NKS). Views and opinions expressed in messages posted are those of the author and do not necessarily reflect the official policy or position of NKS or any of its employees.
This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 19:44:28 EDT