Automatically starting a script upon startup under FreeBSD 5.3

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 - :

sleep 60

(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 -

# Setup resource limits
#ulimit -c 0
#ulimit -m 362144
#ulimit -u 32

/usr/local/bin/screen -d -m /home/gameserver/game/ -S gameserver1
exit 0

(note that all the startup scripts are similar to the above)

Script 3 -


export TERM=vt100

errorNotify() {
/bin/cat $GAMEDIR/resetofserver.txt |/usr/sbin/sendmail

while [ -f $lockfile ]
        for nummod in $modules
        $GAMEDIR/gameserver -module $nummod -port 9999
                rm $GAMEDIR/gameserver.core
        echo "restarting in 60 seconds....."
        sleep 30
exit 0

So there you have it.  I'd be really happy if someone could give me some pointers to starting the "" 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 !)

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

FreeBSD 5.3 EOL-ed year ago.

You can make ripoff of arpwatch startup script, so run "su - user -c gameserver" from script started from /etc/rc.local

See there for scripting advice:
altquarkAuthor Commented:
Hi gheist

ok - I entered

su - gameserver -c '/home/gameserver/game/'

into the /etc/rc.local - and restarted the freebsd box.  

I have, of course, tried this in the past (don't ya love how I provide all the info !) - but I get segmentation faults in the screen sessions - which is the critical issue.  The screen sessions are correctly starting up and they're running the gameserver processes - but each of them segfaults.

altquarkAuthor Commented:
I believe there are a bunch of issues with launching this type of program because of user permissions etc.  Screen helps a lot - and I think I actually figured it out myself.

Because the process is calling not only multiple scripts, but has to call "screen" to launch the individual processes, then all of these should also be launched through screen.

Therefore, I created yet another script - owned by root - called "" which looks like this :

sleep 10
su gameserver -c '/usr/local/bin/screen -d -m /home/gameserver/game/ -S startup'
exit 0

and added this snippet to rc.local

However, I am STILL getting segmentation fault errors.  I'm not sure how to trace these...

If, on the other hand, I wait until the system is up and running - then launch /home/gameserver/game/ AS "gameserver" manually - then everything works perfectly well....

Note, I even tried the "sleep 10" to see if it was something in the system that might not have completed before trying to start all the processes....
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Probably your game server executable reads input. Wrap it:

/opt/game1/gameserver </dev/null 2>&1 >>/dev/null

i.e give it empty input handle.

Normally you need to run gdb against crashing gameserver executable and check what goes wrong.

Can you post error itself?
altquarkAuthor Commented:
I've still not worked out why it doesn't seem to like to restart the server upon system startup - but its fine to start when everything is "quiet".

I'm closing the question and marking it currently as "unsolved" ...
No error message no refund.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.