From 4cb7286fc403601f486678b5d1c6633e95d3fa3c Mon Sep 17 00:00:00 2001 From: xZero707 Date: Fri, 17 May 2024 01:37:37 +0200 Subject: [PATCH] Refactor to new S6 format --- .../dependencies.d/init-verify-wordpress | 0 .../s6-rc.d/init-install-resources/run} | 37 ++++++++++--------- .../s6-rc.d/init-install-resources/type | 1 + .../s6-rc.d/init-install-resources/up | 1 + .../s6-rc.d/init-verify-wordpress/run} | 30 ++++++++------- .../s6-rc.d/init-verify-wordpress/type | 1 + .../s6-rc.d/init-verify-wordpress/up | 1 + .../user/contents.d/init-install-resources | 0 .../user/contents.d/init-verify-wordpress | 0 9 files changed, 39 insertions(+), 32 deletions(-) create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/init-install-resources/dependencies.d/init-verify-wordpress rename rootfs/etc/{cont-init.d/20-install-resources => s6-overlay/s6-rc.d/init-install-resources/run} (68%) create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/init-install-resources/type create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/init-install-resources/up rename rootfs/etc/{cont-init.d/10-verify-wordpress => s6-overlay/s6-rc.d/init-verify-wordpress/run} (53%) create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/init-verify-wordpress/type create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/init-verify-wordpress/up create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/init-install-resources create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/init-verify-wordpress diff --git a/rootfs/etc/s6-overlay/s6-rc.d/init-install-resources/dependencies.d/init-verify-wordpress b/rootfs/etc/s6-overlay/s6-rc.d/init-install-resources/dependencies.d/init-verify-wordpress new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/cont-init.d/20-install-resources b/rootfs/etc/s6-overlay/s6-rc.d/init-install-resources/run similarity index 68% rename from rootfs/etc/cont-init.d/20-install-resources rename to rootfs/etc/s6-overlay/s6-rc.d/init-install-resources/run index 8ec6087..7b26d93 100755 --- a/rootfs/etc/cont-init.d/20-install-resources +++ b/rootfs/etc/s6-overlay/s6-rc.d/init-install-resources/run @@ -20,19 +20,19 @@ checkInstalled() { PLUGIN_SLUG="${PLUGIN[0]}" if wp-plugin check "${PLUGIN_SLUG}"; then - echo "> Plugin '${PLUGIN_SLUG}' installed" + echo "Plugin '${PLUGIN_SLUG}' installed" continue fi ((FAILED_COUNT = FAILED_COUNT + 1)) - echo "> Warning: Plugin '${PLUGIN_SLUG}' failed to install" + echo "Warning: Plugin '${PLUGIN_SLUG}' failed to install" done if [ "${FAILED_COUNT}" = "0" ]; then return 0 fi - echo "> Total of ${FAILED_COUNT} plugins failed to install" + echo "Total of ${FAILED_COUNT} plugins failed to install" return 1 } @@ -42,13 +42,13 @@ function taskInstallPlugins() { CONCURRENCY_LIMIT="${WP_PLUGINS_INSTALL_CONCURRENCY:-5}" - echo "> Automated WordPress Plugins Installer" + echo "Automated WordPress Plugins Installer" if [ -z "${PLUGIN_LIST}" ]; then - echo "> No plugins defined. Skipping installation." + echo "No plugins defined. Skipping installation." return 0 fi - echo "> About to install defined plugins" + echo "About to install defined plugins" for PLUGIN_EXPR in ${PLUGIN_LIST}; do # Split plugin name and version @@ -58,15 +58,15 @@ function taskInstallPlugins() { PLUGIN_VERSION="${PLUGIN[1]:-}" if wp-plugin check "${PLUGIN_SLUG}"; then - echo "> Plugin '${PLUGIN_SLUG}' already installed and will be skipped." + echo "Plugin '${PLUGIN_SLUG}' already installed and will be skipped." continue fi if [ -n "${PLUGIN_VERSION}" ]; then - echo "> Installing plugin '${PLUGIN_SLUG}' version '${PLUGIN_VERSION}'" + echo "Installing plugin '${PLUGIN_SLUG}' version '${PLUGIN_VERSION}'" installPlugin "${PLUGIN_SLUG}" "${PLUGIN_VERSION}" & else - echo "> Installing plugin '${PLUGIN_SLUG}'" + echo "Installing plugin '${PLUGIN_SLUG}'" installPlugin "${PLUGIN_SLUG}" & fi @@ -77,28 +77,30 @@ function taskInstallPlugins() { done done - echo "> Waiting for all tasks to finish..." + echo "Waiting for all tasks to finish..." wait # Plugins are installed concurrently, so we need to verify if installed, separately - echo "> About to verify install of defined plugins" + echo "About to verify install of defined plugins" if ! checkInstalled; then - echo "> Some plugins failed to install" + echo "Some plugins failed to install" return 0 fi - echo "> All plugins installed successfully" + echo "All plugins installed successfully" return 0 } -# Main function +# init-install-resources main main() { + exec > >(while read line; do echo "[init-install-resources] ${line}"; done) 2>&1 + PLUGIN_LIST="${WORDPRESS_PLUGIN_LIST:-}" WP_CONTENT_PATH="/var/www/html/wp-content" WP_PLUGINS_PATH="${WP_CONTENT_PATH}/plugins" - echo "> Automated WordPress Resources Installer" + echo "Automated WordPress Resources Installer" export WP_CONTENT_PATH @@ -108,10 +110,9 @@ main() { taskInstallPlugins "${@}" & sleep 1 - echo "> Waiting for all tasks to complete" + echo "Waiting for all tasks to complete" wait return 0 } -main "${@}" -exit $? +main "${@}" \ No newline at end of file diff --git a/rootfs/etc/s6-overlay/s6-rc.d/init-install-resources/type b/rootfs/etc/s6-overlay/s6-rc.d/init-install-resources/type new file mode 100644 index 0000000..3d92b15 --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/init-install-resources/type @@ -0,0 +1 @@ +oneshot \ No newline at end of file diff --git a/rootfs/etc/s6-overlay/s6-rc.d/init-install-resources/up b/rootfs/etc/s6-overlay/s6-rc.d/init-install-resources/up new file mode 100644 index 0000000..3bd9167 --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/init-install-resources/up @@ -0,0 +1 @@ +/etc/s6-overlay/s6-rc.d/init-install-resources/run \ No newline at end of file diff --git a/rootfs/etc/cont-init.d/10-verify-wordpress b/rootfs/etc/s6-overlay/s6-rc.d/init-verify-wordpress/run similarity index 53% rename from rootfs/etc/cont-init.d/10-verify-wordpress rename to rootfs/etc/s6-overlay/s6-rc.d/init-verify-wordpress/run index f58de5a..e8740a9 100755 --- a/rootfs/etc/cont-init.d/10-verify-wordpress +++ b/rootfs/etc/s6-overlay/s6-rc.d/init-verify-wordpress/run @@ -8,11 +8,11 @@ trap scriptExitHandler EXIT function scriptExitHandler() { LAST_EXIT_CODE=$? if [ "${LAST_EXIT_CODE}" = "0" ]; then - echo "> Script finished successfully" + echo "Script finished successfully" exit "${LAST_EXIT_CODE}" fi - echo "> Script finished with an error" + echo "Script finished with an error" exit "${LAST_EXIT_CODE}" } @@ -20,38 +20,40 @@ function reportUnhealthy() { echo "${1:?REASON is required}" >"/tmp/.wp-unhealthy" } -# Main function +# init-verify-wordpress main function main() { + + exec > >(while read line; do echo "[init-verify-wordpress] ${line}"; done) 2>&1 + # Removes trailing zero if found # This is required due to inconsistencies between WodPress docker image versioning and wp-cli core download # If patch version is 0, it is not considered by wp-cli. WP_VERSION=$(echo "${WP_VERSION:?}" | sed --expression='s/.0$//g') - echo "> Verifying 'WordPress ${WP_VERSION}' installation..." + echo "Verifying 'WordPress ${WP_VERSION}' installation..." WP_INSTALLED_VERSION="$(wp core version)" set -e rm -f "/tmp/.wp-unhealthy" if [ -z "${WP_INSTALLED_VERSION}" ]; then - echo "> ERROR! WordPress installation does not seem to be present or valid. Continuing anyway..." + echo "Error: WordPress installation does not seem to be present or valid. Continuing anyway..." reportUnhealthy "WP_NOT_PRESENT" return 0 elif [ "${WP_INSTALLED_VERSION}" != "${WP_VERSION}" ]; then - echo "> WARNING! WordPress version mismatch" - echo " Expected version: ${WP_VERSION}" - echo " Detected version: ${WP_INSTALLED_VERSION}" - echo "> Seems like WordPress installation got updated outside image scope" - echo " - This is dangerous as changes will not persist when container is recreated which might lead to inconsistencies between installation and the database." - echo " - You should assume that recreating the container will render the website inoperable." - echo " - Please make sure that you're running image: nlss/wordpress:${WP_VERSION}" + echo "WARNING! WordPress version mismatch" + echo " Expected version: ${WP_VERSION}" + echo " Detected version: ${WP_INSTALLED_VERSION}" + echo "Seems like WordPress installation got updated outside image scope" + echo " - This is dangerous as changes will not persist when container is recreated which might lead to inconsistencies between installation and the database." + echo " - You should assume that recreating the container will render the website inoperable." + echo " - Please make sure that you're running image: nlss/wordpress:${WP_VERSION}" reportUnhealthy "WP_VERSION_MISMATCH" return 0 else - echo "> Identified 'WordPress ${WP_VERSION}'" + echo "Identified 'WordPress ${WP_VERSION}'" fi } main "${@}" -exit $? diff --git a/rootfs/etc/s6-overlay/s6-rc.d/init-verify-wordpress/type b/rootfs/etc/s6-overlay/s6-rc.d/init-verify-wordpress/type new file mode 100644 index 0000000..3d92b15 --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/init-verify-wordpress/type @@ -0,0 +1 @@ +oneshot \ No newline at end of file diff --git a/rootfs/etc/s6-overlay/s6-rc.d/init-verify-wordpress/up b/rootfs/etc/s6-overlay/s6-rc.d/init-verify-wordpress/up new file mode 100644 index 0000000..28cabdd --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/init-verify-wordpress/up @@ -0,0 +1 @@ +/etc/s6-overlay/s6-rc.d/init-verify-wordpress/run \ No newline at end of file diff --git a/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/init-install-resources b/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/init-install-resources new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/init-verify-wordpress b/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/init-verify-wordpress new file mode 100644 index 0000000..e69de29