From f8fefe93d97d8f2a8c8b51729a9a7f95bcf74b89 Mon Sep 17 00:00:00 2001 From: Shin <2082119+shinsenter@users.noreply.github.com> Date: Sat, 10 Aug 2024 14:44:36 +0900 Subject: [PATCH] [5.x] Improve autorun and sorting environment variables (#102) * [5.x] Improve autorun and sorting environment variables * [5.x] Rewrite examples --- README.md | 4 +--- src/php/base-os.md | 4 +--- .../common/rootfs/etc/cont-init.d/99-other-fixes | 2 +- src/php/common/rootfs/usr/local/sbin/autorun | 16 ++++++++++------ src/php/common/rootfs/usr/local/sbin/env-default | 2 +- src/php/common/rootfs/usr/local/sbin/with-env | 10 +++++----- src/php/common/shell-php/php-envvars | 2 +- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index ba674737..c8066d31 100644 --- a/README.md +++ b/README.md @@ -393,9 +393,7 @@ services: image: shinsenter/php:8.3-fpm-nginx environment: ENABLE_CRONTAB: "1" - CRONTAB_SETTINGS: | - 0 0 * * * echo "Hello new day!" | tee /tmp/cron-daily.txt - * * * * * echo "This line will run every minute!" | tee /tmp/cron-every-minute.txt + CRONTAB_SETTINGS: "* * * * * echo 'This line will run every minute!' | tee /tmp/cron-every-minute.txt" ``` For more information on environment variables for cron jobs, refer to the [Other System Settings](#other-system-settings) section below. diff --git a/src/php/base-os.md b/src/php/base-os.md index 4a95c894..93452104 100644 --- a/src/php/base-os.md +++ b/src/php/base-os.md @@ -189,9 +189,7 @@ services: image: shinsenter/php:8.3-fpm-nginx environment: ENABLE_CRONTAB: "1" - CRONTAB_SETTINGS: | - 0 0 * * * echo "Hello new day!" | tee /tmp/cron-daily.txt - * * * * * echo "This line will run every minute!" | tee /tmp/cron-every-minute.txt + CRONTAB_SETTINGS: "* * * * * echo 'This line will run every minute!' | tee /tmp/cron-every-minute.txt" ``` For more information on environment variables for cron jobs, refer to the [Other System Settings](#other-system-settings) section below. diff --git a/src/php/common/rootfs/etc/cont-init.d/99-other-fixes b/src/php/common/rootfs/etc/cont-init.d/99-other-fixes index c6f3a23a..cab8b1a5 100755 --- a/src/php/common/rootfs/etc/cont-init.d/99-other-fixes +++ b/src/php/common/rootfs/etc/cont-init.d/99-other-fixes @@ -13,7 +13,7 @@ APP_ROOT="$(app-root)" ################################################################################ # cache environment variables for other processes -mkdir -p /etc/default && with-env | sort >/etc/default/locale +mkdir -p /etc/default && with-env >/etc/default/locale # fix .htaccess to allow uri path after index.php if [ -f "$APP_ROOT/.htaccess" ]; then diff --git a/src/php/common/rootfs/usr/local/sbin/autorun b/src/php/common/rootfs/usr/local/sbin/autorun index 861828a8..4badd904 100755 --- a/src/php/common/rootfs/usr/local/sbin/autorun +++ b/src/php/common/rootfs/usr/local/sbin/autorun @@ -12,11 +12,15 @@ for dir; do debug-echo "\nScanning autorun scripts in $dir" find $dir -type f -name '*.sh' | xargs -r chmod +x 2>&1 >/dev/null - for script in $(find $dir -type f -perm -111 | sort -dbfi); do - if [ -x "$script" ]; then - debug-echo "\nAutorun $script" - with-env "$script" - fi - done + if ! has-cmd run-parts; then + for script in $(find $dir -type f -perm -111 | sort -dbfi); do + if [ -x "$script" ]; then + debug-echo "\nAutorun $script" + with-env "$script" + fi + done + else + with-env run-parts "$dir" + fi fi done diff --git a/src/php/common/rootfs/usr/local/sbin/env-default b/src/php/common/rootfs/usr/local/sbin/env-default index 8a3a6f05..cde94ef9 100755 --- a/src/php/common/rootfs/usr/local/sbin/env-default +++ b/src/php/common/rootfs/usr/local/sbin/env-default @@ -25,7 +25,7 @@ export PATH="$NEW_PATH" fi if [ $# -eq 0 ]; then - source $conf_path && env | sort -dbfi + source $conf_path && env -0 | sort -dbfiz | tr '\0' '\n' exit fi diff --git a/src/php/common/rootfs/usr/local/sbin/with-env b/src/php/common/rootfs/usr/local/sbin/with-env index 188ab34a..4f436468 100755 --- a/src/php/common/rootfs/usr/local/sbin/with-env +++ b/src/php/common/rootfs/usr/local/sbin/with-env @@ -20,10 +20,10 @@ fi if [ "$ENV" != "$DEFAULT_ENV" ] && [ -x "$DEFAULT_ENV" ]; then source "$DEFAULT_ENV"; fi if [ -x "$ENV" ]; then source "$ENV"; fi -# set the default command if [ $# -eq 0 ]; then - set -- "$(command -v env)" + # print the environment variables when no command is given + exec env -0 | sort -dbfiz | tr '\0' '\n' +else + # execute the command + exec "$@" fi - -# run the command with loaded env variables -exec "$@" diff --git a/src/php/common/shell-php/php-envvars b/src/php/common/shell-php/php-envvars index c06860b9..32c2153e 100755 --- a/src/php/common/shell-php/php-envvars +++ b/src/php/common/shell-php/php-envvars @@ -150,7 +150,7 @@ final class DockerPHP } // Cache environment variables - run('mkdir -p /etc/default && with-env | sort >/etc/default/locale'); + run('mkdir -p /etc/default && with-env >/etc/default/locale'); } public function write_static_config()