Test: Better check to see if PHP-FPM is running

This commit is contained in:
cytopia
2022-03-24 13:02:49 +01:00
parent 663f716031
commit 81ef92f91e
16 changed files with 267 additions and 27 deletions

View File

@@ -184,21 +184,6 @@ function docker_exec() {
}
###
### Get docker name
###
function docker_name() {
local name="${1}"
echo "${name}"
#name="$( docker ps | grep "${did}" | awk '{print $(NF)}' )"
#if [ -z "${name}" ]; then
# return 1
#fi
#echo "${name}"
}
###
### Stop container
###
@@ -209,3 +194,50 @@ function docker_stop() {
run "docker kill ${name} || true" 2>/dev/null
run "docker rm -f ${name} || true" 2>/dev/null
}
###
### Check if PHP-FPM is up and running
###
function check_php_fpm_running() {
local name="${1}"
local retries="60"
local index="0"
>&2 echo
# PHP process
index=0
>&2 echo "Checking if PHP-FPM process is running..."
while ! run "docker exec ${name} ps auxwww | grep -E '(php-fpm|php-cgi)'"; do
>&2 printf "."
index="$(( index + 1 ))"
if [ "${index}" = "${retries}" ]; then
>&2 echo
run "docker exec ${name} ps auxwww"
>&2 echo "Failed to find PHP process after ${retries} seconds."
return 1
fi
sleep 1
done
>&2 echo
# Docker logs
index=0
>&2 echo "Checking if PHP-FPM shows success in docker logs..."
while ! run "docker logs ${name} 2>&1 | grep -E 'php-fpm entered RUNNING state|ready to handle connections|fpm is running'"; do
>&2 printf "."
index="$(( index + 1 ))"
if [ "${index}" = "${retries}" ]; then
>&2 echo
>&2 echo "Failed to find PHP success in docker logs after ${retries} seconds."
return 1
fi
sleep 1
done
>&2 echo
# Echo newline and return
return 0
}

View File

@@ -27,6 +27,18 @@ print_h2 "DEBUG_ENTRYPOINT=0"
if ! name="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "${ARCH}" "-e DEBUG_ENTRYPOINT=0" )"; then
exit 1
fi
# Check if PHP-FPM is running
print_h2 "Check if PHP-FPM is running"
if ! check_php_fpm_running "${name}"; then
docker_logs "${name}" || true
docker_stop "${name}" || true
echo "Failed"
exit 1
fi
# Start Tests
print_h2 "Testing..."
if ! run_fail "docker logs ${name} 2>&1 | grep '\[INFO\]'"; then
docker_logs "${name}" || true
docker_stop "${name}" || true
@@ -49,6 +61,18 @@ print_h2 "DEBUG_ENTRYPOINT=1"
if ! name="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "${ARCH}" "-e DEBUG_ENTRYPOINT=1" )"; then
exit 1
fi
# Check if PHP-FPM is running
print_h2 "Check if PHP-FPM is running"
if ! check_php_fpm_running "${name}"; then
docker_logs "${name}" || true
docker_stop "${name}" || true
echo "Failed"
exit 1
fi
# Start Tests
print_h2 "Testing..."
if ! run "docker logs ${name} 2>&1 | grep 'Debug level: 1'"; then
docker_logs "${name}" || true
docker_stop "${name}" || true
@@ -77,6 +101,18 @@ print_h2 "DEBUG_ENTRYPOINT=2"
if ! name="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "${ARCH}" "-e DEBUG_ENTRYPOINT=2" )"; then
exit 1
fi
# Check if PHP-FPM is running
print_h2 "Check if PHP-FPM is running"
if ! check_php_fpm_running "${name}"; then
docker_logs "${name}" || true
docker_stop "${name}" || true
echo "Failed"
exit 1
fi
# Start Tests
print_h2 "Testing..."
if ! run "docker logs ${name} 2>&1 | grep 'Debug level: 2'"; then
docker_logs "${name}" || true
docker_stop "${name}" || true

View File

@@ -27,6 +27,18 @@ print_h2 "DEBUG_ENTRYPOINT=2 NEW_UID=1005"
if ! name="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "${ARCH}" "-e DEBUG_ENTRYPOINT=2 -e NEW_UID=1005" )"; then
exit 1
fi
# Check if PHP-FPM is running
print_h2 "Check if PHP-FPM is running"
if ! check_php_fpm_running "${name}"; then
docker_logs "${name}" || true
docker_stop "${name}" || true
echo "Failed"
exit 1
fi
# Start Tests
print_h2 "Testing..."
if ! run "docker logs ${name} 2>&1 | grep -q '1005'"; then
docker_logs "${name}" || true
docker_stop "${name}" || true
@@ -49,6 +61,18 @@ print_h2 "DEBUG_ENTRYPOINT=2 NEW_UID=1000"
if ! name="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "${ARCH}" "-e DEBUG_ENTRYPOINT=2 -e NEW_UID=1000" )"; then
exit 1
fi
# Check if PHP-FPM is running
print_h2 "Check if PHP-FPM is running"
if ! check_php_fpm_running "${name}"; then
docker_logs "${name}" || true
docker_stop "${name}" || true
echo "Failed"
exit 1
fi
# Start Tests
print_h2 "Testing..."
if ! run "docker logs ${name} 2>&1 | grep -q '1000'"; then
docker_logs "${name}" || true
docker_stop "${name}" || true
@@ -71,6 +95,18 @@ print_h2 "DEBUG_ENTRYPOINT=2 NEW_UID=33"
if ! name="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "${ARCH}" "-e DEBUG_ENTRYPOINT=2 -e NEW_UID=33" )"; then
exit 1
fi
# Check if PHP-FPM is running
print_h2 "Check if PHP-FPM is running"
if ! check_php_fpm_running "${name}"; then
docker_logs "${name}" || true
docker_stop "${name}" || true
echo "Failed"
exit 1
fi
# Start Tests
print_h2 "Testing..."
if ! run "docker logs ${name} 2>&1 | grep -q '33'"; then
docker_logs "${name}" || true
docker_stop "${name}" || true

View File

@@ -27,6 +27,18 @@ print_h2 "DEBUG_ENTRYPOINT=2 NEW_GID=1005"
if ! name="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "${ARCH}" "-e DEBUG_ENTRYPOINT=2 -e NEW_GID=1005" )"; then
exit 1
fi
# Check if PHP-FPM is running
print_h2 "Check if PHP-FPM is running"
if ! check_php_fpm_running "${name}"; then
docker_logs "${name}" || true
docker_stop "${name}" || true
echo "Failed"
exit 1
fi
# Start Tests
print_h2 "Testing..."
if ! run "docker logs ${name} 2>&1 | grep -q '1005'"; then
docker_logs "${name}" || true
docker_stop "${name}" || true
@@ -49,6 +61,18 @@ print_h2 "DEBUG_ENTRYPOINT=2 NEW_GID=1000"
if ! name="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "${ARCH}" "-e DEBUG_ENTRYPOINT=2 -e NEW_GID=1000" )"; then
exit 1
fi
# Check if PHP-FPM is running
print_h2 "Check if PHP-FPM is running"
if ! check_php_fpm_running "${name}"; then
docker_logs "${name}" || true
docker_stop "${name}" || true
echo "Failed"
exit 1
fi
# Start Tests
print_h2 "Testing..."
if ! run "docker logs ${name} 2>&1 | grep -q '1000'"; then
docker_logs "${name}" || true
docker_stop "${name}" || true
@@ -71,6 +95,18 @@ print_h2 "DEBUG_ENTRYPOINT=2 NEW_GID=33"
if ! name="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "${ARCH}" "-e DEBUG_ENTRYPOINT=2 -e NEW_GID=33" )"; then
exit 1
fi
# Check if PHP-FPM is running
print_h2 "Check if PHP-FPM is running"
if ! check_php_fpm_running "${name}"; then
docker_logs "${name}" || true
docker_stop "${name}" || true
echo "Failed"
exit 1
fi
# Start Tests
print_h2 "Testing..."
if ! run "docker logs ${name} 2>&1 | grep -q '33'"; then
docker_logs "${name}" || true
docker_stop "${name}" || true

View File

@@ -49,6 +49,16 @@ if ! name="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "${ARCH}" "-e DEBUG_EN
exit 1
fi
# Check if PHP-FPM is running
print_h2 "Check if PHP-FPM is running"
if ! check_php_fpm_running "${name}"; then
docker_logs "${name}" || true
docker_stop "${name}" || true
echo "Failed"
exit 1
fi
# Nginx.conf
{
echo "server {"

View File

@@ -28,6 +28,17 @@ if ! name="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "${ARCH}" "-e DEBUG_EN
exit 1
fi
# Check if PHP-FPM is running
print_h2 "Check if PHP-FPM is running"
if ! check_php_fpm_running "${name}"; then
docker_logs "${name}" || true
docker_stop "${name}" || true
echo "Failed"
exit 1
fi
# Start Tests
print_h2 "Testing..."
if ! docker_exec "${name}" "apt update"; then
docker_logs "${name}" || true
docker_stop "${name}" || true

View File

@@ -28,6 +28,17 @@ if ! name="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "${ARCH}" "-e DEBUG_EN
exit 1
fi
# Check if PHP-FPM is running
print_h2 "Check if PHP-FPM is running"
if ! check_php_fpm_running "${name}"; then
docker_logs "${name}" || true
docker_stop "${name}" || true
echo "Failed"
exit 1
fi
# Start Tests
print_h2 "Testing..."
if ! run "docker logs ${name} 2>&1 | grep -q 'Europe/Berlin'"; then
docker_logs "${name}" || true
docker_stop "${name}" || true

View File

@@ -55,6 +55,15 @@ if ! name="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "${ARCH}" "-e DEBUG_EN
exit 1
fi
# Check if PHP-FPM is running
print_h2 "Check if PHP-FPM is running"
if ! check_php_fpm_running "${name}"; then
docker_logs "${name}" || true
docker_stop "${name}" || true
echo "Failed"
exit 1
fi
# Nginx.conf
{
echo "server {"

View File

@@ -55,6 +55,15 @@ if ! name="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "${ARCH}" "-e DEBUG_EN
exit 1
fi
# Check if PHP-FPM is running
print_h2 "Check if PHP-FPM is running"
if ! check_php_fpm_running "${name}"; then
docker_logs "${name}" || true
docker_stop "${name}" || true
echo "Failed"
exit 1
fi
# Nginx.conf
{
echo "server {"

View File

@@ -29,8 +29,18 @@ print_h2 "-e DEBUG_ENTRYPOINT=2 -e NEW_UID=$(id -u) -e NEW_GID=$(id -g) -e ENABL
if ! name="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "${ARCH}" "-e DEBUG_ENTRYPOINT=2 -e NEW_UID=$(id -u) -e NEW_GID=$(id -g) -e ENABLE_MAIL=2 -v ${MOUNTPOINT}:/var/mail" )"; then
exit 1
fi
run "sleep 10"
# Check if PHP-FPM is running
print_h2 "Check if PHP-FPM is running"
if ! check_php_fpm_running "${name}"; then
docker_logs "${name}" || true
docker_stop "${name}" || true
echo "Failed"
exit 1
fi
# Start Tests
print_h2 "Testing..."
if ! run "docker logs ${name} 2>&1 | grep -q 'ENABLE_MAIL'"; then
docker_logs "${name}" || true
docker_stop "${name}" || true

View File

@@ -43,8 +43,15 @@ if ! name="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "${ARCH}" "-e DEBUG_EN
docker_stop "${name_mysql}" || true
exit 1
fi
run "sleep 15"
# Check if PHP-FPM is running
print_h2 "Check if PHP-FPM is running"
if ! check_php_fpm_running "${name}"; then
docker_logs "${name}" || true
docker_stop "${name}" || true
echo "Failed"
exit 1
fi
print_h2 "Ensure forwarding info is present in docker logs"
if ! run "docker logs ${name} 2>&1 | grep 'Forwarding ${name_mysql}:3306'"; then
@@ -57,11 +64,6 @@ if ! run "docker logs ${name} 2>&1 | grep 'Forwarding ${name_mysql}:3306'"; then
fi
# Test connectivity
#docker_exec "${did}" "ping -c 1 ${mname}"
#docker_exec "${did}" "echo | nc -w 1 ${mname} 3306"
#docker_exec "${did}" "echo | nc -w 1 127.0.0.1 3306"
# Only work container has mysql binary installed
if [ "${FLAVOUR}" = "work" ]; then
print_h2 "Test connectivity against hostname"

View File

@@ -55,6 +55,15 @@ if ! name="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "${ARCH}" "-e DEBUG_EN
exit 1
fi
# Check if PHP-FPM is running
print_h2 "Check if PHP-FPM is running"
if ! check_php_fpm_running "${name}"; then
docker_logs "${name}" || true
docker_stop "${name}" || true
echo "Failed"
exit 1
fi
# Nginx.conf
{
echo "server {"

View File

@@ -59,6 +59,15 @@ if ! name="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "${ARCH}" "-e DEBUG_EN
exit 1
fi
# Check if PHP-FPM is running
print_h2 "Check if PHP-FPM is running"
if ! check_php_fpm_running "${name}"; then
docker_logs "${name}" || true
docker_stop "${name}" || true
echo "Failed"
exit 1
fi
# Nginx.conf
{
echo "server {"

View File

@@ -39,8 +39,14 @@ if ! name="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "${ARCH}" "-e DEBUG_EN
exit 1
fi
# Wait for both containers to be up and running
run "sleep 10"
# Check if PHP-FPM is running
print_h2 "Check if PHP-FPM is running"
if ! check_php_fpm_running "${name}"; then
docker_logs "${name}" || true
docker_stop "${name}" || true
echo "Failed"
exit 1
fi
# Check entrypoint for script run
print_h2 "Check docker logs for script run"

View File

@@ -38,8 +38,15 @@ print_h2 "-e DEBUG_ENTRYPOINT=2 -e NEW_UID=$(id -u) -e NEW_GID=$(id -g) -v ${RUN
if ! name="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "${ARCH}" "-e DEBUG_ENTRYPOINT=2 -e NEW_UID=$(id -u) -e NEW_GID=$(id -g) -v ${RUN_SH_HOST}:${RUN_SH_CONT}" )"; then
exit 1
fi
# Wait for both containers to be up and running
run "sleep 10"
# Check if PHP-FPM is running
print_h2 "Check if PHP-FPM is running"
if ! check_php_fpm_running "${name}"; then
docker_logs "${name}" || true
docker_stop "${name}" || true
echo "Failed"
exit 1
fi
# Check entrypoint for script run
print_h2 "Check docker logs for script run"

View File

@@ -44,8 +44,15 @@ if ! name="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "${ARCH}" "-e DEBUG_EN
docker_stop "${name_mysql}" || true
exit 1
fi
run "sleep 15"
# Check if PHP-FPM is running
print_h2 "Check if PHP-FPM is running"
if ! check_php_fpm_running "${name}"; then
docker_logs "${name}" || true
docker_stop "${name}" || true
echo "Failed"
exit 1
fi
print_h2 "Run mysqldump-secure"
if ! docker_exec "${name}" "mysqldump-secure -vv"; then