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?
gheistConnect With a Mentor Commented:
No error message no refund.
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.

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

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....
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" ...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.