I have a FreeBSD server that has been running a certain game server for years. However, while other processes have been automatically starting with no apparent issue, trying to get the game server processes to automatically start upon a system startup seems to elude me. I'm thinking that rc.d might be a good way to start these processes - but I need further advice.
First of all, some background information. The game server processes work fine once all other processes have been loaded (ie, when I can SSH to the console) and I run the startup script. The game processes work relatively reliably, but they have been known to crash. Therefore, I had to create a script that would automatically restart the game server process automatically. Secondly, I needed to launch these processes in the background but STILL RETAIN access to the shell process if needed (hence the use of SCREEN). Lastly, due to memory leaks and performance issues after the processes have been running for a significant amount of time, I have a crontab that kills all the game server processes at midnight (thereby forcing them to restart).
Obviously, for security purposes, I'm not explaining anything TOO specific - but since this is a scripting question, the actual game server processes shouldn't need to be revealed.
Version of FreeBSD : 5.3 (patched monthly)
I have a user - "gameserver" which is the user that is supposed to start the game server processes.
I have a directory, "/home/gameserver/game" which contains all of the game programs etc
Script 1 - startall.sh :
(note that there are actually a LARGE number of gameserver processes that get launched - but for simplicity sake, I've cut down the script to show only two being launched)
Script 2 - gameserver1.sh
# Setup resource limits
#ulimit -c 0
#ulimit -m 362144
#ulimit -u 32
/usr/local/bin/screen -d -m /home/gameserver/game/start_server1.sh -S gameserver1
(note that all the startup scripts are similar to the above)
Script 3 - start_server1.sh
/bin/cat $GAMEDIR/resetofserver.txt |/usr/sbin/sendmail firstname.lastname@example.org
while [ -f $lockfile ]
for nummod in $modules
$GAMEDIR/gameserver -module $nummod -port 9999
echo "restarting in 60 seconds....."
So there you have it. I'd be really happy if someone could give me some pointers to starting the "startall.sh" script AS the "gameserver" user ID upon system startup - that way, I could just let my FreeBSD system happily reset itself each month, and I wouldn't have to log in to start it (which is what I have to do currently !)