about summary refs log tree commit homepage
path: root/script/public-inbox-watch
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-08-31 04:41:33 +0000
committerEric Wong <e@80x24.org>2020-09-01 00:19:16 +0000
commit3bfbaacac15a14a379e360dc2d6c5989f49c3769 (patch)
tree88447989892c7f8343d53f86467895732f1a0628 /script/public-inbox-watch
parentcee907599bb7eda0695ae91cf8d633670a88d6c7 (diff)
downloadpublic-inbox-3bfbaacac15a14a379e360dc2d6c5989f49c3769.tar.gz
Sometimes it may not be apparent when/if a signal is
processed, this hopefully improves the situation.

We'll also change the process title when we're quitting
to better inform users.
Diffstat (limited to 'script/public-inbox-watch')
-rwxr-xr-xscript/public-inbox-watch24
1 files changed, 18 insertions, 6 deletions
diff --git a/script/public-inbox-watch b/script/public-inbox-watch
index 02491860..b6c6b202 100755
--- a/script/public-inbox-watch
+++ b/script/public-inbox-watch
@@ -11,18 +11,30 @@ use PublicInbox::Syscall qw($SFD_NONBLOCK);
 my $oldset = PublicInbox::Sigfd::block_signals();
 STDOUT->autoflush(1);
 STDERR->autoflush(1);
-my ($config, $watch);
+local $0 = $0; # local since this script may be eval-ed
+my $watch = PublicInbox::Watch->new(PublicInbox::Config->new);
 my $reload = sub {
-        $config = PublicInbox::Config->new;
-        $watch->quit if $watch;
-        $watch = PublicInbox::Watch->new($config);
+        my $prev = $watch or return; # SIGQUIT issued
+        $watch->quit;
+        $watch = PublicInbox::Watch->new(PublicInbox::Config->new);
+        if ($watch) {
+                warn("I: reloaded\n");
+        } else {
+                warn("E: reloading failed\n");
+                $watch = $prev;
+        }
 };
-$reload->();
+
 if ($watch) {
-        my $scan = sub { $watch->trigger_scan('full') if $watch };
+        my $scan = sub {
+                return if !$watch;
+                warn "I: scanning\n";
+                $watch->trigger_scan('full');
+        };
         my $quit = sub {
                 $watch->quit if $watch;
                 $watch = undef;
+                $0 .= ' quitting';
         };
         my $sig = {
                 HUP => $reload,