| 1 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # Handle compile-time options before loading any modules | ||||||||||||||||||||||||||||
| 4 | # Future::XS must be loaded before Future, so check early | ||||||||||||||||||||||||||||
| 5 | 9 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=5 SCAR=19.2
| |||||||||||||||||||||||||||||
| 6 | 9 | my @to_splice; | |||||||||||||||||||||||||||
| 7 | 9 | for my $i (0 .. $#ARGV) { | |||||||||||||||||||||||||||
| 8 | 45 | ▶ | if ($ARGV[$i] eq '--future-xs') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 9 | 0 | $ENV{PAGI_FUTURE_XS} = 1; | |||||||||||||||||||||||||||
| 10 | 0 | push @to_splice, $i; | |||||||||||||||||||||||||||
| 11 | } | ||||||||||||||||||||||||||||
| 12 | } | ||||||||||||||||||||||||||||
| 13 | # Remove processed flags in reverse order to preserve indices | ||||||||||||||||||||||||||||
| 14 | 9 | for my $i (reverse @to_splice) { | |||||||||||||||||||||||||||
| 15 | 0 | splice @ARGV, $i, 1; | |||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # Capture original args for hot restart re-exec (USR2) | ||||||||||||||||||||||||||||
| 19 | 9 | ▶ | $ENV{PAGI_ARGV} = join("\0", @ARGV) unless exists $ENV{PAGI_ARGV}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 9 | ▶ | use Getopt::Long qw(GetOptionsFromArray :config pass_through no_auto_abbrev); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 9 | ▶ | use PAGI::Server::Runner; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | # Parse PAGI::Server-specific options before passing to Runner | ||||||||||||||||||||||||||||
| 29 | # This keeps Runner server-agnostic | ||||||||||||||||||||||||||||
| 30 | 9 | my %server_opts; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | GetOptionsFromArray( | ||||||||||||||||||||||||||||
| 33 | \@ARGV, | ||||||||||||||||||||||||||||
| 34 | # Network (Unix socket / multi-listener) | ||||||||||||||||||||||||||||
| 35 | 'socket=s' => \$server_opts{socket}, | ||||||||||||||||||||||||||||
| 36 | 'socket-mode=s' => \$server_opts{_socket_mode}, | ||||||||||||||||||||||||||||
| 37 | 'listen=s@' => \$server_opts{_listen}, | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | # Workers/scaling | ||||||||||||||||||||||||||||
| 40 | 'w|workers=i' => \$server_opts{workers}, | ||||||||||||||||||||||||||||
| 41 | 'reuseport' => \$server_opts{reuseport}, | ||||||||||||||||||||||||||||
| 42 | 'max-requests=i' => \$server_opts{max_requests}, | ||||||||||||||||||||||||||||
| 43 | 'max-connections=i' => \$server_opts{max_connections}, | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | # TLS | ||||||||||||||||||||||||||||
| 46 | 'ssl-cert=s' => \$server_opts{_ssl_cert}, | ||||||||||||||||||||||||||||
| 47 | 'ssl-key=s' => \$server_opts{_ssl_key}, | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | # Timeouts | ||||||||||||||||||||||||||||
| 50 | 'timeout=i' => \$server_opts{timeout}, | ||||||||||||||||||||||||||||
| 51 | 'shutdown-timeout=i' => \$server_opts{shutdown_timeout}, | ||||||||||||||||||||||||||||
| 52 | 'request-timeout=i' => \$server_opts{request_timeout}, | ||||||||||||||||||||||||||||
| 53 | 'ws-idle-timeout=i' => \$server_opts{ws_idle_timeout}, | ||||||||||||||||||||||||||||
| 54 | 'sse-idle-timeout=i' => \$server_opts{sse_idle_timeout}, | ||||||||||||||||||||||||||||
| 55 | 'heartbeat-timeout=i' => \$server_opts{heartbeat_timeout}, | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # Lifespan | ||||||||||||||||||||||||||||
| 58 | 'lifespan=s' => \$server_opts{lifespan_mode}, | ||||||||||||||||||||||||||||
| 59 | 'lifespan-startup-timeout=i' => \$server_opts{lifespan_startup_timeout}, | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | # Limits | ||||||||||||||||||||||||||||
| 62 | 'max-body-size=i' => \$server_opts{max_body_size}, | ||||||||||||||||||||||||||||
| 63 | 'max-header-size=i' => \$server_opts{max_header_size}, | ||||||||||||||||||||||||||||
| 64 | 'max-header-count=i' => \$server_opts{max_header_count}, | ||||||||||||||||||||||||||||
| 65 | 'max-receive-queue=i' => \$server_opts{max_receive_queue}, | ||||||||||||||||||||||||||||
| 66 | 'max-ws-frame-size=i' => \$server_opts{max_ws_frame_size}, | ||||||||||||||||||||||||||||
| 67 | 'b|listener-backlog=i' => \$server_opts{listener_backlog}, | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | # Write backpressure watermarks | ||||||||||||||||||||||||||||
| 70 | 'write-high-watermark=i' => \$server_opts{write_high_watermark}, | ||||||||||||||||||||||||||||
| 71 | 'write-low-watermark=i' => \$server_opts{write_low_watermark}, | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # Misc | ||||||||||||||||||||||||||||
| 74 | 'http2' => \$server_opts{http2}, | ||||||||||||||||||||||||||||
| 75 | 'log-level=s' => \$server_opts{log_level}, | ||||||||||||||||||||||||||||
| 76 | 'sync-file-threshold=i' => \$server_opts{sync_file_threshold}, | ||||||||||||||||||||||||||||
| 77 | 'access-log-format=s' => \$server_opts{access_log_format}, | ||||||||||||||||||||||||||||
| 78 | 9 | ); | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | # Build ssl hash if certs provided | ||||||||||||||||||||||||||||
| 81 | 9 | ▶ | if ($server_opts{_ssl_cert} || $server_opts{_ssl_key}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$server_opts{"_ssl_cert"} or $server_opts{"_ssl_key"}
MC/DC0%0/2
$server_opts{"_ssl_cert"} or $server_opts{"_ssl_key"}
$server_opts{"_ssl_cert"}
$server_opts{"_ssl_key"}
Truth table33%1/3
A or B
A= $server_opts{"_ssl_cert"}B= $server_opts{"_ssl_key"}
| |||||||||||||||||||||||||||||
| 82 | die "--ssl-cert and --ssl-key must be specified together\n" | ||||||||||||||||||||||||||||
| 83 | 0 | ▶ | unless $server_opts{_ssl_cert} && $server_opts{_ssl_key}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$server_opts{"_ssl_cert"} and $server_opts{"_ssl_key"}
MC/DC0%0/2
$server_opts{"_ssl_cert"} and $server_opts{"_ssl_key"}
$server_opts{"_ssl_cert"}
$server_opts{"_ssl_key"}
Truth table0%0/3
A and B
A= $server_opts{"_ssl_cert"}B= $server_opts{"_ssl_key"}
| |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | die "SSL cert not found: $server_opts{_ssl_cert}\n" | ||||||||||||||||||||||||||||
| 86 | 0 | ▶ | unless -f $server_opts{_ssl_cert}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | die "SSL key not found: $server_opts{_ssl_key}\n" | ||||||||||||||||||||||||||||
| 88 | 0 | ▶ | unless -f $server_opts{_ssl_key}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | $server_opts{ssl} = { | ||||||||||||||||||||||||||||
| 91 | cert_file => delete $server_opts{_ssl_cert}, | ||||||||||||||||||||||||||||
| 92 | key_file => delete $server_opts{_ssl_key}, | ||||||||||||||||||||||||||||
| 93 | 0 | }; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | 9 | delete $server_opts{_ssl_cert}; | |||||||||||||||||||||||||||
| 96 | 9 | delete $server_opts{_ssl_key}; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | # Handle --socket-mode (octal string to numeric) | ||||||||||||||||||||||||||||
| 99 | 9 | ▶ | if (defined $server_opts{_socket_mode}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 0 | my $mode_str = $server_opts{_socket_mode}; | |||||||||||||||||||||||||||
| 101 | 0 | ▶ | die "--socket-mode must be an octal value like 0660, got: $mode_str\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | unless $mode_str =~ /^0[0-7]{3}$/; | ||||||||||||||||||||||||||||
| 103 | 0 | $server_opts{socket_mode} = oct($mode_str); | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | 9 | delete $server_opts{_socket_mode}; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | # Handle --listen (build listen array from repeated --listen flags) | ||||||||||||||||||||||||||||
| 108 | # Detection: contains ':' -> TCP host:port, otherwise -> Unix socket path | ||||||||||||||||||||||||||||
| 109 | 9 | ▶ | if (my $listen_specs = delete $server_opts{_listen}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 0 | my @listeners; | |||||||||||||||||||||||||||
| 111 | 0 | for my $spec (@$listen_specs) { | |||||||||||||||||||||||||||
| 112 | 0 | ▶ | if ($spec =~ m{^[./]}) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 113 | # Starts with / or . — always a Unix socket path | ||||||||||||||||||||||||||||
| 114 | # (even if it contains colons, e.g. /var/run/app:8080) | ||||||||||||||||||||||||||||
| 115 | 0 | my %entry = (socket => $spec); | |||||||||||||||||||||||||||
| 116 | $entry{socket_mode} = $server_opts{socket_mode} | ||||||||||||||||||||||||||||
| 117 | 0 | ▶ | if defined $server_opts{socket_mode}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | 0 | push @listeners, \%entry; | |||||||||||||||||||||||||||
| 119 | } elsif ($spec =~ /^\[([^\]]+)\]:(\d+)$/) { | ||||||||||||||||||||||||||||
| 120 | # IPv6: [::1]:5000 | ||||||||||||||||||||||||||||
| 121 | 0 | push @listeners, { host => $1, port => int($2) }; | |||||||||||||||||||||||||||
| 122 | } elsif ($spec =~ /^(.+):(\d+)$/) { | ||||||||||||||||||||||||||||
| 123 | # IPv4/hostname: 127.0.0.1:5000 | ||||||||||||||||||||||||||||
| 124 | 0 | push @listeners, { host => $1, port => int($2) }; | |||||||||||||||||||||||||||
| 125 | } else { | ||||||||||||||||||||||||||||
| 126 | # Bare name without / or . prefix — treat as Unix socket | ||||||||||||||||||||||||||||
| 127 | 0 | my %entry = (socket => $spec); | |||||||||||||||||||||||||||
| 128 | $entry{socket_mode} = $server_opts{socket_mode} | ||||||||||||||||||||||||||||
| 129 | 0 | ▶ | if defined $server_opts{socket_mode}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 0 | push @listeners, \%entry; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | 0 | $server_opts{listen} = \@listeners; | |||||||||||||||||||||||||||
| 134 | 0 | delete $server_opts{socket_mode}; # Applied per-listener above | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | # Handle workers (0 for single-process, >1 for multi-worker) | ||||||||||||||||||||||||||||
| 138 | 9 | ▶ | if (defined $server_opts{workers}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | 3 | ▶ | $server_opts{workers} = $server_opts{workers} > 1 ? $server_opts{workers} : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | # Remove undefined options | ||||||||||||||||||||||||||||
| 143 | 9 | %server_opts = map { $_ => $server_opts{$_} } grep { defined $server_opts{$_} } keys %server_opts; | |||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | # Pass server options to Runner | ||||||||||||||||||||||||||||
| 146 | 9 | PAGI::Server::Runner->run(@ARGV, server_options => \%server_opts); | |||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | __END__ | ||||||||||||||||||||||||||||