-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_nginx
executable file
·68 lines (52 loc) · 1.88 KB
/
build_nginx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
# Builds NGINX.
# This script is designed to run in a Heroku Stack Docker
# image. More information on the Heroku Stack can be found
# at https://devcenter.heroku.com/articles/stack
set -e
out_dir=$1
download_dir=/tmp/nginx-download
release_dir=/tmp/nginx-release
NGINX_VERSION=${NGINX_VERSION-1.26.1}
nginx_tarball_url=https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz
rm -rf /tmp/nginx*
mkdir ${download_dir} ${release_dir}
cd ${download_dir}
echo "Downloading $nginx_tarball_url to ${download_dir}"
curl -L $nginx_tarball_url | tar xzv
cd nginx-${NGINX_VERSION}
# Heroku expects SIGTERM to shutdown the application gracefully and
# SIGQUIT to force the shutdown, nginx implements the opposite
# behavior.
echo "Patching nginx to switch SIGTERM and SIGQUIT handlers"
signal_defines_file="src/core/ngx_config.h"
sed -i 's/#define\s\+NGX_TERMINATE_SIGNAL\s\+TERM/#define NGX_TERMINATE_SIGNAL QUIT \/\/remapped for Heroku/' \
${signal_defines_file}
sed -i 's/#define\s\+NGX_SHUTDOWN_SIGNAL\s\+QUIT/#define NGX_SHUTDOWN_SIGNAL TERM \/\/remapped for Heroku/' \
${signal_defines_file}
lines_patched=`grep 'remapped for Heroku' ${signal_defines_file}|wc -l|cut -f1 -d ' '`
if (( ${lines_patched} != 2 )); then
echo "Failed to patch '${signal_defines_file}'"
exit 1
fi
# build `nginx`
./configure \
--with-cc-opt="-O2" \
--with-http_auth_request_module \
--with-http_ssl_module \
--with-http_sub_module \
--prefix=/tmp/nginx
make install
# build `nginx-debug`
./configure \
--with-debug \
--with-http_auth_request_module \
--with-http_ssl_module \
--with-http_sub_module \
--prefix=/tmp/nginx-debug
make install
cp /tmp/nginx/sbin/nginx $release_dir/nginx
cp /tmp/nginx-debug/sbin/nginx $release_dir/nginx-debug
cp /tmp/nginx/conf/mime.types $release_dir/mime.types
tar -zcvf /tmp/nginx-"${STACK}".tgz -C $release_dir .
cp /tmp/nginx-"${STACK}".tgz ${out_dir}