in reply to Perl Daemons and SIGHUP

(a) Why is that ?

Because the default action for SIGHUP is to terminate the process

(b) What is the proper way to reload a daemon ?

As you've mentioned yourself on the chatterbox, exec is a possibility. As I've also told you on the chatterbox, installing a signal handler for SIGHUP and doing the exec in that handle might be a solution

(c) I have encountered in CPAN the package Daemon::Generic, which suggest somekind of solution, does anyonen know this package ?

Since three people have written reviews for it, I'd assume that at least 4 people know this package. Probably a lot more.

Replies are listed 'Best First'.
Re^2: Perl Daemons and SIGHUP
by explodec14 (Novice) on Feb 24, 2010 at 12:58 UTC
    Hi -

    I have installed the signal handler as you advised me. but still the exec call terminates the process and i don't know why.

    Here is the code:
    #!/usr/bin/perl -w use strict; use Socket; use Carp; use MTS; use MTS qw(prepare_transaction); use Proc::Daemon; use File::Temp qw(tempfile); use Data::Dumper; use Logger::Syslog; use JSON; use File::Find; use File::Basename; use Cwd 'realpath'; use POSIX (); #use FindBin(); use File::Spec::Functions qw(rel2abs catfile); no warnings 'File::Find'; my $SELF = rel2abs($0); my @argv = @ARGV; # Daemonizing Proc::Daemon::Init unless defined($ENV{"DEBUG"}); use vars qw($mts $qtime $qattr $qsender $qempty $qxtra $qend @template + $PORT @rcpts $pid $lock_dir @children $cfg $CONFIG_FILE); $CONFIG_FILE = '/etc/mts/mts.conf'; # # Forward Declarations # sub spawn; sub _dispatcher; sub _check_spam; sub _process_request; sub _build_msg; sub _enqueue_messages; sub _prepare_message; sub _notify; sub _signal_handler; sub _recover_transactions; sub _lock_maildrop_dir; sub _read_config; sub _reload_config; $SIG{CHLD} = \&REAPER; $SIG{HUP} = \&sigHUP_handler; #$SIG{__DIE__} = 'IGNORE'; $SIG{ABRT} = \&_signal_handler; $SIG{TERM} = \&_signal_handler; $SIG{INT} = \&_signal_handler; _read_config; #print Dumper $cfg; sub sigHUP_handler { #_reload_config; debug("Restarting daemon with: \$SELF=$SELF and \@argv=@argv "); exec($SELF,@argv); } # POSIX unmasks the sigprocmask properly #my $sigset = POSIX::SigSet->new(); #my $action = POSIX::SigAction->new('sigHUP_handler', $sigset, &POSIX: +:SA_NODEFER); #POSIX::sigaction(&POSIX::SIGHUP, $action); #$action = POSIX::SigAction->new('_signal_handler', $sigset, &POSIX::S +A_NODEFER); #POSIX::sigaction(&POSIX::SIGTERM, $action); #POSIX::sigaction(&POSIX::SIGINT, $action); #POSIX::sigaction(&POSIX::SIGABRT, $action);

    pay attention to the commented code block which uses POSIX. This does the same problem too

    10x
      Is the debug()-line executed at all?
      Perl 6 - links to (nearly) everything that is Perl 6.
        yes. but the exec call takes the process out.
        After that when i do on shell: ps aux | grep mtsd i get nothing