diff --git a/Dockerfiles/prod/data/docker-entrypoint.d/310-custom-startup-scripts.sh b/Dockerfiles/prod/data/docker-entrypoint.d/310-custom-startup-scripts.sh new file mode 100755 index 0000000..49d251b --- /dev/null +++ b/Dockerfiles/prod/data/docker-entrypoint.d/310-custom-startup-scripts.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +set -e +set -u +set -o pipefail + + +############################################################ +# Functions +############################################################ + +### +### Execute custom uesr-supplied scripts +### +execute_custom_scripts() { + local script_dir="${1}" + local debug="${2}" + + if [ ! -d "${script_dir}" ]; then + run "mkdir -p ${script_dir}" "${debug}" + fi + script_files="$( find "${script_dir}" -type f -iname '*.sh' )" + + # loop over them line by line + IFS=' + ' + for script_f in ${script_files}; do + script_name="$( basename "${script_f}" )" + log "info" "Executing custom startup script: ${script_name}" "${debug}" + if ! bash "${script_f}"; then + log "err" "Failed to execute script" "${debug}" + exit 1 + fi + done +} + + +############################################################ +# Sanity Checks +############################################################ + +if ! command -v find >/dev/null 2>&1; then + echo "find not found, but required." + exit 1 +fi +if ! command -v basename >/dev/null 2>&1; then + echo "basename not found, but required." + exit 1 +fi diff --git a/Dockerfiles/prod/data/docker-entrypoint.sh b/Dockerfiles/prod/data/docker-entrypoint.sh index 970820d..4f9f669 100755 --- a/Dockerfiles/prod/data/docker-entrypoint.sh +++ b/Dockerfiles/prod/data/docker-entrypoint.sh @@ -178,6 +178,13 @@ enable_modules "ENABLE_MODULES" "${DEBUG_LEVEL}" disable_modules "DISABLE_MODULES" "${DEBUG_LEVEL}" +### +### Run custom user supplied scripts +### +execute_custom_scripts "/startup.d" "${DEBUG_LEVEL}" + + +### ### ### Startup ### diff --git a/Dockerfiles/work/data/docker-entrypoint.sh b/Dockerfiles/work/data/docker-entrypoint.sh index afe08bd..f1c1a49 100755 --- a/Dockerfiles/work/data/docker-entrypoint.sh +++ b/Dockerfiles/work/data/docker-entrypoint.sh @@ -206,6 +206,12 @@ run "chmod 0755 /shared/httpd" "${DEBUG_LEVEL}" update_ca_certificates "/ca" "${DEBUG_LEVEL}" +### +### Run custom user supplied scripts +### +execute_custom_scripts "/startup.d" "${DEBUG_LEVEL}" + + ### ### Startup ### diff --git a/README.md b/README.md index 3a889f8..40e5b3d 100644 --- a/README.md +++ b/README.md @@ -760,7 +760,7 @@ Have a look at the following table to see all offered volumes for each Docker im
/etc/php-custom.d\*.ini files in order to alter php behaviour./etc/php-modules.d\*.so files in order to add your php modules.\*.ini file in order to actually load your custom provided module./startup.d\*.sh found in this directory will be executed during startup. This is useful to supply additional commands (such as installing custom software) when the container starts up./var/log/phpDOCKER_LOGS to 0, log files will be available under this directory.