2 # Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
5 usage: public-inbox-watch
7 See public-inbox-watch(1) man page for full documentation.
11 use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev);
12 use IO::Handle; # ->autoflush
13 use PublicInbox::Watch;
14 use PublicInbox::Config;
16 use PublicInbox::Sigfd;
17 use PublicInbox::Syscall qw(SFD_NONBLOCK);
19 GetOptions('scan!' => \$do_scan, # undocumented, testing only
20 'help|h' => \(my $show_help)) or do { print STDERR $help; exit 1 };
21 if ($show_help) { print $help; exit 0 };
22 my $oldset = PublicInbox::DS::block_signals();
25 local $0 = $0; # local since this script may be eval-ed
26 my $watch = PublicInbox::Watch->new(PublicInbox::Config->new);
28 my $prev = $watch or return; # SIGQUIT issued
30 $watch = PublicInbox::Watch->new(PublicInbox::Config->new);
32 warn("I: reloaded\n");
34 warn("E: reloading failed\n");
43 $watch->trigger_scan('full');
46 $watch->quit if $watch;
53 CHLD => \&PublicInbox::DS::enqueue_reap,
55 $sig->{QUIT} = $sig->{TERM} = $sig->{INT} = $quit;
57 # --no-scan is only intended for testing atm, undocumented.
58 PublicInbox::DS::requeue($scan) if $do_scan;
60 my $sigfd = PublicInbox::Sigfd->new($sig, SFD_NONBLOCK);
61 local @SIG{keys %$sig} = values(%$sig) unless $sigfd;
63 PublicInbox::DS::sig_setmask($oldset);
64 PublicInbox::DS->SetLoopTimeout(1000);
66 $watch->watch($sig, $oldset) while ($watch);