Gustavo Parrini wrote:
Hi All,I'm having a pretty hard time trying to figure out how can I get init(8) to run a daemon and respawn it if it crashes. By the time I was a Linux user, it was done by adding a line in /etc/inittab and it was all... I know that it must be done in /etc/ttys but I couldn't find any syntax example after searching the FreeBSD manpages, maillists, Handbook and Google. "man init" gives me this: ... The *init* utility can also be used to keep arbitrary daemons running, automatically restarting them if they die. In this case, the first fieldin the ttys(5) <http://www.freebsd.org/cgi/man.cgi?query=ttys&sektion=5&apropos=0&manpath=FreeBSD+6.0-RELEASE+and+Ports> file must not reference the path to a configured devicenode and will be passed to the daemon as the final argument on its com- mand line. This is similar to the facility offered in the AT&T System V UNIX //etc/inittab/. ... Sounded a little cryptic to me... sorry... Can anyone help me? If so, An example line would be fine.
Lets take sendmail as an example here -- just for something concrete to write about, and not because sendmail needs this sort of treatment. Now, you need 4 fields to go into the /etc/ttys file to make this work: name -- which terminal device to use getty -- the program to attach to that terminal type -- the terminal type status -- on or off (See the comments in the /etc/ttys file for more detail on this) So as an example /etc/ttys line try: sendmail "/usr/sbin/sendmail -L sm-mta -bB -q30m" network on The first field here is an arbitrary name -- anything will do so long as it doesn't collide with any of the terminal device names from /dev. The second field is the command and arguments to run, encased in "double quotes". Note the '-bB' flag -- that's important and tells sendmail to stay in the foreground. You definitely don't want '-bd' here. The third field -- terminal type -- is really irrelevant here, so just choose something vaguely appropriate. The fourth field tells init "yes, please do run the sendmail process". Your confusion stems from the fact that what you are doing is running a daemon process -- i.e. a process /without/ a controlling terminal -- from the configuration file for setting up the processes that manage terminals. Yes, it's a hack. The SysV-ish /etc/inittab mechanism has been better thought out in this regard. Note too that when we say 'daemon' we don't mean a process that forks itself on startup, which is part of the standard mechanism for a process to dissociate itself from any controlling terminal (see daemon(3)). All programs in the base system intended to run as daemons will do that, which makes them completely unsuitable for running through this mechanism -- you'll just end up with init(8) spinning madly as it continually tries to restart the process. You can only use the /etc/ttys trick with a program that stays in the foreground. Many system daemons have a debug mode which prevents them from doing the initial fork to dissociate themselves from the terminal.You might wish to investigate the sysutils/daemontools port, which is a set of programs developed by Dan Bernstein for doing (inter alia) pretty
much exactly this job: http://cr.yp.to/daemontools.html Cheers, Matthew -- Dr Matthew J Seaman MA, D.Phil. 7 Priory Courtyard Flat 3 PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate Kent, CT11 9PW
signature.asc
Description: OpenPGP digital signature