Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mkitab problem with /etc/inittab respawning

Status
Not open for further replies.

jeffpas

Programmer
Jul 21, 2008
4
0
0
US
Hi All:

I have worked with /etc/inittab on SCO, but apparently with AIX you should use the 'mkitab' command to add entries instead of just vi'ing the file.

I just need a daemon process (script called 'dpr_daemon') to kick off once and restart if it is ever killed.
After checking through documentation, the logical step appears to be (level 2, normal) add to inittab w/this line:


mkitab "dprdaemon:2:respawn:/dplogs/dpr_daemon"

However, when I do this, I immediately find 10-25 dpr_daemons running on the box. The shock and awe result. Live box, can't play around too much with this.

Is there something I am missing? Surely 'respawn' is as documented in man pages, respawn the process only if killed. 'once' would not restart the process if killed.

Thanks much for any advice---
jeffpas
 
Let me guess, your script fires off the daemon in the background? If so then that is not a good candidate for inittab respawn processing. Modify your script so that it runs the daemon in foreground, or that it [tt]wait[/tt]s for all background processes to finish.


HTH,

p5wizard
 
I'm not following.

Isn't a daemon by its very nature, just a program that runs continually in the background? Thats all this is:

----------
#!/usr/bin/perl

## load required modules
use strict;
use POSIX qw(setsid);
use LWP::Simple;

## Define functions
sub daemonize {
chdir '/' or die "Can't chdir to /: $!";
open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
open STDOUT, '>>/dev/null' or die "Can't write to /dev/null: $!";
open STDERR, '>>/dev/null' or die "Can't write to /dev/null: $!";
defined (my $pid = fork) or die "Can't fork: $!";
exit if $pid;
setsid or die "Can't start a new session: $!";
umask 0;
}


## The following executable called by dpr_daemon
sub monitor_logfiles {
`/dplogs/dpr/dpr_monitor`;
}


## initialize Perl
$[ = 1; # set array base to 1
$| = 1; # flush the buffer


## prepare dpr_daemon
daemonize();


## summon dpr_daemon
while(1) {
monitor_logfiles;

#wait for 20 seconds
sleep(20);
}

------------------


Isn't there some way to just change the /etc/inittab entry to make it respawn without becoming 100 daemons?



 
Well, you have created a [tt]perl[/tt] program that, when run on the command line, starts an image of itself in background, and then returns control to the shell prompt. That perl program is not suitable for running in respawn mode from [tt]init/inittab[/tt]. I'd leave out the fork/exit bit in your daemonize function, so that dpr_daemon effectively runs under [tt]init[/tt]'s control.

As you have it coded now, it's the [tt]exit if $pid;[/tt] that terminates the dpr_daemon process as started by [tt]init[/tt] (after forking a child process that really runs the daemon). [tt]init[/tt] sees its child dpr_daemon exiting (and runs it again as per [tt]respawn[/tt]). Init takes no notice of its grandchild (process forked by [tt]init[/tt]'s child).


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top