]> Sergey Matveev's repositories - public-inbox.git/blob - script/public-inbox-watch
public-inbox-watch: support reloading config with SIGHUP
[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 = PublicInbox::WatchMaildir->new($config);
12 };
13 $reload->();
14 if ($watch_md) {
15         my $scan = sub { $watch_md->scan if $watch_md };
16         $SIG{HUP} = $reload;
17         $SIG{USR1} = $scan;
18         $SIG{ALRM} = sub { $SIG{ALRM} = 'DEFAULT'; $scan->() };
19         alarm(1);
20         $watch_md->watch;
21 }