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

Les Mikesell lesmikesell at gmail.com
Thu Jun 2 20:10:26 UTC 2011


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.

-- 
  Les Mikesell
    lesmikesell at gmail.com




More information about the CentOS mailing list