You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Nginx: using cont-finish.d for more graceful shutdown (#67)
* Nginx: using cont-init.d for more graceful shutdown
First suppress initial TERM/HUP, then use
cont-finish.d as shutdown script
* README: added drain timing explanation
Copy file name to clipboardExpand all lines: README.md
+23-34Lines changed: 23 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,59 +17,48 @@ See parent(s) [docker-base](https://github.com/behance/docker-base) for addition
17
17
18
18
### Expectations
19
19
20
-
Applications using this as a container parent must copy their html/app into the `/var/www/html` folder
21
-
NOTE: Nginx is exposed and bound to an unprivileged port, `8080`
20
+
- Applications must copy their html/app into the `/var/www/html` folder
21
+
-NOTE: Nginx is exposed and bound to an unprivileged port, `8080`
22
22
23
23
24
24
### Security
25
25
26
-
For Ubuntu-based variants, a convenience script is provided for security-only package updates. To run: `/bin/bash -e /security_updates.sh`
26
+
See parent [configuration](https://github.com/behance/docker-base#security)
27
27
28
28
29
29
### Environment Variables
30
30
31
31
Variable | Example | Description
32
32
--- | --- | ---
33
-
`SERVER_MAX_BODY_SIZE` | `SERVER_MAX_BODY_SIZE=4M` | Allows the downstream application to specify a non-default `client_max_body_size` configuration for the `server`-level directive in `/etc/nginx/sites-available/default`
34
-
`SERVER_INDEX` | `SERVER_INDEX index.html index.html index.php` | Changes the default pages to hit for folder and web roots
35
-
`SERVER_APP_NAME` | `SERVER_APP_NAME='view'` | Gets appended to the default logging format
36
-
`SERVER_GZIP_OPTIONS` | `SERVER_GZIP_OPTIONS=1` | Allows default set of static content to be served gzipped
37
-
`SERVER_SENDFILE` | `SERVER_SENDFILE=off` | Allows runtime to specify value of nginx's `sendfile` (default, on)
`SERVER_LOG_MINIMAL` | `SERVER_LOG_MINIMAL=1` | Minimize the logging format, appropriate for development environments
45
-
`S6_KILL_FINISH_MAXTIME` | `S6_KILL_FINISH_MAXTIME=1000` | Wait time (in ms) for zombie reaping before sending a kill signal
46
-
`S6_KILL_GRACETIME` | `S6_KILL_GRACETIME=500` | Wait time (in ms) for S6 finish scripts before sending kill signal
33
+
SERVER_MAX_BODY_SIZE | SERVER_MAX_BODY_SIZE=4M | Allows the downstream application to specify a non-default `client_max_body_size` configuration for the `server`-level directive in `/etc/nginx/sites-available/default`
34
+
SERVER_INDEX | SERVER_INDEX index.html index.html index.php | Changes the default pages to hit for folder and web roots
35
+
SERVER_APP_NAME | SERVER_APP_NAME='view' | Gets appended to the default logging format
36
+
SERVER_GZIP_OPTIONS | SERVER_GZIP_OPTIONS=1 | Allows default set of static content to be served gzipped
37
+
SERVER_SENDFILE | SERVER_SENDFILE=off | Allows runtime to specify value of nginx's `sendfile` (default, on)
SERVER_LOG_MINIMAL | SERVER_LOG_MINIMAL=1 | Minimize the logging format, appropriate for development environments
45
+
S6_KILL_FINISH_MAXTIME | S6_KILL_FINISH_MAXTIME=55000 | The maximum time (in ms) a script in /etc/cont-finish.d could take before sending a KILL signal to it. Take into account that this parameter will be used per each script execution, it's not a max time for the whole set of scripts. This value has a max of 65535 on Alpine variants.
46
+
S6_KILL_GRACETIME | S6_KILL_GRACETIME=500 | Wait time (in ms) for S6 finish scripts before sending kill signal
47
47
48
48
49
49
### Startup/Runtime Modification
50
50
51
-
To inject changes just before runtime, shell scripts (ending in .sh) may be placed into the
52
-
`/etc/cont-init.d` folder. For example, the above environment variables are used to drive nginx configuration at runtime.
53
-
As part of the process manager, these scripts are run in advance of the supervised processes. @seehttps://github.com/just-containers/s6-overlay#executing-initialization-andor-finalization-tasks
51
+
- Environment variables are used to drive nginx configuration at runtime
52
+
- See [here](https://github.com/behance/docker-base#startupruntime-modification) for more advanced options
54
53
54
+
### Shutdown Behavior
55
55
56
-
### Advanced Modification
57
-
58
-
More advanced changes can take effect using the run.d system. Similar to the `/etc/cont-init.d/` script system, any scripts (ending in .sh) in the `/run.d/` folder will be executed ahead of the S6 initialization.
59
-
60
-
- If run.d script terminates with a non-zero exit code, container will stop, terminating with the script's exit code, unless...
61
-
- If script terminates with exit code of $SIGNAL_BUILD_STOP (99), this will signal the container to stop cleanly. This can be used for multi-stage builds
62
-
56
+
Graceful shutdown is handled as part of the [existing](https://github.com/behance/docker-base#shutdown-behavior) S6 termination process, using a `/etc/cont-finish.d` script.
57
+
Nginx will attempt to drain active workers, while rejecting new connections. The drain timeout is controlled by `S6_KILL_FINISH_MAXTIME`, which corresponds to the length of time the supervisor will wait for the script to run during shutdown. This value defaults to 55s, which deliberately `less` than an downstream load balancers default max connection length (60s). Each upstream's timeout must be less than the downstream, for sanity and lack of timing precision.
63
58
64
59
### Long-running processes (workers + crons)
65
60
66
-
This container image can be shared between web and non-web processes. An example use case would be
67
-
a web service and codebase that also has a few crons and background workers. To reuse this container for
68
-
those types of workloads:
69
-
70
-
`docker run {image_id} /worker.sh 3 /bin/binary -parameters -that -binary -receives`
71
-
72
-
Runs `3` copies of `/bin/binary` that receives the parameters `-parameters -that -binary -receives`
61
+
- See parent [configuration](https://github.com/behance/docker-base#long-running-processes-workers--crons) on reusing container for other purposes.
0 commit comments