use IO::FDPass;
use POSIX qw(_exit setsid :sys_wait_h :errno_h :signal_h);
use Sys::Syslog qw(openlog syslog LOG_INFO LOG_ERR LOG_WARNING);
+use Time::HiRes qw();
our $logger;
}
}
+sub autoreload_check ($) {
+ my ($f) = @_;
+ my @s = Time::HiRes::stat($f);
+ if (!@s) {
+ $!==ENOENT or fail_log("autoreload check: stat failed: $f: $!");
+ return;
+ }
+ if ($s[9] > $startup_mtime) {
+ syslog(LOG_INFO, "$0 prefork [$$]: reloading; due to $f");
+ _exit(0);
+ }
+}
+
sub initialisation_complete {
my %opts = @_;
fail_log("watcher stderr read: $!");
}
- # TODO stat checking, quit here if we are stale
+ if (%opts{autoreload_inc} // 1) {
+ foreach my $f (values %INC) {
+ autoreload_check($f);
+ }
+ }
+ foreach my $f (@{ %opts{autoreload_extra} // [] }) {
+ autoreload_check($f);
+ }
# Anything to accept ?
if (accept(CALL, LISTEN)) {