Skip to content

Commit 7c2eb91

Browse files
committed
๐Ÿ—ƒ๏ธ Update codebase ๐Ÿ—ƒ๏ธ
rootfs/usr/local/bin/entrypoint.sh rootfs/usr/local/etc/docker/functions/entrypoint.sh
1 parent 9a96d0e commit 7c2eb91

File tree

2 files changed

+86
-35
lines changed

2 files changed

+86
-35
lines changed

โ€Žrootfs/usr/local/bin/entrypoint.shโ€Ž

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
# shellcheck shell=bash
33
# - - - - - - - - - - - - - - - - - - - - - - - - -
4-
##@Version : 202511301200-git
4+
##@Version : 202511301726-git
55
# @@Author : GEN_SCRIPT_REPLACE_AUTHOR
66
# @@Contact : GEN_SCRIPT_REPLACE_EMAIL
77
# @@License : GEN_SCRIPT_REPLACE_LICENSE
@@ -21,7 +21,25 @@
2121
# shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2090,SC2115,SC2120,SC2155,SC2199,SC2229,SC2317,SC2329
2222
# - - - - - - - - - - - - - - - - - - - - - - - - -
2323
# run trap command on exit
24-
trap 'retVal=$?;[ "$SERVICE_IS_RUNNING" != "yes" ] && [ -f "$SERVICE_PID_FILE" ] && rm -Rf "$SERVICE_PID_FILE";exit $retVal' INT TERM PWR
24+
trap '__trap_exit_handler' EXIT
25+
trap '__trap_signal_handler' INT TERM PWR
26+
# - - - - - - - - - - - - - - - - - - - - - - - - -
27+
__trap_exit_handler() {
28+
local retVal=$?
29+
if [ "$SERVICE_IS_RUNNING" != "yes" ] && [ -f "$SERVICE_PID_FILE" ]; then
30+
rm -Rf "$SERVICE_PID_FILE" 2>/dev/null || true
31+
fi
32+
exit $retVal
33+
}
34+
# - - - - - - - - - - - - - - - - - - - - - - - - -
35+
__trap_signal_handler() {
36+
local retVal=$?
37+
echo "Container received shutdown signal"
38+
if [ "$SERVICE_IS_RUNNING" != "yes" ] && [ -f "$SERVICE_PID_FILE" ]; then
39+
rm -Rf "$SERVICE_PID_FILE" 2>/dev/null || true
40+
fi
41+
exit $retVal
42+
}
2543
# - - - - - - - - - - - - - - - - - - - - - - - - -
2644
# setup debugging - https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
2745
if [ -f "/config/.debug" ] && [ -z "$DEBUGGER_OPTIONS" ]; then

โ€Žrootfs/usr/local/etc/docker/functions/entrypoint.shโ€Ž

Lines changed: 66 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
# shellcheck shell=bash
33
# - - - - - - - - - - - - - - - - - - - - - - - - -
4-
##@Version : 202511301145-git
4+
##@Version : 202511301726-git
55
# @@Author : Jason Hempstead
66
# @@Contact : [email protected]
77
# @@License : LICENSE.md
@@ -166,13 +166,31 @@ __find_and_remove() {
166166
__pgrep() {
167167
local count=3
168168
local srvc="${1:-SERVICE_NAME}"
169+
local found=0
170+
if [ -z "$srvc" ] || [ "$srvc" = "SERVICE_NAME" ]; then
171+
return 10
172+
fi
169173
while [ $count -ge 0 ]; do
170-
# Use exact process name matching, not full command line search
171-
pgrep -x "$srvc" >/dev/null 2>&1 && return 0
172-
sleep 1
174+
if pgrep -x "$srvc" >/dev/null 2>&1; then
175+
found=1
176+
break
177+
elif pgrep -f "$srvc" >/dev/null 2>&1; then
178+
found=1
179+
break
180+
elif ps -ef 2>/dev/null | grep -v grep | grep -qw "$srvc"; then
181+
found=1
182+
break
183+
fi
184+
if [ $count -gt 0 ]; then
185+
sleep 1
186+
fi
173187
count=$((count - 1))
174188
done
175-
return 10
189+
if [ $found -eq 1 ]; then
190+
return 0
191+
else
192+
return 10
193+
fi
176194
}
177195
# - - - - - - - - - - - - - - - - - - - - - - - - -
178196
__find_file_relative() {
@@ -766,11 +784,27 @@ __check_for_group() { cat "/etc/group" 2>/dev/null | awk -F ':' '{print $1}' | s
766784
# - - - - - - - - - - - - - - - - - - - - - - - - -
767785
# check if process is already running
768786
__proc_check() {
769-
cmd_bin="$(type -P "${1:-$EXEC_CMD_BIN}")"
770-
cmd_name="$(basename "${cmd_bin:-$EXEC_CMD_NAME}")"
771-
if __pgrep "$cmd_bin" || __pgrep "$cmd_name"; then
787+
local cmd_bin cmd_name check_result
788+
cmd_bin="$(type -P "${1:-$EXEC_CMD_BIN}" 2>/dev/null || echo "${1:-$EXEC_CMD_BIN}")"
789+
cmd_name="$(basename "${cmd_bin:-${1:-$EXEC_CMD_NAME}}" 2>/dev/null)"
790+
if [ -z "$cmd_name" ] || [ "$cmd_name" = "." ]; then
791+
return 1
792+
fi
793+
check_result=1
794+
if [ -n "$cmd_bin" ] && __pgrep "$cmd_bin" 2>/dev/null; then
795+
check_result=0
796+
elif [ -n "$cmd_name" ] && __pgrep "$cmd_name" 2>/dev/null; then
797+
check_result=0
798+
elif [ -f "$SERVICE_PID_FILE" ]; then
799+
local pid_from_file
800+
pid_from_file="$(cat "$SERVICE_PID_FILE" 2>/dev/null || echo "")"
801+
if [ -n "$pid_from_file" ] && kill -0 "$pid_from_file" 2>/dev/null; then
802+
check_result=0
803+
fi
804+
fi
805+
if [ $check_result -eq 0 ]; then
772806
SERVICE_IS_RUNNING="yes"
773-
touch "$SERVICE_PID_FILE"
807+
touch "$SERVICE_PID_FILE" 2>/dev/null || true
774808
return 0
775809
else
776810
return 1
@@ -1041,31 +1075,28 @@ __start_init_scripts() {
10411075
__service_banner "โœ…" "Service $service completed successfully -" "configuration service"
10421076
else
10431077
# Allow some time for service to initialize
1044-
sleep 1
1078+
sleep 2
10451079
# Check for service success indicators
10461080
local expected_pid_file="/run/init.d/$service.pid"
1081+
set +e
10471082
if [ "$SERVICE_USES_PID" = "no" ]; then
1048-
# Service doesn't use PID files - check if expected PID file exists or assume success
1049-
if [ -f "$expected_pid_file" ]; then
1050-
retPID="$(cat "$expected_pid_file" 2>/dev/null || echo "0")"
1051-
initStatus="0"
1052-
__service_banner "โœ…" "Service $service started successfully -" "PID file"
1053-
else
1054-
initStatus="0"
1055-
__service_banner "โœ…" "Service $service started successfully -" "no PID tracking"
1056-
fi
1083+
# Service doesn't use PID files - assume success unless explicitly failed
1084+
initStatus="0"
1085+
__service_banner "โœ…" "Service $service completed successfully -" "no PID tracking required"
10571086
else
10581087
# Service uses PID tracking - verify actual running processes
1059-
set +e # Temporarily disable exit on error
10601088
retPID=""
1061-
# First, try to find actual running process with various name patterns
1089+
local found_process=""
1090+
# Try multiple name variants to find the process
10621091
for name_variant in "$service" "${service}84" "${service}d" "$(echo "$service" | sed 's/-//g')" "$(echo "$service" | tr -d '-')"; do
10631092
if [ -z "$retPID" ]; then
10641093
retPID=$(__get_pid "$name_variant" 2>/dev/null || echo "")
1065-
[ -n "$retPID" ] && found_process="$name_variant" && break
1094+
if [ -n "$retPID" ] && [ "$retPID" != "0" ]; then
1095+
found_process="$name_variant"
1096+
break
1097+
fi
10661098
fi
10671099
done
1068-
set -e # Re-enable exit on error
10691100
if [ -n "$retPID" ] && [ "$retPID" != "0" ]; then
10701101
# Found actual running process
10711102
initStatus="0"
@@ -1076,20 +1107,18 @@ __start_init_scripts() {
10761107
if [ -n "$file_pid" ] && kill -0 "$file_pid" 2>/dev/null; then
10771108
initStatus="0"
10781109
__service_banner "โœ…" "Service $service started successfully -" "PID: $file_pid (from file)"
1079-
elif [ -n "$file_pid" ]; then
1080-
initStatus="1"
1081-
critical_failures=$((critical_failures + 1))
1082-
__service_banner "โš ๏ธ" "Service $service has stale PID file -" "process $file_pid not running"
10831110
else
1111+
# PID file exists but process isn't running - treat as warning, not failure
10841112
initStatus="0"
1085-
__service_banner "โœ…" "Service $service completed initialization -" "no process tracking"
1113+
__service_banner "โš ๏ธ" "Service $service may not be running -" "no process found (non-critical)"
10861114
fi
10871115
else
1088-
# No process and no PID file - this is likely a configuration-only service
1116+
# No process and no PID file - likely a configuration-only service
10891117
initStatus="0"
10901118
__service_banner "โœ…" "Service $service completed successfully -" "configuration service"
10911119
fi
10921120
fi
1121+
set -e
10931122
fi
10941123
else
10951124
initStatus="1"
@@ -1102,15 +1131,19 @@ __start_init_scripts() {
11021131
done
11031132

11041133
# Summary
1134+
echo ""
11051135
if [ $critical_failures -gt 0 ]; then
1106-
echo "โš ๏ธ Warning: $critical_failures service(s) failed to start"
1107-
if [ "$exit_on_failure" = "true" ] && [ $critical_failures -ge 1 ]; then
1108-
echo "โŒ Exiting due to critical service failures"
1136+
echo "โš ๏ธ Warning: $critical_failures critical service(s) reported failures"
1137+
if [ "$exit_on_failure" = "true" ] && [ $critical_failures -ge 2 ]; then
1138+
echo "โŒ Exiting due to multiple critical service failures (threshold: 2)"
11091139
return 1
1140+
else
1141+
echo "โ„น๏ธ Continuing with $critical_failures failure(s) - container may still be functional"
11101142
fi
11111143
else
1112-
echo "โœ… All services started successfully"
1144+
echo "โœ… All service initializations completed successfully"
11131145
fi
1146+
echo ""
11141147
fi
11151148
fi
11161149

0 commit comments

Comments
ย (0)