]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LEI.pm
lei up --all: send signals to workers, receive errors
[public-inbox.git] / lib / PublicInbox / LEI.pm
index 9620e26422134ff92531707ab1b01a4629e5a606..b6338377328f01a4cb382a13b2bf73e677cafa74 100644 (file)
@@ -516,12 +516,6 @@ sub sigpipe_handler { # handles SIGPIPE from @WQ_KEYS workers
        fail_handler($_[0], 13, delete $_[0]->{1});
 }
 
-# PublicInbox::OnDestroy callback for SIGINT to take out the entire pgid
-sub sigint_reap {
-       my ($pgid) = @_;
-       dwaitpid($pgid) if kill('-INT', $pgid);
-}
-
 sub fail ($$;$) {
        my ($self, $buf, $exit_code) = @_;
        local $current_lei = $self;
@@ -579,6 +573,7 @@ sub _lei_atfork_child {
                POSIX::setpgid(0, $$) // die "setpgid(0, $$): $!";
        }
        close($_) for (grep(defined, delete @$self{qw(3 old_1 au_done)}));
+       delete $self->{-socks};
        if (my $op_c = delete $self->{pkt_op_c}) {
                close(delete $op_c->{sock});
        }
@@ -600,6 +595,7 @@ sub _lei_atfork_child {
                        $cb->(@_) unless PublicInbox::Eml::warn_ignore(@_)
                };
        }
+       $SIG{TERM} = sub { exit(128 + 15) };
        $current_lei = $persist ? undef : $self; # for SIG{__WARN__}
 }
 
@@ -1149,7 +1145,9 @@ sub event_step {
                if ($buf eq '') {
                        _drop_wq($self); # EOF, client disconnected
                        dclose($self);
-               } elsif ($buf =~ /\A(?:STOP|CONT)\z/) {
+                       $buf = 'TERM';
+               }
+               if ($buf =~ /\A(?:STOP|CONT|TERM)\z/) {
                        my $sig = "-$buf";
                        for my $wq (grep(defined, @$self{@WQ_KEYS})) {
                                $wq->wq_kill($sig) or $wq->wq_kill_old($sig);
@@ -1157,6 +1155,8 @@ sub event_step {
                } else {
                        die "unrecognized client signal: $buf";
                }
+               my $s = $self->{-socks} // []; # lei up --all
+               @$s = grep { send($_, $buf, MSG_EOR) } @$s;
        };
        if (my $err = $@) {
                eval { $self->fail($err) };