Skip to content

Commit

Permalink
[5.x] Improve autorun and sorting environment variables (#102)
Browse files Browse the repository at this point in the history
* [5.x] Improve autorun and sorting environment variables

* [5.x] Rewrite examples
  • Loading branch information
shinsenter authored Aug 10, 2024
1 parent 6e9c735 commit f8fefe9
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 1 addition & 3 deletions src/php/base-os.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/php/common/rootfs/etc/cont-init.d/99-other-fixes
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 10 additions & 6 deletions src/php/common/rootfs/usr/local/sbin/autorun
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/php/common/rootfs/usr/local/sbin/env-default
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions src/php/common/rootfs/usr/local/sbin/with-env
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"
2 changes: 1 addition & 1 deletion src/php/common/shell-php/php-envvars
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit f8fefe9

Please sign in to comment.