Skip to content

Commit

Permalink
Make PHP-FPM timeout configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
cytopia committed Aug 4, 2018
1 parent 5ebb59e commit 17abe7c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Expand Up @@ -10,7 +10,7 @@ LABEL \
###
### Build arguments
###
ARG VHOST_GEN_GIT_REF=0.11
ARG VHOST_GEN_GIT_REF=0.12
ARG CERT_GEN_GIT_REF=0.2

ENV BUILD_DEPS \
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -127,6 +127,7 @@ This Docker container adds a lot of injectables in order to customize it to your
| PHP_FPM_ENABLE | bool | `0` | Enable PHP-FPM for the default vhost and the mass virtual hosts. |
| PHP_FPM_SERVER_ADDR | string | `` | IP address or hostname of remote PHP-FPM server.<br/><strong>Required when enabling PHP.</strong> |
| PHP_FPM_SERVER_PORT | int | `9000` | Port of remote PHP-FPM server |
| PHP_FPM_TIMEOUT | int | `180` | Timeout in seconds to upstream PHP-FPM server |

##### Optional environmental variables (default vhost)

Expand Down
35 changes: 35 additions & 0 deletions data/docker-entrypoint.d/04-php-fpm.sh
Expand Up @@ -96,3 +96,38 @@ export_php_fpm_server_port() {
# Ensure variable is exported if not set
eval "export ${varname}=${value}"
}


###
### Ensure PHP_FPM_TIMEOUT is set (if needed)
###
export_php_fpm_timeout() {
local varname="${1}"
local debug="${2}"
local value="180"

if [ "${PHP_FPM_ENABLE}" = "1" ]; then
if ! env_set "${varname}"; then
log "info" "\$${varname} not specified, keeping default: ${value}" "${debug}"
else
value="$( env_get "${varname}" )"

if [ -z "${value}" ]; then
log "err" "\$${varname} is empty." "${debug}"
exit 1
fi
if ! isint "${value}"; then
log "err" "\$${varname} is not a valid integer: ${value}" "${debug}"
exit 1
fi
if [ "${value}" -lt "0" ]; then
log "err" "\$${varname} must be greater than 0: ${value}" "${debug}"
exit 1
fi
log "info" "PHP-FPM: Timeout: ${value}" "${debug}"
fi
fi

# Ensure variable is exported if not set
eval "export ${varname}=${value}"
}
5 changes: 3 additions & 2 deletions data/docker-entrypoint.sh
Expand Up @@ -82,6 +82,7 @@ export_docker_logs "DOCKER_LOGS" "${DEBUG_LEVEL}"
export_php_fpm_enable "PHP_FPM_ENABLE" "${DEBUG_LEVEL}"
export_php_fpm_server_addr "PHP_FPM_SERVER_ADDR" "${DEBUG_LEVEL}"
export_php_fpm_server_port "PHP_FPM_SERVER_PORT" "${DEBUG_LEVEL}"
export_php_fpm_timeout "PHP_FPM_TIMEOUT" "${DEBUG_LEVEL}"


###
Expand Down Expand Up @@ -125,8 +126,8 @@ fi
###
### Enable and configure PHP-FPM
###
vhost_gen_php_fpm "${PHP_FPM_ENABLE}" "${PHP_FPM_SERVER_ADDR}" "${PHP_FPM_SERVER_PORT}" "/etc/vhost-gen/main.yml" "${DEBUG_LEVEL}"
vhost_gen_php_fpm "${PHP_FPM_ENABLE}" "${PHP_FPM_SERVER_ADDR}" "${PHP_FPM_SERVER_PORT}" "/etc/vhost-gen/mass.yml" "${DEBUG_LEVEL}"
vhost_gen_php_fpm "${PHP_FPM_ENABLE}" "${PHP_FPM_SERVER_ADDR}" "${PHP_FPM_SERVER_PORT}" "${PHP_FPM_TIMEOUT}" "/etc/vhost-gen/main.yml" "${DEBUG_LEVEL}"
vhost_gen_php_fpm "${PHP_FPM_ENABLE}" "${PHP_FPM_SERVER_ADDR}" "${PHP_FPM_SERVER_PORT}" "${PHP_FPM_TIMEOUT}" "/etc/vhost-gen/mass.yml" "${DEBUG_LEVEL}"


###
Expand Down

0 comments on commit 17abe7c

Please sign in to comment.