mirror of
https://github.com/casjaysdevdocker/postfix
synced 2025-09-20 15:57:43 -04:00
🗃️ Committing everything that changed 🗃️
Some checks failed
release-tag / release-image (push) Failing after 17s
Some checks failed
release-tag / release-image (push) Failing after 17s
rootfs/usr/local/etc/docker/functions/entrypoint.sh rootfs/usr/local/etc/docker/init.d/01-postfix.sh rootfs/usr/local/etc/docker/init.d/09-supervisord.sh
This commit is contained in:
@@ -45,7 +45,7 @@ __cd() { { [ -d "$1" ] || mkdir -p "$1"; } && builtin cd "$1" || return 1; }
|
||||
__is_in_file() { [ -e "$2" ] && grep -Rsq "$1" "$2" && return 0 || return 1; }
|
||||
__curl() { curl -q -sfI --max-time 3 -k -o /dev/null "$@" &>/dev/null || return 10; }
|
||||
__find() { find "$1" -mindepth 1 -type ${2:-f,d} 2>/dev/null | grep '.' || return 10; }
|
||||
__pcheck() { [ -n "$(which pgrep 2>/dev/null)" ] && pgrep -o "$1$" &>/dev/null || return 10; }
|
||||
__pcheck() { [ -n "$(which pgrep 2>/dev/null)" ] && pgrep -x "$1" &>/dev/null || return 10; }
|
||||
__file_exists_with_content() { [ -n "$1" ] && [ -f "$1" ] && [ -s "$1" ] && return 0 || return 2; }
|
||||
__sed() { sed -i 's|'$1'|'$2'|g' "$3" &>/dev/null || sed -i "s|$1|$2|g" "$3" &>/dev/null || return 1; }
|
||||
__ps() { [ -f "$(type -P ps)" ] && ps "$@" 2>/dev/null | sed 's|:||g' | grep -Fw " ${1:-$SERVICE_NAME}$" || return 10; }
|
||||
@@ -57,11 +57,12 @@ __pgrep() {
|
||||
local count=3
|
||||
local srvc="${1:-SERVICE_NAME}"
|
||||
while [ $count -ge 0 ]; do
|
||||
__pcheck "${1:-SERVICE_NAME}" || __ps "${1:-$SERVICE_NAME}" | grep -qv ' grep'
|
||||
# Use exact process name matching, not full command line search
|
||||
pgrep -x "$srvc" >/dev/null 2>&1 && return 0
|
||||
sleep 1
|
||||
count=$((count - 1))
|
||||
done
|
||||
[ $count -ne 0 ] && return 0 || return 10
|
||||
return 10
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__find_file_relative() {
|
||||
@@ -74,9 +75,26 @@ __find_directory_relative() {
|
||||
find "$1"/* -not -path '*env/*' -not -path '.git*' -type d 2>/dev/null | sed 's|'$1'/||g' | sort -u | grep -v '^$' | grep '.' || false
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__pid_exists() { ps -ax --no-header | sed 's/^[[:space:]]*//g' | awk -F' ' '{print $1}' | sed 's|:||g' | grep '[0-9]' | sort -uV | grep "^$1$" && return 0 || return 1; }
|
||||
__is_running() { ps -eo args --no-header | awk '{print $1,$2,$3}' | sed 's|:||g' | sort -u | grep -vE 'grep|COMMAND|awk|tee|ps|sed|sort|tail' | grep "$1" | grep -q "${2:-^}" && return 0 || return 1; }
|
||||
__get_pid() { ps -ax --no-header | sed 's/^[[:space:]]*//g;s|;||g;s|:||g' | awk '{print $1,$5}' | sed 's|:||g' | grep "$1$" | grep -v 'grep' | awk -F' ' '{print $1}' | grep '[0-9]' | sort -uV | head -n1 | grep '.' && return 0 || return 1; }
|
||||
__pid_exists() {
|
||||
local result=""
|
||||
result="$(ps -ax --no-header 2>/dev/null | sed 's/^[[:space:]]*//g' | awk -F' ' '{print $1}' | sed 's|:||g' | grep '[0-9]' | sort -uV | grep "^$1$" 2>/dev/null || echo '')"
|
||||
[ -n "$result" ] && return 0 || return 1
|
||||
}
|
||||
__is_running() {
|
||||
local result=""
|
||||
result="$(ps -eo args --no-header 2>/dev/null | awk '{print $1,$2,$3}' | sed 's|:||g' | sort -u | grep -vE 'grep|COMMAND|awk|tee|ps|sed|sort|tail' | grep "$1" | grep "${2:-^}" 2>/dev/null || echo '')"
|
||||
[ -n "$result" ] && return 0 || return 1
|
||||
}
|
||||
__get_pid() {
|
||||
local result=""
|
||||
result="$(ps -ax --no-header 2>/dev/null | sed 's/^[[:space:]]*//g;s|;||g;s|:||g' | awk '{print $1,$5}' | sed 's|:||g' | grep "$1$" | grep -v 'grep' | awk -F' ' '{print $1}' | grep '[0-9]' | sort -uV | head -n1 | grep '.' 2>/dev/null || echo '')"
|
||||
if [ -n "$result" ]; then
|
||||
echo "$result"
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__format_variables() { printf '%s\n' "${@//,/ }" | tr ' ' '\n' | sort -RVu | grep -v '^$' | tr '\n' ' ' | __clean_variables | grep '.' || return 0; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
@@ -577,7 +595,6 @@ __proc_check() {
|
||||
if __pgrep "$cmd_bin" || __pgrep "$cmd_name"; then
|
||||
SERVICE_IS_RUNNING="yes"
|
||||
touch "$SERVICE_PID_FILE"
|
||||
echo "$cmd_name is already running"
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
@@ -777,19 +794,42 @@ __start_init_scripts() {
|
||||
__service_banner "✅" "Service $service started successfully -" "no PID tracking"
|
||||
fi
|
||||
else
|
||||
# Service uses PID tracking - get actual PID
|
||||
retPID=$(__get_pid "$service")
|
||||
# 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
|
||||
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
|
||||
fi
|
||||
done
|
||||
|
||||
set -e # Re-enable exit on error
|
||||
|
||||
if [ -n "$retPID" ] && [ "$retPID" != "0" ]; then
|
||||
# Found actual running process
|
||||
initStatus="0"
|
||||
__service_banner "✅" "Service $service started successfully -" "PID: ${retPID}"
|
||||
__service_banner "✅" "Service $service started successfully -" "PID: ${retPID} ($found_process)"
|
||||
elif [ -f "$expected_pid_file" ]; then
|
||||
retPID="$(cat "$expected_pid_file" 2>/dev/null || echo "0")"
|
||||
# No running process but PID file exists - verify PID is valid
|
||||
file_pid="$(cat "$expected_pid_file" 2>/dev/null || echo "")"
|
||||
if [ -n "$file_pid" ] && kill -0 "$file_pid" 2>/dev/null; then
|
||||
initStatus="0"
|
||||
__service_banner "✅" "Service $service started successfully -" "PID file"
|
||||
else
|
||||
__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 appears to have started but" "no process found"
|
||||
__service_banner "⚠️" "Service $service has stale PID file -" "process $file_pid not running"
|
||||
else
|
||||
initStatus="0"
|
||||
__service_banner "✅" "Service $service completed initialization -" "no process tracking"
|
||||
fi
|
||||
else
|
||||
# No process and no PID file - this is likely a configuration-only service
|
||||
initStatus="0"
|
||||
__service_banner "✅" "Service $service completed successfully -" "configuration service"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
26
rootfs/usr/local/etc/docker/init.d/01-postfix.sh
Executable file → Normal file
26
rootfs/usr/local/etc/docker/init.d/01-postfix.sh
Executable file → Normal file
@@ -31,13 +31,25 @@ export PATH="/usr/local/etc/docker/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/s
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
SCRIPT_FILE="$0"
|
||||
SERVICE_NAME="postfix"
|
||||
# Function to exit appropriately based on context
|
||||
__script_exit() {
|
||||
local exit_code="${1:-0}"
|
||||
if [ "${BASH_SOURCE[0]}" != "${0}" ]; then
|
||||
# Script is being sourced - use return
|
||||
return "$exit_code"
|
||||
else
|
||||
# Script is being executed - use exit
|
||||
exit "$exit_code"
|
||||
fi
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
SCRIPT_NAME="$(basename -- "$SCRIPT_FILE" 2>/dev/null)"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# exit if __start_init_scripts function hasn't been Initialized
|
||||
if [ ! -f "/run/__start_init_scripts.pid" ]; then
|
||||
echo "__start_init_scripts function hasn't been Initialized" >&2
|
||||
SERVICE_IS_RUNNING="no"
|
||||
exit 1
|
||||
__script_exit 1
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# import the functions file
|
||||
@@ -50,8 +62,6 @@ for set_env in "/root/env.sh" "/usr/local/etc/docker/env"/*.sh "/config/env"/*.s
|
||||
[ -f "$set_env" ] && . "$set_env"
|
||||
done
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
printf '%s\n' "# - - - Initializing $SERVICE_NAME - - - #"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Custom functions
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
@@ -208,7 +218,7 @@ __run_pre_execute_checks() {
|
||||
if [ $exitStatus -ne 0 ]; then
|
||||
echo "The pre-execution check has failed" >&2
|
||||
[ -f "$SERVICE_PID_FILE" ] && rm -Rf "$SERVICE_PID_FILE"
|
||||
exit 1
|
||||
__script_exit 1
|
||||
fi
|
||||
# allow custom functions
|
||||
if builtin type -t __run_pre_execute_checks_local | grep -q 'function'; then __run_pre_execute_checks_local; fi
|
||||
@@ -400,7 +410,7 @@ __run_start_script() {
|
||||
__post_execute 2>"/dev/stderr" | tee -p -a "/data/logs/init.txt"
|
||||
retVal=$?
|
||||
echo "Initializing $SCRIPT_NAME has completed"
|
||||
exit $retVal
|
||||
__script_exit $retVal
|
||||
else
|
||||
# ensure the command exists
|
||||
if [ ! -x "$cmd" ]; then
|
||||
@@ -434,7 +444,7 @@ __run_start_script() {
|
||||
if [ ! -f "$START_SCRIPT" ]; then
|
||||
cat <<EOF >"$START_SCRIPT"
|
||||
#!/usr/bin/env bash
|
||||
trap 'exitCode=\$?;[ \$exitCode -ne 0 ] && [ -f "\$SERVICE_PID_FILE" ] && rm -Rf "\$SERVICE_PID_FILE";exit \$exitCode' EXIT
|
||||
trap 'exitCode=\$?;if [ \$exitCode -ne 0 ] && [ -f "\$SERVICE_PID_FILE" ]; then rm -Rf "\$SERVICE_PID_FILE"; fi; exit \$exitCode' EXIT
|
||||
#
|
||||
set -Eeo pipefail
|
||||
# Setting up $cmd to run as ${SERVICE_USER:-root} with env
|
||||
@@ -457,7 +467,7 @@ EOF
|
||||
execute_command="$(__trim "$su_exec $cmd_exec")"
|
||||
cat <<EOF >"$START_SCRIPT"
|
||||
#!/usr/bin/env bash
|
||||
trap 'exitCode=\$?;[ \$exitCode -ne 0 ] && [ -f "\$SERVICE_PID_FILE" ] && rm -Rf "\$SERVICE_PID_FILE";exit \$exitCode' EXIT
|
||||
trap 'exitCode=\$?;if [ \$exitCode -ne 0 ] && [ -f "\$SERVICE_PID_FILE" ]; then rm -Rf "\$SERVICE_PID_FILE"; fi; exit \$exitCode' EXIT
|
||||
#
|
||||
set -Eeo pipefail
|
||||
# Setting up $cmd to run as ${SERVICE_USER:-root}
|
||||
@@ -711,4 +721,4 @@ __post_execute 2>"/dev/stderr" | tee -p -a "/data/logs/init.txt" &
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__banner "Initializing of $SERVICE_NAME has completed with statusCode: $SERVICE_EXIT_CODE" | tee -p -a "/data/logs/entrypoint.log" "/data/logs/init.txt"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
exit $SERVICE_EXIT_CODE
|
||||
__script_exit $SERVICE_EXIT_CODE
|
||||
|
26
rootfs/usr/local/etc/docker/init.d/09-supervisord.sh
Executable file → Normal file
26
rootfs/usr/local/etc/docker/init.d/09-supervisord.sh
Executable file → Normal file
@@ -31,13 +31,25 @@ export PATH="/usr/local/etc/docker/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/s
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
SCRIPT_FILE="$0"
|
||||
SERVICE_NAME="supervisord"
|
||||
# Function to exit appropriately based on context
|
||||
__script_exit() {
|
||||
local exit_code="${1:-0}"
|
||||
if [ "${BASH_SOURCE[0]}" != "${0}" ]; then
|
||||
# Script is being sourced - use return
|
||||
return "$exit_code"
|
||||
else
|
||||
# Script is being executed - use exit
|
||||
exit "$exit_code"
|
||||
fi
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
SCRIPT_NAME="$(basename -- "$SCRIPT_FILE" 2>/dev/null)"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# exit if __start_init_scripts function hasn't been Initialized
|
||||
if [ ! -f "/run/__start_init_scripts.pid" ]; then
|
||||
echo "__start_init_scripts function hasn't been Initialized" >&2
|
||||
SERVICE_IS_RUNNING="no"
|
||||
exit 1
|
||||
__script_exit 1
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# import the functions file
|
||||
@@ -50,8 +62,6 @@ for set_env in "/root/env.sh" "/usr/local/etc/docker/env"/*.sh "/config/env"/*.s
|
||||
[ -f "$set_env" ] && . "$set_env"
|
||||
done
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
printf '%s\n' "# - - - Initializing $SERVICE_NAME - - - #"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Custom functions
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
@@ -208,7 +218,7 @@ __run_pre_execute_checks() {
|
||||
if [ $exitStatus -ne 0 ]; then
|
||||
echo "The pre-execution check has failed" >&2
|
||||
[ -f "$SERVICE_PID_FILE" ] && rm -Rf "$SERVICE_PID_FILE"
|
||||
exit 1
|
||||
__script_exit 1
|
||||
fi
|
||||
# allow custom functions
|
||||
if builtin type -t __run_pre_execute_checks_local | grep -q 'function'; then __run_pre_execute_checks_local; fi
|
||||
@@ -376,7 +386,7 @@ __run_start_script() {
|
||||
__post_execute 2>"/dev/stderr" | tee -p -a "/data/logs/init.txt"
|
||||
retVal=$?
|
||||
echo "Initializing $SCRIPT_NAME has completed"
|
||||
exit $retVal
|
||||
__script_exit $retVal
|
||||
else
|
||||
# ensure the command exists
|
||||
if [ ! -x "$cmd" ]; then
|
||||
@@ -410,7 +420,7 @@ __run_start_script() {
|
||||
if [ ! -f "$START_SCRIPT" ]; then
|
||||
cat <<EOF >"$START_SCRIPT"
|
||||
#!/usr/bin/env bash
|
||||
trap 'exitCode=\$?;[ \$exitCode -ne 0 ] && [ -f "\$SERVICE_PID_FILE" ] && rm -Rf "\$SERVICE_PID_FILE";exit \$exitCode' EXIT
|
||||
trap 'exitCode=\$?;if [ \$exitCode -ne 0 ] && [ -f "\$SERVICE_PID_FILE" ]; then rm -Rf "\$SERVICE_PID_FILE"; fi; exit \$exitCode' EXIT
|
||||
#
|
||||
set -Eeo pipefail
|
||||
# Setting up $cmd to run as ${SERVICE_USER:-root} with env
|
||||
@@ -433,7 +443,7 @@ EOF
|
||||
execute_command="$(__trim "$su_exec $cmd_exec")"
|
||||
cat <<EOF >"$START_SCRIPT"
|
||||
#!/usr/bin/env bash
|
||||
trap 'exitCode=\$?;[ \$exitCode -ne 0 ] && [ -f "\$SERVICE_PID_FILE" ] && rm -Rf "\$SERVICE_PID_FILE";exit \$exitCode' EXIT
|
||||
trap 'exitCode=\$?;if [ \$exitCode -ne 0 ] && [ -f "\$SERVICE_PID_FILE" ]; then rm -Rf "\$SERVICE_PID_FILE"; fi; exit \$exitCode' EXIT
|
||||
#
|
||||
set -Eeo pipefail
|
||||
# Setting up $cmd to run as ${SERVICE_USER:-root}
|
||||
@@ -687,4 +697,4 @@ __post_execute 2>"/dev/stderr" | tee -p -a "/data/logs/init.txt" &
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__banner "Initializing of $SERVICE_NAME has completed with statusCode: $SERVICE_EXIT_CODE" | tee -p -a "/data/logs/entrypoint.log" "/data/logs/init.txt"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
exit $SERVICE_EXIT_CODE
|
||||
__script_exit $SERVICE_EXIT_CODE
|
||||
|
Reference in New Issue
Block a user