From 0e70c8c099b166097d9bffa7fa8fb07ade9925f7 Mon Sep 17 00:00:00 2001 From: xZero707 Date: Fri, 17 May 2024 07:25:10 +0200 Subject: [PATCH] Fix the bug where wait hangs forever --- .../s6-rc.d/init-install-resources/run | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/rootfs/etc/s6-overlay/s6-rc.d/init-install-resources/run b/rootfs/etc/s6-overlay/s6-rc.d/init-install-resources/run index 2f91218..b908423 100755 --- a/rootfs/etc/s6-overlay/s6-rc.d/init-install-resources/run +++ b/rootfs/etc/s6-overlay/s6-rc.d/init-install-resources/run @@ -42,7 +42,7 @@ checkInstalled() { } # Plugins installer -function taskInstallPlugins() { +taskInstallPlugins() { export WP_PLUGINS_PATH local concurrencyLimit="${WP_PLUGINS_INSTALL_CONCURRENCY:-5}" @@ -57,6 +57,8 @@ function taskInstallPlugins() { return 0 fi + local jobs=() + echo "About to install defined plugins" for pluginExpr in ${PLUGIN_LIST}; do @@ -74,9 +76,11 @@ function taskInstallPlugins() { if [ -n "${pluginVersion}" ]; then echo "Installing plugin '${pluginSlug}' version '${pluginVersion}'" installPlugin "${pluginSlug}" "${pluginVersion}" & + jobs+=($!) else echo "Installing plugin '${pluginSlug}'" installPlugin "${pluginSlug}" & + jobs+=($!) fi # Run maximum of X plugin installs in parallel @@ -87,7 +91,10 @@ function taskInstallPlugins() { done echo "Waiting for all tasks to finish..." - wait + + for pid in ${jobs[@]}; do + wait $pid + done # Plugins are installed concurrently, so we need to verify if installed, separately echo "About to verify install of defined plugins" @@ -111,15 +118,22 @@ main() { echo "Automated WordPress Resources Installer" + local jobs=() + export WP_CONTENT_PATH WP_PLUGINS_INSTALL_CONCURRENCY="${WP_PLUGINS_INSTALL_CONCURRENCY:-5}" export PLUGIN_LIST WP_PLUGINS_PATH WP_PLUGINS_INSTALL_CONCURRENCY taskInstallPlugins "${@}" & + jobs+=($!) - sleep 1 echo "Waiting for all tasks to complete" - wait + + # Wait for all tasks but do not wait for the background task + for pid in ${jobs[@]}; do + wait $pid + done + return 0 }