From a8e5593b36f9485ee125ff8f97689edb55ba05d1 Mon Sep 17 00:00:00 2001 From: adamiBs Date: Sat, 14 Sep 2024 09:55:26 +0300 Subject: [PATCH] Improve docker-entrypoint.sh scripts - Provide preliminary checks for the modules, with appropriate warning messages. This is to support entry command overrides. https://github.com/docker-library/official-images/pull/17549#issuecomment-2350726819 --- alpine/docker-entrypoint.sh | 37 +++++++++++++++++++++++++++++++------ debian/docker-entrypoint.sh | 37 +++++++++++++++++++++++++++++++------ 2 files changed, 62 insertions(+), 12 deletions(-) diff --git a/alpine/docker-entrypoint.sh b/alpine/docker-entrypoint.sh index 77e274f9..114e094d 100755 --- a/alpine/docker-entrypoint.sh +++ b/alpine/docker-entrypoint.sh @@ -21,14 +21,39 @@ if [ "$um" = '0022' ]; then umask 0077 fi -modules_dir="/usr/local/lib/redis/modules/" command="exec \"\$@\"" +if [ "$1" = 'redis-server' ]; then + echo "Starting Redis Server" + modules_dir="/usr/local/lib/redis/modules/" + + if [ ! -d "$modules_dir" ]; then + echo "Warning: Default Redis modules directory $modules_dir does not exist." + elif [ -n "$(ls -A $modules_dir 2>/dev/null)" ]; then + for module in "$modules_dir"/*.so; + do + if [ ! -s "$module" ]; then + echo "Skipping module $module: file has no size." + continue + fi + + if [ -d "$module" ]; then + echo "Skipping module $module: is a directory." + continue + fi + + if [ ! -r "$module" ]; then + echo "Skipping module $module: file is not readable." + continue + fi -if [ -n "$(ls -A $modules_dir)" ]; then - for module in "$modules_dir"/*.so; - do - command="$command --loadmodule $module" - done + if [ ! -x "$module" ]; then + echo "Warning: Module $module is not executable." + fi + + command="$command --loadmodule $module" + done + fi fi + eval "$command" \ No newline at end of file diff --git a/debian/docker-entrypoint.sh b/debian/docker-entrypoint.sh index 77e274f9..114e094d 100755 --- a/debian/docker-entrypoint.sh +++ b/debian/docker-entrypoint.sh @@ -21,14 +21,39 @@ if [ "$um" = '0022' ]; then umask 0077 fi -modules_dir="/usr/local/lib/redis/modules/" command="exec \"\$@\"" +if [ "$1" = 'redis-server' ]; then + echo "Starting Redis Server" + modules_dir="/usr/local/lib/redis/modules/" + + if [ ! -d "$modules_dir" ]; then + echo "Warning: Default Redis modules directory $modules_dir does not exist." + elif [ -n "$(ls -A $modules_dir 2>/dev/null)" ]; then + for module in "$modules_dir"/*.so; + do + if [ ! -s "$module" ]; then + echo "Skipping module $module: file has no size." + continue + fi + + if [ -d "$module" ]; then + echo "Skipping module $module: is a directory." + continue + fi + + if [ ! -r "$module" ]; then + echo "Skipping module $module: file is not readable." + continue + fi -if [ -n "$(ls -A $modules_dir)" ]; then - for module in "$modules_dir"/*.so; - do - command="$command --loadmodule $module" - done + if [ ! -x "$module" ]; then + echo "Warning: Module $module is not executable." + fi + + command="$command --loadmodule $module" + done + fi fi + eval "$command" \ No newline at end of file