use PublicInbox::DS qw(now);
use PublicInbox::Syscall qw($SFD_NONBLOCK);
require PublicInbox::Listener;
-require PublicInbox::ParentPipe;
+use PublicInbox::EOFpipe;
use PublicInbox::Sigfd;
+use PublicInbox::GitAsyncCat;
my @CMD;
my ($set_user, $oldset);
my (@cfg_listen, $stdout, $stderr, $group, $user, $pid_file, $daemonize);
sub daemon_prepare ($) {
my ($default_listen) = @_;
my $listener_names = {}; # sockname => IO::Handle
- my $oldset = PublicInbox::Sigfd::block_signals();
+ $oldset = PublicInbox::Sigfd::block_signals();
@CMD = ($0, @ARGV);
- my %opts = (
+ my ($prog) = ($CMD[0] =~ m!([^/]+)\z!g);
+ my $help = <<EOF;
+usage: $prog [-l ADDRESS] [--cert=FILE] [--key=FILE]
+
+options:
+
+ -l ADDRESS address to listen on (default: $default_listen)
+ --cert=FILE default SSL/TLS certificate
+ --key=FILE default SSL/TLS certificate
+ -W WORKERS number of worker processes to spawn (default: 1)
+
+See public-inbox-daemon(8) and $prog(1) man pages for more.
+EOF
+ my %opt = (
'l|listen=s' => \@cfg_listen,
'1|stdout=s' => \$stdout,
'2|stderr=s' => \$stderr,
'D|daemonize' => \$daemonize,
'cert=s' => \$default_cert,
'key=s' => \$default_key,
+ 'help|h' => \(my $show_help),
);
- GetOptions(%opts) or die "bad command-line args\n";
+ GetOptions(%opt) or die $help;
+ if ($show_help) { print $help; exit 0 };
if (defined $pid_file && $pid_file =~ /\.oldbin\z/) {
die "--pid-file cannot end with '.oldbin'\n";
sub master_loop {
pipe(my ($p0, $p1)) or die "failed to create parent-pipe: $!";
- # 1031: F_SETPIPE_SZ, 4096: page size
- fcntl($p1, 1031, 4096) if $^O eq 'linux';
my $set_workers = $worker_processes;
reopen_logs();
my $ignore_winch;
};
my $sigfd = PublicInbox::Sigfd->new($sig, 0);
local %SIG = (%SIG, %$sig) if !$sigfd;
- PublicInbox::restore_signals($oldset) if !$sigfd;
+ PublicInbox::Sigfd::sig_setmask($oldset) if !$sigfd;
while (1) { # main loop
my $n = scalar keys %pids;
unless (@listeners) {
$pids{$pid} = $i;
}
}
- PubliInbox::Sigfd::set_sigmask($oldset) if !$sigfd;
+ PublicInbox::Sigfd::sig_setmask($oldset) if !$sigfd;
}
if ($sigfd) { # Linux and IO::KQueue users:
if ($worker_processes > 0) {
$refresh->(); # preload by default
my $fh = master_loop(); # returns if in child process
- PublicInbox::ParentPipe->new($fh, \&worker_quit);
+ PublicInbox::EOFpipe->new($fh, \&worker_quit, undef);
} else {
reopen_logs();
$set_user->() if $set_user;
if (!$sigfd) {
# wake up every second to accept signals if we don't
# have signalfd or IO::KQueue:
- PublicInbox::Sigfd::set_sigmask($oldset);
+ PublicInbox::Sigfd::sig_setmask($oldset);
PublicInbox::DS->SetLoopTimeout(1000);
}
PublicInbox::DS->EventLoop;
daemon_prepare($default);
my $af_default = $default =~ /:8080\z/ ? 'httpready' : undef;
my $for_destroy = daemonize();
+
+ # localize GCF2C for tests:
+ local $PublicInbox::GitAsyncCat::GCF2C;
+
daemon_loop($refresh, $post_accept, $tlsd, $af_default);
PublicInbox::DS->Reset;
# ->DESTROY runs when $for_destroy goes out-of-scope