Use two init levels for startup scripts

This commit is contained in:
cytopia
2018-12-28 18:47:57 +01:00
parent 3926ee7c7d
commit 452269c1b0
5 changed files with 74 additions and 6 deletions

View File

@@ -181,7 +181,8 @@ disable_modules "DISABLE_MODULES" "${DEBUG_LEVEL}"
###
### Run custom user supplied scripts
###
execute_custom_scripts "/startup.d" "${DEBUG_LEVEL}"
execute_custom_scripts "/startup.1.d" "${DEBUG_LEVEL}"
execute_custom_scripts "/startup.2.d" "${DEBUG_LEVEL}"
###

View File

@@ -209,7 +209,8 @@ update_ca_certificates "/ca" "${DEBUG_LEVEL}"
###
### Run custom user supplied scripts
###
execute_custom_scripts "/startup.d" "${DEBUG_LEVEL}"
execute_custom_scripts "/startup.1.d" "${DEBUG_LEVEL}"
execute_custom_scripts "/startup.2.d" "${DEBUG_LEVEL}"
###

View File

@@ -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="6"><strong>prod</strong><br/><br/><strong>work</strong></td>
<td rowspan="7"><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>
@@ -773,8 +773,12 @@ Have a look at the following table to see all offered volumes for each Docker im
<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>
<td><code>/startup.1.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. (will run before <code>/startup.2.d</code>)</td>
</tr>
<tr>
<td><code>/startup.2.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. (will run after <code>/startup.1.d</code>)</td>
</tr>
<tr>
<td><code>/var/log/php</code></td>

View File

@@ -23,7 +23,7 @@ FLAVOUR="${3}"
### Check if PHP still starts up with working scripts
###
RUN_SH_HOST="$( mktemp -d )"
RUN_SH_CONT="/startup.d"
RUN_SH_CONT="/startup.1.d"
# Fix mount permissions
chmod 0777 "${RUN_SH_HOST}"

View File

@@ -0,0 +1,62 @@
#!/usr/bin/env bash
set -e
set -u
set -o pipefail
CWD="$(cd -P -- "$(dirname -- "$0")" && pwd -P)"
IMAGE="${1}"
VERSION="${2}"
FLAVOUR="${3}"
# shellcheck disable=SC1090
. "${CWD}/../.lib.sh"
############################################################
# Tests
############################################################
###
### Check if PHP still starts up with working scripts
###
RUN_SH_HOST="$( mktemp -d )"
RUN_SH_CONT="/startup.2.d"
# Fix mount permissions
chmod 0777 "${RUN_SH_HOST}"
# Add a startup script to execute
printf "#!/bin/bash\\necho 'abcdefghijklmnopq';\\n" > "${RUN_SH_HOST}/myscript1.sh"
chmod +x "${RUN_SH_HOST}/myscript1.sh"
# Start PHP-FPM
did="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "-e DEBUG_ENTRYPOINT=2 -e NEW_UID=$(id -u) -e NEW_GID=$(id -g) -v ${RUN_SH_HOST}:${RUN_SH_CONT}" )"
# Wait for both containers to be up and running
run "sleep 10"
# Check entrypoint for script run
if ! run "docker logs ${did} | grep 'myscript1.sh'"; then
docker_logs "${did}" || true
docker_stop "${did}" || true
rm -rf "${RUN_SH_HOST}"
echo "Failed"
exit 1
fi
# Check entrypoint for script output
if ! run "docker logs ${did} | grep 'abcdefghijklmnopq'"; then
docker_logs "${did}" || true
docker_stop "${did}" || true
rm -rf "${RUN_SH_HOST}"
echo "Failed"
exit 1
fi
# Cleanup
docker_stop "${did}"
rm -rf "${RUN_SH_HOST}"