Skip to content

Commit bb19d58

Browse files
authored
Merge pull request #26 from devilbox/release-0.30
Be able to customise worker connections and worker processes
2 parents 789c5aa + d1fd59c commit bb19d58

File tree

5 files changed

+81
-2
lines changed

5 files changed

+81
-2
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ This Docker container adds a lot of injectables in order to customize it to your
116116

117117
`PHP_FPM_SERVER_ADDR` is required when enabling PHP FPM.
118118

119+
##### Optional environmental variables (nginx)
120+
121+
| Variable | Type | Default | Description |
122+
|----------|------|---------|-------------|
123+
| WORKER_CONNECTIONS | int | `1024` | [worker_connections](https://nginx.org/en/docs/ngx_core_module.html#worker_connections) |
124+
| WORKER_PROCESSES | int or `auto` | `auto` | [worker_processes](https://nginx.org/en/docs/ngx_core_module.html#worker_processes) |
125+
119126
##### Optional environmental variables (general)
120127

121128
| Variable | Type | Default | Description |
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
set -u
5+
set -o pipefail
6+
7+
8+
############################################################
9+
# Functions
10+
############################################################
11+
12+
###
13+
### Change worker_processes
14+
###
15+
set_worker_processess() {
16+
local wp_varname="${1}"
17+
local debug="${2}"
18+
local default="auto"
19+
local config="/etc/nginx/nginx.conf"
20+
21+
if ! env_set "${wp_varname}"; then
22+
log "info" "\$${wp_varname} not set. Keeping default worker_processes: '${default}'." "${debug}"
23+
run "sed -i'' 's/__WORKER_PROCESSES__/${default}/g' ${config}" "${debug}"
24+
else
25+
wp="$( env_get "${wp_varname}" )"
26+
27+
if [ "${wp}" = "auto" ]; then
28+
log "info" "\$${wp_varname} set to its default value: '${default}'." "${debug}"
29+
run "sed -i'' 's/__WORKER_PROCESSES__/${default}/g' ${config}" "${debug}"
30+
else
31+
if ! isint "${wp}"; then
32+
log "err" "\$${wp_varname} is not an integer: '${wp}'" "${debug}"
33+
exit 1
34+
else
35+
log "info" "Setting worker_processes to: ${wp}" "${debug}"
36+
run "sed -i'' 's/__WORKER_PROCESSES__/${wp}/g' ${config}" "${debug}"
37+
fi
38+
fi
39+
fi
40+
}
41+
42+
43+
###
44+
### Change worker_connections
45+
###
46+
set_worker_connections() {
47+
local wc_varname="${1}"
48+
local debug="${2}"
49+
local default="1024"
50+
local config="/etc/nginx/nginx.conf"
51+
52+
if ! env_set "${wc_varname}"; then
53+
log "info" "\$${wc_varname} not set. Keeping default worker_connections: '${default}'." "${debug}"
54+
run "sed -i'' 's/__WORKER_CONNECTIONS__/${default}/g' ${config}" "${debug}"
55+
else
56+
wc="$( env_get "${wc_varname}" )"
57+
58+
if ! isint "${wc}"; then
59+
log "err" "\$${wc_varname} is not an integer: '${wc}'" "${debug}"
60+
exit 1
61+
else
62+
log "info" "Setting worker_connections to: ${wc}" "${debug}"
63+
run "sed -i'' 's/__WORKER_CONNECTIONS__/${wc}/g' ${config}" "${debug}"
64+
fi
65+
fi
66+
}

data/docker-entrypoint.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ set_gid "NEW_GID" "${MY_GROUP}" "${DEBUG_LEVEL}"
6767
set_timezone "TIMEZONE" "${DEBUG_LEVEL}"
6868

6969

70+
###
71+
### Nginx settings
72+
###
73+
set_worker_processess "WORKER_PROCESSES" "${DEBUG_LEVEL}"
74+
set_worker_connections "WORKER_CONNECTIONS" "${DEBUG_LEVEL}"
75+
7076

7177
#############################################################
7278
## Variable exports

data/nginx/nginx.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# MAIN SETTINGS
33
# =================================================================================================
44

5-
worker_processes auto;
5+
worker_processes __WORKER_PROCESSES__;
66

77
user nginx;
88
daemon off;
@@ -11,7 +11,7 @@ error_log /var/log/nginx/error.log warn;
1111
pid /var/run/nginx.pid;
1212

1313
events {
14-
worker_connections 1024;
14+
worker_connections __WORKER_CONNECTIONS__;
1515
}
1616

1717

0 commit comments

Comments
 (0)