passenger: provide dynamic nginx module.

Closes #36754.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
Camden Narzt 2019-02-05 12:35:42 -07:00 committed by Mike McQuaid
parent b080409d00
commit 54d05f3244
No known key found for this signature in database
GPG key ID: 48A898132FD8EE70

View file

@ -12,9 +12,16 @@ class Passenger < Formula
sha256 "d094cecf62e66a527482b681bdfa01cc7fa956a16ad9e4d2fea520ffc63cac6f" => :sierra
end
# to build nginx module
depends_on "nginx" => [:build, :test]
depends_on "openssl"
depends_on "pcre"
patch do
url "https://github.com/phusion/passenger/commit/20ca9e52.patch?full_index=1"
sha256 "e18966542571ce906b6fd9bdb7959418fba20da3669a2c7442a17f4e53179892"
end
def install
# https://github.com/Homebrew/homebrew-core/pull/1046
ENV.delete("SDKROOT")
@ -26,6 +33,20 @@ class Passenger < Formula
system "rake", "apache2"
system "rake", "nginx"
nginx_addon_dir = `./bin/passenger-config about nginx-addon-dir`.strip
mkdir "nginx" do
system "tar", "-xf", "#{Formula["nginx"].opt_share}/src/src.tar.xz", "--strip-components", "1"
args = (Formula["nginx"].opt_share/"src/configure_args.txt").read.split("\n")
args << "--add-dynamic-module=#{nginx_addon_dir}"
system "./configure", *args
system "make"
(libexec/"buildout/nginx_dynamic/").mkpath
cp "objs/ngx_http_passenger_module.so", libexec/"buildout/nginx_dynamic/"
end
(libexec/"download_cache").mkpath
@ -36,9 +57,9 @@ class Passenger < Formula
necessary_files = %w[configure Rakefile README.md CONTRIBUTORS
CONTRIBUTING.md LICENSE CHANGELOG package.json
passenger.gemspec build bin doc images man dev src
passenger.gemspec build bin doc images dev src
resources buildout]
libexec.mkpath
cp_r necessary_files, libexec, :preserve => true
# Allow Homebrew to create symlinks for the Phusion Passenger commands.
@ -47,29 +68,34 @@ class Passenger < Formula
# Ensure that the Phusion Passenger commands can always find their library
# files.
locations_ini = `/usr/bin/ruby ./bin/passenger-config --make-locations-ini --for-native-packaging-method=homebrew`
locations_ini = `./bin/passenger-config --make-locations-ini --for-native-packaging-method=homebrew`
locations_ini.gsub!(/=#{Regexp.escape Dir.pwd}/, "=#{libexec}")
(libexec/"src/ruby_supportlib/phusion_passenger/locations.ini").write(locations_ini)
ruby_libdir = `/usr/bin/ruby ./bin/passenger-config about ruby-libdir`.strip
ruby_libdir = `./bin/passenger-config about ruby-libdir`.strip
ruby_libdir.gsub!(/^#{Regexp.escape Dir.pwd}/, libexec)
system "/usr/bin/ruby", "./dev/install_scripts_bootstrap_code.rb",
system "./dev/install_scripts_bootstrap_code.rb",
"--ruby", ruby_libdir, *Dir[libexec/"bin/*"]
system("/usr/bin/ruby ./bin/passenger-config compile-nginx-engine")
system "./bin/passenger-config", "compile-nginx-engine"
cp Dir["buildout/support-binaries/nginx*"], libexec/"buildout/support-binaries", :preserve => true
nginx_addon_dir = `/usr/bin/ruby ./bin/passenger-config about nginx-addon-dir`.strip
nginx_addon_dir.gsub!(/^#{Regexp.escape Dir.pwd}/, libexec)
system "/usr/bin/ruby", "./dev/install_scripts_bootstrap_code.rb",
system "./dev/install_scripts_bootstrap_code.rb",
"--nginx-module-config", libexec/"bin", "#{nginx_addon_dir}/config"
mv libexec/"man", share
man1.install Dir["man/*.1"]
man8.install Dir["man/*.8"]
end
def caveats; <<~EOS
To activate Phusion Passenger for Nginx, run:
brew install nginx --with-passenger
brew install nginx
And add the following to #{etc}/nginx/nginx.conf at the top scope (outside http{}):
load_module #{opt_libexec}/buildout/nginx_dynamic/ngx_http_passenger_module.so;
And add the following to #{etc}/nginx/nginx.conf in the http scope:
passenger_root #{opt_libexec}/src/ruby_supportlib/phusion_passenger/locations.ini;
passenger_ruby /usr/bin/ruby;
To activate Phusion Passenger for Apache, create /etc/apache2/other/passenger.conf:
LoadModule passenger_module #{opt_libexec}/buildout/apache2/mod_passenger.so
@ -81,5 +107,35 @@ class Passenger < Formula
test do
ruby_libdir = `#{HOMEBREW_PREFIX}/bin/passenger-config --ruby-libdir`.strip
assert_equal "#{libexec}/src/ruby_supportlib", ruby_libdir
(testpath/"nginx.conf").write <<~EOS
load_module #{opt_libexec}/buildout/nginx_dynamic/ngx_http_passenger_module.so;
worker_processes 4;
error_log #{testpath}/error.log;
pid #{testpath}/nginx.pid;
events {
worker_connections 1024;
}
http {
passenger_root #{opt_libexec}/src/ruby_supportlib/phusion_passenger/locations.ini;
passenger_ruby /usr/bin/ruby;
client_body_temp_path #{testpath}/client_body_temp;
fastcgi_temp_path #{testpath}/fastcgi_temp;
proxy_temp_path #{testpath}/proxy_temp;
scgi_temp_path #{testpath}/scgi_temp;
uwsgi_temp_path #{testpath}/uwsgi_temp;
server {
passenger_enabled on;
listen 8080;
root #{testpath};
access_log #{testpath}/access.log;
error_log #{testpath}/error.log;
}
}
EOS
system "#{Formula["nginx"].opt_bin}/nginx", "-t", "-c", testpath/"nginx.conf"
end
end