]> Sergey Matveev's repositories - public-inbox.git/blob - script/public-inbox-watch
51f1baa29c98868c6d9ded5c57702540fc1d3a46
[public-inbox.git] / script / public-inbox-watch
1 #!/usr/bin/perl -w
2 # Copyright (C) 2016 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use strict;
5 use warnings;
6 use PublicInbox::WatchMaildir;
7 use PublicInbox::Config;
8 my ($config, $watch_md);
9 my $reload = sub {
10         $config = PublicInbox::Config->new;
11         $watch_md->quit if $watch_md;
12         $watch_md = PublicInbox::WatchMaildir->new($config);
13 };
14 $reload->();
15 if ($watch_md) {
16         my $scan = sub { $watch_md->trigger_scan('full') if $watch_md };
17         $SIG{HUP} = $reload;
18         $SIG{USR1} = $scan;
19         $SIG{ALRM} = sub { $SIG{ALRM} = 'DEFAULT'; $scan->() };
20         alarm(1);
21         $watch_md->watch while ($watch_md);
22 }