Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch nginx so it does graceful shutdown on SIGTERM and fast shutdown… #88

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bin/start-nginx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

trap "echo start-nginx got SIGTERM. Ignoring while nginx shuts down gracefully" SIGTERM

psmgr=/tmp/nginx-buildpack-wait
rm -f $psmgr
mkfifo $psmgr
Expand Down
2 changes: 2 additions & 0 deletions bin/start-nginx-debug
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

trap "echo start-nginx-debug got SIGTERM. Ignoring while nginx shuts down gracefully" SIGTERM

psmgr=/tmp/nginx-buildpack-wait
rm -f $psmgr
mkfifo $psmgr
Expand Down
2 changes: 2 additions & 0 deletions bin/start-nginx-solo
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

trap "echo start-nginx-solo got SIGTERM. Ignoring while nginx shuts down gracefully" SIGTERM

psmgr=/tmp/nginx-buildpack-wait
rm -f $psmgr
mkfifo $psmgr
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [x.x] - xxxx-xx-xx
### Changes
- [all] Patched nginx so it gracefully shuts down on SIGTERM.
- [all] start-nginx scripts ignore the SIGTERM signal so they do not kill off nginx abruptly.

## [1.7] - 2021-06-04
### Changes
- [heroku-18] updated nginx to 1.20.1
Expand Down
Binary file modified nginx-heroku-18.tgz
Binary file not shown.
Binary file modified nginx-heroku-20.tgz
Binary file not shown.
17 changes: 17 additions & 0 deletions scripts/build_nginx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ echo "Downloading $zlib_url"
echo "Downloading $uuid4_url"
(cd nginx-${NGINX_VERSION} && curl -L $uuid4_url | tar xvz )

if [ -d "/buildpack/scripts/patchfiles/${NGINX_VERSION}" ]
then
PATCHFILES=$(find /buildpack/scripts/patchfiles/${NGINX_VERSION} -name '*.patch')
else
PATCHFILES=$(find /buildpack/scripts/patchfiles/default -name '*.patch')
fi


(
cd nginx-${NGINX_VERSION}
for f in $PATCHFILES
do
echo "patch: $f"
patch -p0 < $f
done
)

# This will build `nginx`
(
cd nginx-${NGINX_VERSION}
Expand Down
13 changes: 13 additions & 0 deletions scripts/patchfiles/default/0001-Custom-Terminate-Signal.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--- src/core/ngx_config.h 2020-05-23 04:21:07.000000000 +0000
+++ src/core/ngx_config.h 2020-05-23 04:15:17.000000000 +0000
@@ -56,9 +56,8 @@

#define ngx_random random

-/* TODO: #ifndef */
-#define NGX_SHUTDOWN_SIGNAL QUIT
-#define NGX_TERMINATE_SIGNAL TERM
+#define NGX_SHUTDOWN_SIGNAL TERM
+#define NGX_TERMINATE_SIGNAL QUIT
#define NGX_NOACCEPT_SIGNAL WINCH
#define NGX_RECONFIGURE_SIGNAL HUP