I would probably use the bones of the answer you refer to, but add:
a handler for SIGHUP
which re-reads the config file of IPs to suppress, and,
a handler for SIGUSR1
which reports how much time there is remaining.
So, it would look like this roughly:
#!/usr/bin/perl
use strict;
use warnings;
use Proc::Daemon;
Proc::Daemon::Init;
my $continue = 1;
################################################################################
# Exit on SIGTERM
################################################################################
$SIG{TERM} = sub { $continue = 0 };
################################################################################
# Re-read config file on SIGHUP
################################################################################
$SIG{HUP} = sub {
# Re-read some config file - probably using same sub that we used at startup
open(my $fh, '>', '/tmp/status.txt');
print $fh "Re-read config file\n";
close $fh;
};
################################################################################
# Report remaining time on SIGUSR1
################################################################################
$SIG{USR1} = sub {
# Subtract something from something and report difference
open(my $fh, '>', '/tmp/status.txt');
print $fh "Time remaining = 42\n";
close $fh;
};
################################################################################
# Main loop
################################################################################
while ($continue) {
sleep 1;
}
You would then send the HUP signal or USR1 signal with:
pkill -HUP daemon.pl
or
pkill -USR1 daemon.pl
and look in /tmp/status.txt
for the output from the daemon. The above commands assume you stored the Perl script as daemon.pl
- adjust if you used a different name.
Or you could have the daemon write its own pid
in a file on startup and use the -F
option to pkill
.