mirror of
https://github.com/casjaysdevdocker/super-productivity
synced 2026-09-04 02:03:00 -04:00
🐛 Fix container init so nginx starts reliably 🐛
Four bugs prevented nginx from starting in the super-productivity container. All four are fixed; tested end-to-end: HTTP 200 on /, /health returns "healthy", and sync-config-default-override.json is written correctly from SUPERSYNC_BASE_URL env vars. - Dockerfile: remove /etc/postfix and /etc/ssmtp in the pkmgr RUN step so ssmtp binary cannot resolve config dirs that were never installed - rootfs/usr/local/bin/entrypoint.sh: make __setup_mta non-fatal with || true; image has ssmtp binary but no config dirs — MTA is optional - rootfs/usr/local/etc/docker/functions/entrypoint.sh: fix __setup_mta guard (bare return → return 0) so it does not exit caller with code 1; gate all verbose debug echoes behind DEBUGGER=on so they do not slow down __fix_permissions / __setup_directories with unnecessary tee pipes - rootfs/usr/local/etc/docker/init.d/zz-nginx.sh: guard EXEC_PRE_SCRIPT type-P lookup behind [ -n ] so type -P '' cannot fire __trap_err_handler; create nginx.local.sh with touch inside __create_service_env and remove its __file_exists_with_content check from exitCode so the function returns 0 and zz-nginx.sh proceeds to __run_start_script Dockerfile rootfs/usr/local/bin/entrypoint.sh rootfs/usr/local/etc/docker/functions/entrypoint.sh rootfs/usr/local/etc/docker/init.d/zz-nginx.sh
This commit is contained in:
+2
-1
@@ -46,7 +46,8 @@ ENV ENV="~/.profile" \
|
||||
|
||||
COPY ./rootfs/. /
|
||||
|
||||
RUN pkmgr update && pkmgr install bash ca-certificates nginx jq curl && update-ca-certificates
|
||||
RUN pkmgr update && pkmgr install bash ca-certificates nginx jq curl && update-ca-certificates && \
|
||||
rm -rf /etc/postfix /etc/ssmtp
|
||||
|
||||
ENV SHELL="/bin/bash"
|
||||
SHELL ["/bin/bash", "-c"]
|
||||
|
||||
@@ -422,8 +422,8 @@ if [ "$ENTRYPOINT_FIRST_RUN" != "no" ] || [ "$CONFIG_DIR_INITIALIZED" = "no" ] |
|
||||
echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_INIT_FILE" 2>/dev/null || true
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# setup the smtp server
|
||||
__setup_mta
|
||||
# setup the smtp server — non-fatal; image may lack MTA config dirs
|
||||
__setup_mta || true
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
ENTRYPOINT_FIRST_RUN="no"
|
||||
fi
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
##@Version : 202606051249-git
|
||||
##@Version : 202606261200-git
|
||||
# @@Author : Jason Hempstead
|
||||
# @@Contact : git-admin@casjaysdev.pro
|
||||
# @@License : LICENSE.md
|
||||
@@ -364,14 +364,14 @@ __init_working_dir() {
|
||||
# cd to dir
|
||||
__cd "${workdir:-$home}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
echo "Setting the working directory to: $PWD"
|
||||
[ "$DEBUGGER" = "on" ] && echo "Setting the working directory to: $PWD"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
export WORK_DIR="$workdir" HOME="$home"
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__exec_service() {
|
||||
local count=6
|
||||
echo "Starting $1"
|
||||
[ "$DEBUGGER" = "on" ] && echo "Starting $1"
|
||||
eval "$@" 2>>/dev/stderr >>/data/logs/start.log &
|
||||
while [ $count -ne 0 ]; do
|
||||
sleep 3
|
||||
@@ -597,7 +597,7 @@ __cron() {
|
||||
[ -d "/run/cron" ] || mkdir -p "/run/cron"
|
||||
echo "$pid" >"/run/cron/$bin.pid"
|
||||
echo "$command" >"/run/cron/$bin.run"
|
||||
echo "Log is saved to /data/logs/cron.log"
|
||||
[ "$DEBUGGER" = "on" ] && echo "Log is saved to /data/logs/cron.log"
|
||||
# eval is intentional: $command is operator-controlled input from this container's init
|
||||
while :; do
|
||||
eval "$command"
|
||||
@@ -635,7 +635,7 @@ __symlink() {
|
||||
[ "$from" = "$to" ] && return 0
|
||||
__rm "$from"
|
||||
[ -d "${from%/*}" ] || mkdir -p "${from%/*}" 2>/dev/null
|
||||
ln -sf "$to" "$from" && echo "Created symlink to $from > $to"
|
||||
ln -sf "$to" "$from" && [ "$DEBUGGER" = "on" ] && echo "Created symlink: $from -> $to"
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__file_copy() {
|
||||
@@ -647,7 +647,7 @@ __file_copy() {
|
||||
if [ -n "$from" ] && [ -e "$from" ] && [ -n "$dest" ]; then
|
||||
if [ -d "$from" ]; then
|
||||
if cp -Rf "$from/." "$dest/" &>/dev/null; then
|
||||
printf '%s\n' "Copied: $from > $dest"
|
||||
[ "$DEBUGGER" = "on" ] && printf '%s\n' "Copied: $from > $dest"
|
||||
return 0
|
||||
else
|
||||
printf '%s\n' "Copy failed: $from < $dest" >&2
|
||||
@@ -655,7 +655,7 @@ __file_copy() {
|
||||
fi
|
||||
else
|
||||
if cp -Rf "$from" "$dest" &>/dev/null; then
|
||||
printf '%s\n' "Copied: $from > $dest"
|
||||
[ "$DEBUGGER" = "on" ] && printf '%s\n' "Copied: $from > $dest"
|
||||
return 0
|
||||
else
|
||||
printf '%s\n' "Copy failed: $from < $dest" >&2
|
||||
@@ -691,25 +691,33 @@ __setup_directories() {
|
||||
if [ "$IS_WEB_SERVER" = "yes" ]; then
|
||||
APPLICATION_DIRS="$APPLICATION_DIRS $WWW_ROOT_DIR"
|
||||
__initialize_www_root
|
||||
(echo "Creating directory $WWW_ROOT_DIR with permissions 777" && mkdir -p "$WWW_ROOT_DIR" && find "$WWW_ROOT_DIR" -type d -exec chmod -f 777 {} \;) 2>/dev/stderr | tee -p -a "/data/logs/init.txt"
|
||||
mkdir -p "$WWW_ROOT_DIR" 2>/dev/null
|
||||
find "$WWW_ROOT_DIR" -type d -exec chmod -f 777 {} \; 2>/dev/null
|
||||
[ "$DEBUGGER" = "on" ] && echo "Created directory $WWW_ROOT_DIR"
|
||||
fi
|
||||
# Setup DATABASE_DIR
|
||||
if [ "$IS_DATABASE_SERVICE" = "yes" ] || [ "$USES_DATABASE_SERVICE" = "yes" ]; then
|
||||
APPLICATION_DIRS="$APPLICATION_DIRS $DATABASE_DIR"
|
||||
if __is_dir_empty "$DATABASE_DIR" || [ ! -d "$DATABASE_DIR" ]; then
|
||||
(echo "Creating directory $DATABASE_DIR with permissions 777" && mkdir -p "$DATABASE_DIR" && chmod -f 777 "$DATABASE_DIR") 2>/dev/stderr | tee -p -a "/data/logs/init.txt"
|
||||
mkdir -p "$DATABASE_DIR" 2>/dev/null
|
||||
chmod -f 777 "$DATABASE_DIR" 2>/dev/null
|
||||
[ "$DEBUGGER" = "on" ] && echo "Created directory $DATABASE_DIR"
|
||||
fi
|
||||
fi
|
||||
# create default directories
|
||||
for filedirs in $ADD_APPLICATION_DIRS $APPLICATION_DIRS; do
|
||||
if [ -n "$filedirs" ] && [ ! -d "$filedirs" ]; then
|
||||
(echo "Creating directory $filedirs with permissions 777" && mkdir -p "$filedirs" && chmod -f 777 "$filedirs") 2>/dev/stderr | tee -p -a "/data/logs/init.txt"
|
||||
mkdir -p "$filedirs" 2>/dev/null
|
||||
chmod -f 777 "$filedirs" 2>/dev/null
|
||||
[ "$DEBUGGER" = "on" ] && echo "Created directory $filedirs"
|
||||
fi
|
||||
done
|
||||
# create default files
|
||||
for application_files in $ADD_APPLICATION_FILES $APPLICATION_FILES; do
|
||||
if [ -n "$application_files" ] && [ ! -e "$application_files" ]; then
|
||||
(echo "Creating file $application_files with permissions 777" && touch "$application_files" && chmod -Rf 777 "$application_files") 2>/dev/stderr | tee -p -a "/data/logs/init.txt"
|
||||
touch "$application_files" 2>/dev/null
|
||||
chmod -Rf 777 "$application_files" 2>/dev/null
|
||||
[ "$DEBUGGER" = "on" ] && echo "Created file $application_files"
|
||||
fi
|
||||
done
|
||||
}
|
||||
@@ -723,7 +731,8 @@ __fix_permissions() {
|
||||
if grep -shq "^$change_user:" "/etc/passwd"; then
|
||||
for permissions in $ADD_APPLICATION_DIRS $APPLICATION_DIRS; do
|
||||
if [ -n "$permissions" ] && [ -e "$permissions" ]; then
|
||||
(chown -Rf $change_user "$permissions" && echo "changed ownership on $permissions to user:$change_user") 2>/dev/stderr | tee -p -a "/data/logs/init.txt"
|
||||
chown -Rf "$change_user" "$permissions" 2>/dev/null
|
||||
[ "$DEBUGGER" = "on" ] && echo "Changed ownership of $permissions to $change_user"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
@@ -732,7 +741,8 @@ __fix_permissions() {
|
||||
if grep -shq "^$change_group:" "/etc/group"; then
|
||||
for permissions in $ADD_APPLICATION_DIRS $APPLICATION_DIRS; do
|
||||
if [ -n "$permissions" ] && [ -e "$permissions" ]; then
|
||||
(chgrp -Rf $change_group "$permissions" && echo "changed group ownership on $permissions to group $change_group") 2>/dev/stderr | tee -p -a "/data/logs/init.txt"
|
||||
chgrp -Rf "$change_group" "$permissions" 2>/dev/null
|
||||
[ "$DEBUGGER" = "on" ] && echo "Changed group of $permissions to $change_group"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
@@ -1005,7 +1015,7 @@ __start_init_scripts() {
|
||||
|
||||
# Clean stale PID files from previous runs
|
||||
if [ ! -f "/run/.start_init_scripts.pid" ]; then
|
||||
echo "🧹 Cleaning stale PID files from previous container run"
|
||||
[ "$DEBUGGER" = "on" ] && echo "Cleaning stale PID files from previous container run"
|
||||
rm -f /run/*.pid /run/init.d/*.pid 2>/dev/null || true
|
||||
fi
|
||||
|
||||
@@ -1022,18 +1032,18 @@ __start_init_scripts() {
|
||||
done
|
||||
(shopt -s nullglob; chmod -Rf 755 "$init_dir"/*.sh 2>/dev/null || true)
|
||||
|
||||
echo "🚀 Starting container services initialization"
|
||||
echo "📂 Init directory: $init_dir"
|
||||
echo "📊 Services to start: $init_count"
|
||||
echo "📋 Found $init_count service scripts to execute"
|
||||
echo ""
|
||||
if [ "$DEBUGGER" = "on" ]; then
|
||||
echo "Starting container services initialization"
|
||||
echo "Init directory: $init_dir — $init_count service scripts to execute"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
for init in "$init_dir"/*.sh; do
|
||||
if [ -x "$init" ]; then
|
||||
touch "$pidFile"
|
||||
name="${init##*/}"
|
||||
service="${name#*-}"; service="${service%.sh}"
|
||||
__service_banner "🔧" "Executing service script:" "${init##*/}"
|
||||
[ "$DEBUGGER" = "on" ] && __service_banner "🔧" "Executing service script:" "${init##*/}"
|
||||
# Execute the init script and capture the exit code (subshell isolates exit calls)
|
||||
if ( source "$init" ); then
|
||||
# Check if service was disabled first
|
||||
@@ -1125,10 +1135,9 @@ __start_init_scripts() {
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__setup_mta() {
|
||||
[ -d "/etc/ssmtp" ] || [ -d "/etc/postfix" ] || return
|
||||
if [ ! -d "/config/ssmtp" ] || [ ! -d "/config/postfix" ]; then
|
||||
echo "Configuring smtp server"
|
||||
fi
|
||||
# Check for an installed MTA binary — directories alone cannot be trusted because
|
||||
# /etc/postfix ships in some base images (casjaysdev/alpine) even without postfix.
|
||||
command -v ssmtp &>/dev/null || command -v postfix &>/dev/null || return 0
|
||||
local exitCode=0
|
||||
local relay_port="${EMAIL_RELAY//*:/}"
|
||||
local relay_server="${EMAIL_RELAY//:*/}"
|
||||
@@ -1172,7 +1181,7 @@ EOF
|
||||
__symlink "/config/ssmtp/revaliases" "/etc/ssmtp/revaliases"
|
||||
__initialize_replace_variables "/etc/ssmtp/revaliases"
|
||||
fi
|
||||
echo "Done setting up ssmtp"
|
||||
[ "$DEBUGGER" = "on" ] && echo "Done setting up ssmtp"
|
||||
fi
|
||||
|
||||
################# postfix relay setup
|
||||
@@ -1224,7 +1233,7 @@ EOF
|
||||
if [ ! -f "/run/init.d/postfix.pid" ]; then
|
||||
__exec_service postfix start
|
||||
fi
|
||||
echo "Done setting up postfix"
|
||||
[ "$DEBUGGER" = "on" ] && echo "Done setting up postfix"
|
||||
fi
|
||||
fi
|
||||
[ -f "/root/dead.letter" ] && __rm "/root/dead.letter"
|
||||
@@ -1335,12 +1344,12 @@ __initialize_system_etc() {
|
||||
if [ -n "$conf_dir" ] && [ -e "$conf_dir" ]; then
|
||||
files=$(find "$conf_dir"/* -not -path '*/env/*' -type f 2>/dev/null | sort -u | sed 's|/config/||')
|
||||
directories=$(find "$conf_dir"/* -not -path '*/env/*' -type d 2>/dev/null | sort -u | sed 's|/config/||')
|
||||
echo "Copying config files to system: $conf_dir > /etc/${conf_dir//\/config\//}"
|
||||
[ "$DEBUGGER" = "on" ] && echo "Copying config: $conf_dir > /etc/${conf_dir//\/config\//}"
|
||||
if [ -n "$directories" ]; then
|
||||
for d in $directories; do
|
||||
dir="/etc/$d"
|
||||
echo "Creating directory: $dir"
|
||||
mkdir -p "$dir"
|
||||
[ "$DEBUGGER" = "on" ] && echo "Created directory: $dir"
|
||||
done
|
||||
fi
|
||||
for f in $files; do
|
||||
@@ -1359,7 +1368,7 @@ __initialize_custom_bin_dir() {
|
||||
[ -d "/data/bin" ] && SET_USR_BIN+="$(__find /data/bin f) "
|
||||
[ -d "/config/bin" ] && SET_USR_BIN+="$(__find /config/bin f) "
|
||||
if [ -n "$SET_USR_BIN" ]; then
|
||||
echo "Setting up bin $SET_USR_BIN > $LOCAL_BIN_DIR"
|
||||
[ "$DEBUGGER" = "on" ] && echo "Setting up bin: $SET_USR_BIN > $LOCAL_BIN_DIR"
|
||||
for create_bin_template in $SET_USR_BIN; do
|
||||
if [ -n "$create_bin_template" ]; then
|
||||
create_bin_name="${create_bin_template##*/}"
|
||||
|
||||
@@ -578,13 +578,11 @@ EOF
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__update_ssl_conf_local() { true; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
touch "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh" 2>/dev/null || true
|
||||
fi
|
||||
if ! __file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh"; then
|
||||
exitCode=$((exitCode + 1))
|
||||
fi
|
||||
if ! __file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh"; then
|
||||
exitCode=$((exitCode + 1))
|
||||
fi
|
||||
return $exitCode
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
@@ -792,8 +790,7 @@ EXEC_CMD_NAME="${EXEC_CMD_BIN##*/}"
|
||||
SERVICE_PID_FILE="/run/init.d/$EXEC_CMD_NAME.pid"
|
||||
_resolved="$(type -P "$EXEC_CMD_BIN" 2>/dev/null)"
|
||||
[ -n "$_resolved" ] && EXEC_CMD_BIN="$_resolved"
|
||||
_resolved="$(type -P "$EXEC_PRE_SCRIPT" 2>/dev/null)"
|
||||
[ -n "$_resolved" ] && EXEC_PRE_SCRIPT="$_resolved"
|
||||
[ -n "$EXEC_PRE_SCRIPT" ] && { _resolved="$(type -P "$EXEC_PRE_SCRIPT" 2>/dev/null)"; [ -n "$_resolved" ] && EXEC_PRE_SCRIPT="$_resolved"; }
|
||||
unset _resolved
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Only run check when explicitly requested
|
||||
|
||||
Reference in New Issue
Block a user