[CentOS] Restarting a Perl-script (socket daemon) from /etc/inittab

Alexander Farber alexander.farber at gmail.com
Thu Jun 2 20:29:44 UTC 2011


On Thu, Jun 2, 2011 at 10:10 PM, Les Mikesell <lesmikesell at gmail.com> wrote:
> On 6/2/2011 2:46 PM, Alexander Farber wrote:
>>
>> The Perl server poll()s TCP-sockets and forks
>> only once - at the startup by calling this method:
>>
>>      sub daemonize {
>>          die "Can not fork: $!\n" unless defined (my $child = fork());
>>          # the parent should die
>>          exit 0 if $child;
>
> [....]
>
>> Since I'm tired of restarting the server manually,
>> I've tried to add it to the /etc/inittab:
>>
>>      pref:3:respawn:/bin/su -c '/usr/local/pref/pref.pl' nobody
>>
>> (and I've added a nightly cronjob to
>> "pkill pref.pl" in the hope to refresh perl this way).
>>
>> Unfortunately this does not work as expected -
>> in the /var/log/messages I see that the script
>> is being started again and again every 5 mins:
>>
>>      Jun  2 18:55:56 myhost init: Id "pref"
>>      respawning too fast: disabled for 5 minutes
>>
>> What am I doing wrong here?
>
> It needs to not fork/exit on its own if you want init to respawn when it
> exits.

Thank you Les, so init does the forking for me?

I'll try it in few hours, when I have less users online.

And I wonder how often does init try to run
a program, before it stops for 5 minutes...

Mark, my pref.pl is 80 lines long, the rest is in few modules.

Yes, perl interpreter 5.8.8 crashes for me once a week,
but I don't really have a chance to solve it - I'm not a
perl interpreter developer myself, I don't have an easy
test case for them to try, I don't have a 2nd server or time
to reproduce it myself. I need to solve this problem now
(going to vacation on Sunday).

Greetings from Germany
Alex



More information about the CentOS mailing list