There are (at least) two ways to do what you want. The simple way is to add commands to the file /etc/rc.d/rc.local
(or /etc/rc.local, which is normally just a link to /etc/rc.d/rc.local); commands in this file get executed at the end of the startup process.
A better way is to treat your program like any other server process, and not only consider graceful startup but also graceful shutdown. Look at xfs, the font server as a fairly simple model. First, look at the executable script file /etc/rc.d/init.d/xfs; it can be called with any of the arguments 'start', 'stop', 'restart' or 'status' and these are handled by the case command. The script makes use of various functions defined in the file 'functions', such as gprintf which handles the translation of messages into other languages (by lookup rather than by advanced linguistic abilities!). There are links to this script in various companion directories:
/etc/rc.d/rc0.d/K10xfs
/etc/rc.d/rc1.d/K10xfs
/etc/rc.d/rc2.d/S20xfs
/etc/rc.d/rc3.d/S20xfs
...and so on...
The digit after the rc in rcN.d refers to a particular runlevel (look at /etc/inittab to see what runlevels are about), the various
scripts in /etc/rcN.d/ are executed when the system enters that runlevel. Scripts named Snn* are startup scripts, executed in alphabetic order so lower nn means executed sooner, and are called with argument 'start'; scripts named Knn* are shutdown (K for kill) scripts, called with the argument 'stop'. Whenever the system enters runlevel N it first runs the Knn* scripts and then runs the Snn* scripts for that runlevel -- look at the script /etc/rc, which is responsible for doing this. And read the man page for init. Also read the man page for chkconfig, a tool that makes it simple to create/delete the links referred to above. You'll
see the lines consulted by chkconfig in the xfs script.
Please don't try to mess with system scripts such as /etc/rc, you can very easily end up with an unmaintainable system -- eg,
even if you get it right, you find yourself upgrading your system to a more recent version of Linux in a few months time, and you forget about those idiosyncratic changes you made, and wonder why your game server no longer starts or stops gracefully. And if you get it wrong by messing with the system scripts, you can get your system into a truly awful mess.
All the best,
Peter R
|