In most versions of Linux, one of the common mechanisms to have a program automatically started when you first boot up the machine is by placing an entry in /etc/inittab.
For background, this is what it's all about. A program called "init" is the first program that runs when a Unix system first starts, and its job is just to start and babysit a bunch of other programs. Those are listed (on most systems) in the "/etc/inittab" file. Besides the name of the program and options it needs to run, you can specify there when the program should be run (e.g. always, just when we're starting up or shutting down, etc.) and what to do if it stops running. In some ways this is similar to other tools like 'cron', but has its differences. So while 'cron' is something that wakes up every so often and runs a program by itself, 'init' is always running, and so can keep an eye on any program its responsible for, starting it or stopping it as needed.
Depending how you want to run ProjectForum, exactly what you put in /etc/inittab will also vary. But here is a fairly typical example:
ptmp:2345:respawn:su -c '/home/pfuser/projectforum -directory /home/pfuser -nologo' pfuser
Let's dissect this:
- the "ptmp" is a unique identifier for every entry in /etc/inittab
- the "2345" specifies the "runlevel" at which the process should be running (2345 represents normal system operation, rather than for example the time when the machine is shutting down)
- the "respawn" says that if for some reason the process is terminated, it will be automatically restarted
- everything after the last colon is the actual command to be run, which in this case has several pieces:
- the "su -c '...' pfuser" means that the process should be run not as the fully privileged root user, but by a user account pfuser; you could also accomplish this using a 'setuid' binary
- the "/home/pfuser/projectforum" is the process that will be run (i.e. the ProjectForum application)
- the "-directory /home/pfuser" provides the location where ProjectForum will write it's "Group Data" directory
- the "-nologo" instructs ProjectForum not to write out any status messages like "listening on ..."
- the "su -c '...' pfuser" means that the process should be run not as the fully privileged root user, but by a user account pfuser; you could also accomplish this using a 'setuid' binary
Again, because each system is different, you'll want to check for specifics; try "man init" and "man inittab".

With some (which?) versions of cron on Linux, you can replace the above by a line in the crontab for that user (crontab -e), containing something like:
@reboot ./projectforum -nologo
This will not restart pf if it ever stops, but it does start it up after every reboot - works nicely on unattended systems.
Posted by: | December 11, 2007 at 08:02 AM