Skip to content

AutomaticStartup INITTAB method

Lieven Hollevoet edited this page Sep 22, 2014 · 1 revision

The following is from Harald Koch on 04/2002

I'll offer an alternate method. Neither is really better or worse; it depends on your environment and requirements. I have a strong preference for running mission critical software directly from init, instead of from startup scripts; init will automatically restart software that crashes. I do this with misterhouse, SSH, and a database that I run. init is controlled from a file called (usually) /etc/inittab. Here's my MH entry from inittab:

 mh:2345:respawn:/home/mhouse/mhinit

This tells init to run ``/home/mhouse/mhinit when the computer is in any multi-user mode (see Mike's message for a definition of runlevels), and to run it again when it exits. And here's my script:

 ----- /home/mhouse/mhinit -----
 #!/bin/sh
 mhhome=/home/mhouse
 cd ${mhhome}
 exec >> error_log 2>&1
 export PATH=${mhhome}/mh/bin:${mhhome}/bin:$PATH
 export mh_parms=${mhhome}/mh.ini
 # rotate logs
 /bin/mv log.3 log.4
 /bin/mv log.2 log.3
 /bin/mv log.1 log.2
 /bin/mv log.0 log.1
 /bin/mv log   log.0
 # start
 exec ${mhhome}/mh/bin/mh -log_file ${mhhome}/log
 ----- /home/mhouse/mhinit -----

This method *does* make it harder to stop MH, because you have to edit /etc/inittab, change the ``respawn to ``off, and then run ``telinit q to tell init to re-read the config file. On the other hand, it means that MH will restart itself automatically even if it exits due to bad code, which does happen to me occaisionally.


Additional note: Make sure your script is executable. chmod +x scriptname

Clone this wiki locally