Skip to content

Commit

Permalink
Allow for custom user-supplied startup scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
cytopia committed Dec 24, 2018
1 parent 4f1a054 commit 023ad2a
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions Dockerfiles/prod/data/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
###
Expand Down
6 changes: 6 additions & 0 deletions Dockerfiles/work/data/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
###
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ Have a look at the following table to see all offered volumes for each Docker im
</thead>
<tbody>
<tr>
<td rowspan="5"><strong>prod</strong><br/><br/><strong>work</strong></td>
<td rowspan="6"><strong>prod</strong><br/><br/><strong>work</strong></td>
<td><code>/etc/php-custom.d</code></td>
<td>Mount this directory into your host computer and add custom <code>\*.ini</code> files in order to alter php behaviour.</td>
</tr>
Expand All @@ -772,6 +772,10 @@ Have a look at the following table to see all offered volumes for each Docker im
<td><code>/etc/php-modules.d</code></td>
<td>Mount this directory into your host computer and add custo <code>\*.so</code> files in order to add your php modules.<br/><br/><strong>Note:</strong>Your should then also provide a custom <code>\*.ini</code> file in order to actually load your custom provided module.</td>
</tr>
<tr>
<td><code>/startup.d</code></td>
<td>Any executable scripts ending by <code>\*.sh</code> 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.</td>
</tr>
<tr>
<td><code>/var/log/php</code></td>
<td>When setting environment variable <code>DOCKER_LOGS</code> to <code>0</code>, log files will be available under this directory.</td>
Expand Down

0 comments on commit 023ad2a

Please sign in to comment.