Skip to content

Commit 8d366cf

Browse files
authored
Merge pull request #157 from psaux-it/wait_for_file
implement wait_for_file
2 parents 2df9679 + 892fb14 commit 8d366cf

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

nginx/entrypoint-nginx.sh

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,33 @@ wait_for_service() {
5555
echo -e "${COLOR_GREEN}${COLOR_BOLD}NPP-NGINX:${COLOR_RESET} ${COLOR_CYAN}${host}:${port}${COLOR_RESET} is now available! Proceeding..."
5656
}
5757

58+
# Function to wait for the WordPress post-start readiness marker file.
59+
# Polling a file on the shared web-root volume survives 'nginx' restarting
60+
# on its own, unlike a one-shot TCP probe that only tolerates a single check.
61+
wait_for_file() {
62+
local file="$1"
63+
local retries=60
64+
local wait_time=5
65+
66+
while [[ ! -f "${file}" ]]; do
67+
if [[ "${retries}" -le 0 ]]; then
68+
echo -e "${COLOR_RED}${COLOR_BOLD}NPP-NGINX-FATAL:${COLOR_RESET} ${COLOR_CYAN}${file}${COLOR_RESET} was not created in time. Exiting..."
69+
exit 1
70+
fi
71+
echo -e "${COLOR_YELLOW}${COLOR_BOLD}NPP-NGINX:${COLOR_RESET} Waiting for ${COLOR_CYAN}${file}${COLOR_RESET} to appear..."
72+
sleep "${wait_time}"
73+
retries=$((retries - 1))
74+
done
75+
76+
echo -e "${COLOR_GREEN}${COLOR_BOLD}NPP-NGINX:${COLOR_RESET} ${COLOR_CYAN}${file}${COLOR_RESET} found! Proceeding..."
77+
}
78+
5879
# Display pre-entrypoint start message
5980
echo -e "${COLOR_GREEN}${COLOR_BOLD}NPP-NGINX:${COLOR_RESET} ${COLOR_CYAN}${COLOR_BOLD}[Pre-Entrypoint]:${COLOR_RESET} Preparing environment before starting the ${COLOR_LIGHT_CYAN}Nginx${COLOR_RESET} service..."
6081

6182
# Wait for 'php-fpm' to be up
6283
wait_for_service "wordpress" 9001
6384

64-
# Wait for Wordpress core Initialization to complete
65-
wait_for_service "wordpress" 9999
66-
6785
# Check if required environment variables are set
6886
for var in \
6987
NPP_UID \
@@ -80,6 +98,9 @@ for var in \
8098
fi
8199
done
82100

101+
# Wait for Wordpress core Initialization (post-start setup) to complete
102+
wait_for_file "${NPP_WEB_ROOT}/.npp-ready"
103+
83104
# Create Isolated PHP process owner user and group on Nginx container
84105
echo -e "${COLOR_GREEN}${COLOR_BOLD}NPP-NGINX:${COLOR_RESET} Checking PHP process owner user and group with UID ${COLOR_CYAN}${NPP_UID}${COLOR_RESET} and GID ${COLOR_CYAN}${NPP_GID}${COLOR_RESET}"
85106
if ! getent passwd "${NPP_USER}" >/dev/null 2>&1; then

0 commit comments

Comments
 (0)