From 9f9825fd4c29aa9aaf6efdf8b1f4ad6fbc272b40 Mon Sep 17 00:00:00 2001 From: casjay Date: Sun, 30 Nov 2025 18:27:27 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=97=83=EF=B8=8F=20Update=20codebase=20?= =?UTF-8?q?=F0=9F=97=83=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit rootfs/usr/local/bin/entrypoint.sh rootfs/usr/local/etc/docker/functions/entrypoint.sh --- rootfs/usr/local/bin/entrypoint.sh | 30 ++++-- .../local/etc/docker/functions/entrypoint.sh | 99 ++++++++++++------- 2 files changed, 90 insertions(+), 39 deletions(-) diff --git a/rootfs/usr/local/bin/entrypoint.sh b/rootfs/usr/local/bin/entrypoint.sh index 67b9d67..715a1e9 100755 --- a/rootfs/usr/local/bin/entrypoint.sh +++ b/rootfs/usr/local/bin/entrypoint.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # shellcheck shell=bash # - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202511301200-git +##@Version : 202511301726-git # @@Author : GEN_SCRIPT_REPLACE_AUTHOR # @@Contact : GEN_SCRIPT_REPLACE_EMAIL # @@License : GEN_SCRIPT_REPLACE_LICENSE @@ -21,7 +21,25 @@ # shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2090,SC2115,SC2120,SC2155,SC2199,SC2229,SC2317,SC2329 # - - - - - - - - - - - - - - - - - - - - - - - - - # run trap command on exit -trap 'retVal=$?;[ "$SERVICE_IS_RUNNING" != "yes" ] && [ -f "$SERVICE_PID_FILE" ] && rm -Rf "$SERVICE_PID_FILE";exit $retVal' INT TERM PWR +trap '__trap_exit_handler' EXIT +trap '__trap_signal_handler' INT TERM PWR +# - - - - - - - - - - - - - - - - - - - - - - - - - +__trap_exit_handler() { + local retVal=$? + if [ "$SERVICE_IS_RUNNING" != "yes" ] && [ -f "$SERVICE_PID_FILE" ]; then + rm -Rf "$SERVICE_PID_FILE" 2>/dev/null || true + fi + exit $retVal +} +# - - - - - - - - - - - - - - - - - - - - - - - - - +__trap_signal_handler() { + local retVal=$? + echo "Container received shutdown signal" + if [ "$SERVICE_IS_RUNNING" != "yes" ] && [ -f "$SERVICE_PID_FILE" ]; then + rm -Rf "$SERVICE_PID_FILE" 2>/dev/null || true + fi + exit $retVal +} # - - - - - - - - - - - - - - - - - - - - - - - - - # setup debugging - https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html if [ -f "/config/.debug" ] && [ -z "$DEBUGGER_OPTIONS" ]; then @@ -196,10 +214,10 @@ if [ -n "$CONTAINER_WEB_SERVER_WWW_REPO" ]; then fi # - - - - - - - - - - - - - - - - - - - - - - - - - # variables based on env/files -[ -f "/config/enable/ssl" ] && SSL_ENABLED="yes" -[ -f "/config/enable/ssh" ] && SSH_ENABLED="yes" -[ "$WEB_SERVER_PORT" = "443" ] && SSL_ENABLED="yes" -[ "$CONTAINER_WEB_SERVER_PROTOCOL" = "https" ] && SSL_ENABLED="yes" +if [ -f "/config/enable/ssl" ]; then SSL_ENABLED="yes"; fi +if [ -f "/config/enable/ssh" ]; then SSH_ENABLED="yes"; fi +if [ "$WEB_SERVER_PORT" = "443" ]; then SSL_ENABLED="yes"; fi +if [ "$CONTAINER_WEB_SERVER_PROTOCOL" = "https" ]; then SSL_ENABLED="yes"; fi # - - - - - - - - - - - - - - - - - - - - - - - - - # export variables diff --git a/rootfs/usr/local/etc/docker/functions/entrypoint.sh b/rootfs/usr/local/etc/docker/functions/entrypoint.sh index d41e492..7c3b4f6 100644 --- a/rootfs/usr/local/etc/docker/functions/entrypoint.sh +++ b/rootfs/usr/local/etc/docker/functions/entrypoint.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # shellcheck shell=bash # - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202511301145-git +##@Version : 202511301726-git # @@Author : Jason Hempstead # @@Contact : git-admin@casjaysdev.pro # @@License : LICENSE.md @@ -166,13 +166,31 @@ __find_and_remove() { __pgrep() { local count=3 local srvc="${1:-SERVICE_NAME}" + local found=0 + if [ -z "$srvc" ] || [ "$srvc" = "SERVICE_NAME" ]; then + return 10 + fi while [ $count -ge 0 ]; do - # Use exact process name matching, not full command line search - pgrep -x "$srvc" >/dev/null 2>&1 && return 0 - sleep 1 + if pgrep -x "$srvc" >/dev/null 2>&1; then + found=1 + break + elif pgrep -f "$srvc" >/dev/null 2>&1; then + found=1 + break + elif ps -ef 2>/dev/null | grep -v grep | grep -qw "$srvc"; then + found=1 + break + fi + if [ $count -gt 0 ]; then + sleep 1 + fi count=$((count - 1)) done - return 10 + if [ $found -eq 1 ]; then + return 0 + else + return 10 + fi } # - - - - - - - - - - - - - - - - - - - - - - - - - __find_file_relative() { @@ -766,11 +784,27 @@ __check_for_group() { cat "/etc/group" 2>/dev/null | awk -F ':' '{print $1}' | s # - - - - - - - - - - - - - - - - - - - - - - - - - # check if process is already running __proc_check() { - cmd_bin="$(type -P "${1:-$EXEC_CMD_BIN}")" - cmd_name="$(basename "${cmd_bin:-$EXEC_CMD_NAME}")" - if __pgrep "$cmd_bin" || __pgrep "$cmd_name"; then + local cmd_bin cmd_name check_result + cmd_bin="$(type -P "${1:-$EXEC_CMD_BIN}" 2>/dev/null || echo "${1:-$EXEC_CMD_BIN}")" + cmd_name="$(basename "${cmd_bin:-${1:-$EXEC_CMD_NAME}}" 2>/dev/null)" + if [ -z "$cmd_name" ] || [ "$cmd_name" = "." ]; then + return 1 + fi + check_result=1 + if [ -n "$cmd_bin" ] && __pgrep "$cmd_bin" 2>/dev/null; then + check_result=0 + elif [ -n "$cmd_name" ] && __pgrep "$cmd_name" 2>/dev/null; then + check_result=0 + elif [ -f "$SERVICE_PID_FILE" ]; then + local pid_from_file + pid_from_file="$(cat "$SERVICE_PID_FILE" 2>/dev/null || echo "")" + if [ -n "$pid_from_file" ] && kill -0 "$pid_from_file" 2>/dev/null; then + check_result=0 + fi + fi + if [ $check_result -eq 0 ]; then SERVICE_IS_RUNNING="yes" - touch "$SERVICE_PID_FILE" + touch "$SERVICE_PID_FILE" 2>/dev/null || true return 0 else return 1 @@ -1041,31 +1075,28 @@ __start_init_scripts() { __service_banner "✅" "Service $service completed successfully -" "configuration service" else # Allow some time for service to initialize - sleep 1 + sleep 2 # Check for service success indicators local expected_pid_file="/run/init.d/$service.pid" + set +e if [ "$SERVICE_USES_PID" = "no" ]; then - # Service doesn't use PID files - check if expected PID file exists or assume success - if [ -f "$expected_pid_file" ]; then - retPID="$(cat "$expected_pid_file" 2>/dev/null || echo "0")" - initStatus="0" - __service_banner "✅" "Service $service started successfully -" "PID file" - else - initStatus="0" - __service_banner "✅" "Service $service started successfully -" "no PID tracking" - fi + # Service doesn't use PID files - assume success unless explicitly failed + initStatus="0" + __service_banner "✅" "Service $service completed successfully -" "no PID tracking required" else # Service uses PID tracking - verify actual running processes - set +e # Temporarily disable exit on error retPID="" - # First, try to find actual running process with various name patterns + local found_process="" + # Try multiple name variants to find the process for name_variant in "$service" "${service}84" "${service}d" "$(echo "$service" | sed 's/-//g')" "$(echo "$service" | tr -d '-')"; do if [ -z "$retPID" ]; then retPID=$(__get_pid "$name_variant" 2>/dev/null || echo "") - [ -n "$retPID" ] && found_process="$name_variant" && break + if [ -n "$retPID" ] && [ "$retPID" != "0" ]; then + found_process="$name_variant" + break + fi fi done - set -e # Re-enable exit on error if [ -n "$retPID" ] && [ "$retPID" != "0" ]; then # Found actual running process initStatus="0" @@ -1076,20 +1107,18 @@ __start_init_scripts() { if [ -n "$file_pid" ] && kill -0 "$file_pid" 2>/dev/null; then initStatus="0" __service_banner "✅" "Service $service started successfully -" "PID: $file_pid (from file)" - elif [ -n "$file_pid" ]; then - initStatus="1" - critical_failures=$((critical_failures + 1)) - __service_banner "⚠️" "Service $service has stale PID file -" "process $file_pid not running" else + # PID file exists but process isn't running - treat as warning, not failure initStatus="0" - __service_banner "✅" "Service $service completed initialization -" "no process tracking" + __service_banner "⚠️" "Service $service may not be running -" "no process found (non-critical)" fi else - # No process and no PID file - this is likely a configuration-only service + # No process and no PID file - likely a configuration-only service initStatus="0" __service_banner "✅" "Service $service completed successfully -" "configuration service" fi fi + set -e fi else initStatus="1" @@ -1102,15 +1131,19 @@ __start_init_scripts() { done # Summary + echo "" if [ $critical_failures -gt 0 ]; then - echo "⚠️ Warning: $critical_failures service(s) failed to start" - if [ "$exit_on_failure" = "true" ] && [ $critical_failures -ge 1 ]; then - echo "❌ Exiting due to critical service failures" + echo "⚠️ Warning: $critical_failures critical service(s) reported failures" + if [ "$exit_on_failure" = "true" ] && [ $critical_failures -ge 2 ]; then + echo "❌ Exiting due to multiple critical service failures (threshold: 2)" return 1 + else + echo "ℹ️ Continuing with $critical_failures failure(s) - container may still be functional" fi else - echo "✅ All services started successfully" + echo "✅ All service initializations completed successfully" fi + echo "" fi fi