2013-04-17 00:19:26 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Getopt::Std qw(getopts);
|
|
|
|
use Cwd qw/cwd/;
|
|
|
|
|
|
|
|
sub sh ($);
|
2015-03-01 05:14:50 +00:00
|
|
|
sub write_config_file ($);
|
2013-04-17 00:19:26 +00:00
|
|
|
|
|
|
|
my %opts;
|
2014-05-17 21:19:01 +00:00
|
|
|
getopts("lf:", \%opts) or die "Usage: $0 [-f] [-l] <cores>\n";
|
2013-04-17 00:19:26 +00:00
|
|
|
|
|
|
|
my $jobs = shift || 4;
|
|
|
|
|
|
|
|
my $cwd = cwd();
|
2014-08-20 21:44:22 +00:00
|
|
|
if ($cwd !~ /ngx_openresty-(\d+(?:\.\d+)+(?:rc\d+(?:\.\d+)?)?)$/) {
|
2013-04-17 00:19:26 +00:00
|
|
|
die "Bad current working directory: $cwd\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
my $ver = $1;
|
|
|
|
|
2013-04-17 19:08:54 +00:00
|
|
|
my ($make, $lua);
|
2013-04-17 00:19:26 +00:00
|
|
|
|
|
|
|
if ($^O eq 'freebsd' || $^O eq 'solaris') {
|
|
|
|
$make = 'gmake';
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$make = 'make';
|
|
|
|
}
|
|
|
|
|
2015-06-23 14:33:01 +00:00
|
|
|
my $cfg_opts = "";
|
2013-04-17 19:08:54 +00:00
|
|
|
|
|
|
|
if ($opts{l}) {
|
|
|
|
$lua = 'Lua';
|
2014-01-10 06:02:49 +00:00
|
|
|
$cfg_opts .= " --with-lua51";
|
2013-04-17 19:08:54 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
$lua = 'LuaJIT';
|
2014-01-10 06:02:49 +00:00
|
|
|
#$cfg_opts .= " --with-luajit";
|
2013-04-17 19:08:54 +00:00
|
|
|
}
|
|
|
|
|
2013-11-13 04:43:55 +00:00
|
|
|
if ($^O eq 'solaris') {
|
|
|
|
$cfg_opts .= " --with-cc=gcc";
|
|
|
|
}
|
|
|
|
|
2015-03-01 05:14:50 +00:00
|
|
|
if ($^O eq 'darwin') {
|
|
|
|
$cfg_opts .= " --with-cc-opt='-I/usr/local/include'"
|
|
|
|
. " --with-ld-opt='-L/usr/local/lib'";
|
|
|
|
}
|
|
|
|
|
2013-04-17 00:19:26 +00:00
|
|
|
my $prefix;
|
|
|
|
|
2015-03-01 05:14:50 +00:00
|
|
|
my $config = do { local $/; <DATA> };
|
|
|
|
|
|
|
|
sub write_config_file ($) {
|
|
|
|
my $outfile = shift;
|
|
|
|
warn "Writing file $outfile\n";
|
|
|
|
open my $out, ">$outfile" or
|
|
|
|
die "Cannot open $outfile for writing: $!\n";
|
|
|
|
print $out $config;
|
|
|
|
close $out;
|
|
|
|
}
|
|
|
|
|
|
|
|
write_config_file "/tmp/nginx.conf";
|
|
|
|
|
2015-06-23 14:33:01 +00:00
|
|
|
warn "=== Without Gzip/SSL/PCRE ===\n";
|
2015-01-29 22:56:02 +00:00
|
|
|
$prefix = "/usr/local/openresty-nogzip";
|
|
|
|
unless ($opts{f}) {
|
2015-06-23 14:33:01 +00:00
|
|
|
sh "./configure $cfg_opts --without-http_rewrite_module --without-http_ssl_module --without-pcre --without-http_gzip_module --prefix=$prefix -j$jobs > /dev/null";
|
2015-01-29 22:56:02 +00:00
|
|
|
}
|
|
|
|
sh "$make -j$jobs > /dev/null";
|
|
|
|
sh "sudo $make install > /dev/null";
|
2015-03-01 05:14:50 +00:00
|
|
|
sh "sudo cp /tmp/nginx.conf $prefix/nginx/conf/nginx.conf";
|
2015-01-29 22:56:02 +00:00
|
|
|
sh "$prefix/nginx/sbin/nginx -V 2>&1 |grep $ver";
|
|
|
|
sh "$prefix/nginx/sbin/nginx -V 2>&1 |grep '\\--without-http_gzip_module'";
|
2015-06-23 14:33:01 +00:00
|
|
|
sh "$prefix/nginx/sbin/nginx -V 2>&1 |grep -v -q '\\--with-http_ssl_module'";
|
|
|
|
sh "$prefix/nginx/sbin/nginx -V 2>&1 |grep '\\--without-pcre'";
|
2015-01-29 22:56:02 +00:00
|
|
|
system "sudo killall nginx > /dev/null 2>&1";
|
|
|
|
sh "sudo $prefix/nginx/sbin/nginx";
|
|
|
|
sh "curl -si localhost/lua|grep $lua";
|
|
|
|
sh "curl -si localhost/lua|grep $ver";
|
|
|
|
sh "curl -si localhost/cjson|grep 'json.safe: '";
|
|
|
|
sh qq{$prefix/bin/resty -e 'ngx.say("Hello World!")'|grep 'Hello World'};
|
|
|
|
sh "sudo $prefix/nginx/sbin/nginx -sstop";
|
|
|
|
|
2015-06-23 14:33:01 +00:00
|
|
|
$cfg_opts .= " --with-http_iconv_module";
|
|
|
|
|
2015-01-29 22:56:02 +00:00
|
|
|
warn "\n=== No Pool Build ===\n";
|
2013-06-11 23:51:26 +00:00
|
|
|
$prefix = "/usr/local/openresty-nopool";
|
|
|
|
unless ($opts{f}) {
|
|
|
|
sh "./configure --with-no-pool-patch $cfg_opts --prefix=$prefix -j$jobs > /dev/null";
|
|
|
|
}
|
|
|
|
sh "$make -j$jobs > /dev/null";
|
|
|
|
sh "sudo $make install > /dev/null";
|
2015-03-01 05:14:50 +00:00
|
|
|
sh "sudo cp /tmp/nginx.conf $prefix/nginx/conf/nginx.conf";
|
2013-06-11 23:51:26 +00:00
|
|
|
sh "$prefix/nginx/sbin/nginx -V 2>&1 |grep $ver";
|
|
|
|
#sh "$prefix/nginx/sbin/nginx -V 2>&1 |grep '\\--with-no-pool-patch'";
|
|
|
|
system "sudo killall nginx > /dev/null 2>&1";
|
|
|
|
sh "sudo $prefix/nginx/sbin/nginx";
|
|
|
|
sh "curl -si localhost/lua|grep $lua";
|
|
|
|
sh "curl -si localhost/lua|grep $ver";
|
|
|
|
sh "curl -si localhost/lua|grep 'no pool'";
|
2014-03-01 05:22:33 +00:00
|
|
|
sh "curl -si localhost/cjson|grep 'json.safe: '";
|
2015-01-21 22:53:26 +00:00
|
|
|
sh qq{$prefix/bin/resty -e 'ngx.say("Hello World!")'|grep 'Hello World'};
|
2013-06-11 23:51:26 +00:00
|
|
|
sh "sudo $prefix/nginx/sbin/nginx -sstop";
|
|
|
|
|
|
|
|
warn "\n=== Normal Build ===\n";
|
2013-04-17 00:19:26 +00:00
|
|
|
$prefix = "/usr/local/openresty";
|
|
|
|
unless ($opts{f}) {
|
2013-04-17 19:08:54 +00:00
|
|
|
sh "./configure $cfg_opts -j$jobs > /dev/null";
|
2013-04-17 00:19:26 +00:00
|
|
|
}
|
|
|
|
sh "$make -j$jobs > /dev/null";
|
|
|
|
sh "sudo $make install > /dev/null";
|
2015-03-01 05:14:50 +00:00
|
|
|
sh "sudo cp /tmp/nginx.conf $prefix/nginx/conf/nginx.conf";
|
2013-04-17 00:19:26 +00:00
|
|
|
sh "$prefix/nginx/sbin/nginx -V 2>&1 |grep $ver";
|
2013-04-17 00:24:10 +00:00
|
|
|
system "sudo killall nginx > /dev/null 2>&1";
|
2013-04-17 00:19:26 +00:00
|
|
|
sh "sudo $prefix/nginx/sbin/nginx";
|
2013-04-17 19:08:54 +00:00
|
|
|
sh "curl -si localhost/lua|grep $lua";
|
2013-04-17 00:19:26 +00:00
|
|
|
sh "curl -si localhost/lua|grep $ver";
|
2014-03-01 05:22:33 +00:00
|
|
|
sh "curl -si localhost/cjson|grep 'json.safe: '";
|
2015-01-21 22:53:26 +00:00
|
|
|
sh qq{$prefix/bin/resty -e 'ngx.say("Hello World!")'|grep 'Hello World'};
|
2013-04-17 00:19:26 +00:00
|
|
|
sh "sudo $prefix/nginx/sbin/nginx -sstop";
|
|
|
|
|
|
|
|
warn "\n=== Debug Build ===\n";
|
|
|
|
$prefix = "/usr/local/openresty-debug";
|
|
|
|
unless ($opts{f}) {
|
2014-05-17 21:19:01 +00:00
|
|
|
my $more_cfg_opts = '';
|
|
|
|
if ($lua eq 'LuaJIT') {
|
|
|
|
$more_cfg_opts .= " --with-luajit-xcflags='-DLUA_USE_TRACE_LOGS'"
|
|
|
|
}
|
|
|
|
sh "./configure --with-debug $cfg_opts $more_cfg_opts --prefix=$prefix -j$jobs > /dev/null";
|
2013-04-17 00:19:26 +00:00
|
|
|
}
|
|
|
|
sh "$make -j$jobs > /dev/null";
|
|
|
|
sh "sudo $make install > /dev/null";
|
2015-03-01 05:14:50 +00:00
|
|
|
sh "sudo cp /tmp/nginx.conf $prefix/nginx/conf/nginx.conf";
|
2013-04-17 00:19:26 +00:00
|
|
|
sh "$prefix/nginx/sbin/nginx -V 2>&1 |grep $ver";
|
|
|
|
sh "$prefix/nginx/sbin/nginx -V 2>&1 |grep '\\--with-debug'";
|
2013-04-17 00:24:10 +00:00
|
|
|
system "sudo killall nginx > /dev/null 2>&1";
|
2013-04-17 00:19:26 +00:00
|
|
|
sh "sudo $prefix/nginx/sbin/nginx";
|
2013-04-17 19:08:54 +00:00
|
|
|
sh "curl -si localhost/lua|grep $lua";
|
2013-04-17 00:19:26 +00:00
|
|
|
sh "curl -si localhost/lua|grep $ver";
|
2014-03-01 05:22:33 +00:00
|
|
|
sh "curl -si localhost/cjson|grep 'json.safe: '";
|
2015-01-21 22:53:26 +00:00
|
|
|
sh qq{$prefix/bin/resty -e 'ngx.say("Hello World!")'|grep 'Hello World'};
|
2013-04-17 00:19:26 +00:00
|
|
|
sh "sudo $prefix/nginx/sbin/nginx -sstop";
|
|
|
|
|
|
|
|
warn "\n=== DTrace Build ===\n";
|
|
|
|
$prefix = "/usr/local/openresty-dtrace";
|
|
|
|
unless ($opts{f}) {
|
2013-04-17 19:08:54 +00:00
|
|
|
sh "./configure $cfg_opts --with-dtrace-probes --prefix=$prefix -j$jobs > /dev/null";
|
2013-04-17 00:19:26 +00:00
|
|
|
}
|
|
|
|
sh "$make -j$jobs > /dev/null";
|
|
|
|
sh "sudo $make install > /dev/null";
|
2015-03-01 05:14:50 +00:00
|
|
|
sh "sudo cp /tmp/nginx.conf $prefix/nginx/conf/nginx.conf";
|
2013-04-17 00:19:26 +00:00
|
|
|
sh "$prefix/nginx/sbin/nginx -V 2>&1 |grep $ver";
|
|
|
|
sh "$prefix/nginx/sbin/nginx -V 2>&1 |grep '\\--with-dtrace-probes'";
|
2013-04-17 00:24:10 +00:00
|
|
|
system "sudo killall nginx > /dev/null 2>&1";
|
2013-04-17 00:19:26 +00:00
|
|
|
sh "sudo $prefix/nginx/sbin/nginx";
|
2013-04-17 19:08:54 +00:00
|
|
|
sh "curl -si localhost/lua|grep $lua";
|
2013-04-17 00:19:26 +00:00
|
|
|
sh "curl -si localhost/lua|grep $ver";
|
2014-03-01 05:22:33 +00:00
|
|
|
sh "curl -si localhost/cjson|grep 'json.safe: '";
|
2013-04-17 00:19:26 +00:00
|
|
|
if ($^O eq 'linux') {
|
|
|
|
sh "stap -L 'process(\"$prefix/nginx/sbin/nginx\").mark(\"*\")'|grep http__lua__coroutine__done";
|
|
|
|
|
2013-04-18 06:06:29 +00:00
|
|
|
} elsif ($^O eq 'freebsd' || $^O eq 'darwin' || $^O eq 'solaris') {
|
2013-04-17 00:19:26 +00:00
|
|
|
sh "sudo dtrace -l|grep http-lua-coroutine-done";
|
|
|
|
}
|
2015-01-21 22:53:26 +00:00
|
|
|
sh qq{$prefix/bin/resty -e 'ngx.say("Hello World!")'|grep 'Hello World'};
|
2013-04-17 00:19:26 +00:00
|
|
|
|
|
|
|
sh "sudo $prefix/nginx/sbin/nginx -sstop";
|
|
|
|
|
|
|
|
sub sh ($) {
|
|
|
|
my $cmd = shift;
|
|
|
|
system($cmd) == 0 or die "Command \"$cmd\" failed";
|
|
|
|
}
|
2015-03-01 05:14:50 +00:00
|
|
|
|
|
|
|
__DATA__
|
|
|
|
|
|
|
|
user nobody;
|
|
|
|
worker_processes 1;
|
|
|
|
error_log logs/error.log;
|
|
|
|
pid logs/nginx.pid;
|
|
|
|
|
|
|
|
events {
|
|
|
|
accept_mutex off;
|
|
|
|
worker_connections 256;
|
|
|
|
}
|
|
|
|
|
|
|
|
http {
|
|
|
|
include mime.types;
|
|
|
|
default_type application/octet-stream;
|
|
|
|
|
|
|
|
init_by_lua '
|
|
|
|
if jit then
|
|
|
|
require "resty.core"
|
|
|
|
end
|
|
|
|
';
|
|
|
|
|
|
|
|
server {
|
|
|
|
listen *:80;
|
|
|
|
server_name localhost;
|
|
|
|
|
|
|
|
location = /lua {
|
|
|
|
content_by_lua '
|
|
|
|
local upstream = require "ngx.upstream"
|
|
|
|
if jit then
|
|
|
|
ngx.say(jit.version)
|
|
|
|
else
|
|
|
|
ngx.say(_VERSION)
|
|
|
|
end
|
|
|
|
';
|
|
|
|
}
|
|
|
|
|
|
|
|
location = /cjson {
|
|
|
|
content_by_lua '
|
|
|
|
local json = require "cjson.safe"
|
|
|
|
ngx.say("cjson.safe: ", json.encode{foo = 123})
|
|
|
|
';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|