X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FDaemon.pm;h=0329bd34ed3292ea93b7db3a737bded43119bf43;hb=3d41aa23f35501ca92aab8aa42980fa73f7fa74f;hp=9125584b3b12b334a078eb1c9aec1ff4aa5f27af;hpb=87b61d1daa05bdcf9d810d1655e5abb45456e9a5;p=public-inbox.git diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm index 9125584b..0329bd34 100644 --- a/lib/PublicInbox/Daemon.pm +++ b/lib/PublicInbox/Daemon.pm @@ -1,5 +1,5 @@ -# Copyright (C) 2015 all contributors -# License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt) +# Copyright (C) 2015-2018 all contributors +# License: AGPL-3.0+ # contains common daemon code for the nntpd and httpd servers. # This may be used for read-only IMAP server if we decide to implement it. package PublicInbox::Daemon; @@ -9,6 +9,7 @@ use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/; use IO::Handle; use IO::Socket; use Cwd qw/abs_path/; +use Time::HiRes qw(clock_gettime CLOCK_MONOTONIC); STDOUT->autoflush(1); STDERR->autoflush(1); require Danga::Socket; @@ -102,16 +103,18 @@ sub check_absolute ($$) { } sub daemonize () { - foreach my $i (0..$#ARGV) { - my $arg = $ARGV[$i]; - next unless -e $arg; - $ARGV[$i] = abs_path($arg); - } - check_absolute('stdout', $stdout); - check_absolute('stderr', $stderr); - check_absolute('pid-file', $pid_file); + if ($daemonize) { + foreach my $i (0..$#ARGV) { + my $arg = $ARGV[$i]; + next unless -e $arg; + $ARGV[$i] = abs_path($arg); + } + check_absolute('stdout', $stdout); + check_absolute('stderr', $stderr); + check_absolute('pid-file', $pid_file); - chdir '/' or die "chdir failed: $!"; + chdir '/' or die "chdir failed: $!"; + } return unless (defined $pid_file || defined $group || defined $user || $daemonize); @@ -179,10 +182,11 @@ sub worker_quit { Danga::Socket->SetPostLoopCallback(sub { my ($dmap, undef) = @_; my $n = 0; + my $now = clock_gettime(CLOCK_MONOTONIC); foreach my $s (values %$dmap) { $s->can('busy') or next; - if ($s->busy) { + if ($s->busy($now)) { ++$n; } else { # close as much as possible, early as possible