mirror of
https://github.com/casjaysdevdocker/bind
synced 2026-06-24 14:01:05 -04:00
🗃️ rootfs: shield internal entrypoint PID files from /run/*.pid sweeps 🗃️
Update the embedded entrypoint copies in rootfs/ to match the upstream template change. Internal state files renamed to dotfiles so they're not matched by `/run/*.pid` cleanup globs: - /run/init.d/entrypoint.pid -> /run/.entrypoint.pid - /run/no_exit.pid -> /run/.no_exit.pid - /run/backup.pid -> /run/.backup.pid - /run/__start_init_scripts.pid -> /run/.start_init_scripts.pid Per-service PIDs in /run/init.d/ are unchanged. .claude/ Dockerfile .env.scripts .gitattributes .gitea/workflows/docker.yaml .gitignore LICENSE.md rootfs/root/docker/setup/00-init.sh rootfs/root/docker/setup/01-system.sh rootfs/root/docker/setup/02-packages.sh rootfs/root/docker/setup/03-files.sh rootfs/root/docker/setup/04-users.sh rootfs/root/docker/setup/05-custom.sh rootfs/root/docker/setup/06-post.sh rootfs/root/docker/setup/07-cleanup.sh rootfs/tmp/etc/bind/named.conf rootfs/tmp/etc/nginx/fastcgi_params rootfs/tmp/etc/nginx/nginx.conf rootfs/usr/local/bin/entrypoint.sh rootfs/usr/local/bin/pkmgr rootfs/usr/local/etc/docker/functions/entrypoint.sh rootfs/usr/local/etc/docker/init.d/01-tor.sh rootfs/usr/local/etc/docker/init.d/02-named.sh rootfs/usr/local/etc/docker/init.d/03-nginx.sh rootfs/usr/local/etc/docker/init.d/04-php-fpm.sh rootfs/usr/local/share/template-files/config/env/default.sample rootfs/usr/local/share/template-files/config/env/examples/zz-entrypoint.sh
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
##@Version : 202511301726-git
|
||||
##@Version : 202602061352-git
|
||||
# @@Author : Jason Hempstead
|
||||
# @@Contact : jason@casjaysdev.pro
|
||||
# @@License : WTFPL
|
||||
# @@ReadME : entrypoint.sh --help
|
||||
# @@Copyright : Copyright: (c) 2025 Jason Hempstead, Casjays Developments
|
||||
# @@Created : Sunday, Nov 30, 2025 18:37 EST
|
||||
# @@Copyright : Copyright: (c) 2026 Jason Hempstead, Casjays Developments
|
||||
# @@Created : Tuesday, May 05, 2026 14:38 EDT
|
||||
# @@File : entrypoint.sh
|
||||
# @@Description : Entrypoint file for bind
|
||||
# @@Changelog : New script
|
||||
@@ -21,56 +21,22 @@
|
||||
# shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2090,SC2115,SC2120,SC2155,SC2199,SC2229,SC2317,SC2329
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# run trap command on exit
|
||||
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
|
||||
}
|
||||
trap 'retVal=$?;[ "$SERVICE_IS_RUNNING" != "yes" ] && [ -f "$SERVICE_PID_FILE" ] && rm -Rf "$SERVICE_PID_FILE";exit $retVal' INT TERM PWR
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# setup debugging - https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
|
||||
if [ -f "/config/.debug" ] && [ -z "$DEBUGGER_OPTIONS" ]; then
|
||||
export DEBUGGER_OPTIONS="$(<"/config/.debug")"
|
||||
else
|
||||
DEBUGGER_OPTIONS="${DEBUGGER_OPTIONS:-}"
|
||||
fi
|
||||
if [ "$DEBUGGER" = "on" ] || [ -f "/config/.debug" ]; then
|
||||
echo "Enabling debugging"
|
||||
set -o pipefail -x$DEBUGGER_OPTIONS
|
||||
export DEBUGGER="on"
|
||||
else
|
||||
set -o pipefail
|
||||
fi
|
||||
[ -f "/config/.debug" ] && [ -z "$DEBUGGER_OPTIONS" ] && export DEBUGGER_OPTIONS="$(<"/config/.debug")" || DEBUGGER_OPTIONS="${DEBUGGER_OPTIONS:-}"
|
||||
{ [ "$DEBUGGER" = "on" ] || [ -f "/config/.debug" ]; } && echo "Enabling debugging" && set -o pipefail -x$DEBUGGER_OPTIONS && export DEBUGGER="on" || set -o pipefail
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
PATH="/usr/local/etc/docker/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set bash options
|
||||
SCRIPT_FILE="$0"
|
||||
CONTAINER_NAME="bind"
|
||||
SCRIPT_NAME="$(basename -- "$SCRIPT_FILE" 2>/dev/null)"
|
||||
SCRIPT_NAME="${SCRIPT_FILE##*/}"
|
||||
CONTAINER_NAME="${ENV_CONTAINER_NAME:-$CONTAINER_NAME}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# remove whitespaces from beginning argument
|
||||
while :; do
|
||||
if [ "$1" = " " ]; then
|
||||
shift 1
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
while :; do [ "$1" = " " ] && shift 1 || break; done
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
[ "$1" = "$SCRIPT_FILE" ] && shift 1
|
||||
[ "$1" = "$SCRIPT_NAME" ] && shift 1
|
||||
@@ -204,7 +170,7 @@ export ENTRYPOINT_DATA_INIT_FILE="${ENTRYPOINT_DATA_INIT_FILE:-/data/.docker_has
|
||||
export ENTRYPOINT_CONFIG_INIT_FILE="${ENTRYPOINT_CONFIG_INIT_FILE:-/config/.docker_has_run}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
if [ -n "$CONTAINER_WEB_SERVER_WWW_REPO" ]; then
|
||||
www_temp_dir="/tmp/git/$(basename -- "$CONTAINER_WEB_SERVER_WWW_REPO")"
|
||||
www_temp_dir="/tmp/git/${CONTAINER_WEB_SERVER_WWW_REPO##*/}"
|
||||
rm -Rf "${WWW_ROOT_DIR:?}"/* "${www_temp_dir:?}"/* 2>/dev/null || true
|
||||
mkdir -p "$WWW_ROOT_DIR" "$www_temp_dir" 2>/dev/null || true
|
||||
git clone -q "$CONTAINER_WEB_SERVER_WWW_REPO" "$www_temp_dir" 2>/dev/null || true
|
||||
@@ -401,7 +367,7 @@ if [ "$ENTRYPOINT_FIRST_RUN" != "no" ]; then
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# import hosts file into container
|
||||
if [ -f "/usr/local/etc/hosts" ] && [ "$UPDATE_FILE_HOSTS" = "yes" ]; then
|
||||
cat "/usr/local/etc/hosts" 2>/dev/null | grep -vF "$HOSTNAME" >>"/etc/hosts" 2>/dev/null || true
|
||||
grep -vF "$HOSTNAME" "/usr/local/etc/hosts" 2>/dev/null >>"/etc/hosts" 2>/dev/null || true
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# import resolv.conf file into container
|
||||
@@ -428,72 +394,77 @@ if [ -f "/usr/local/bin/.gitkeep" ]; then
|
||||
rm -Rf "/usr/local/bin/.gitkeep" 2>/dev/null || true
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Setup bin directory - /config/bin > /usr/local/bin
|
||||
__initialize_custom_bin_dir
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Copy default system configs - /usr/local/share/template-files/defaults > /config/
|
||||
__initialize_default_templates
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Copy custom config files - /usr/local/share/template-files/config > /config/
|
||||
__initialize_config_dir
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Copy custom data files - /usr/local/share/template-files/data > /data/
|
||||
__initialize_data_dir
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__initialize_ssl_certs
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
if [ -f "$ENTRYPOINT_INIT_FILE" ]; then
|
||||
ENTRYPOINT_FIRST_RUN="no"
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
if [ -d "/config" ]; then
|
||||
echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_INIT_FILE" 2>/dev/null || true
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Check if this is a new container
|
||||
if [ -f "$ENTRYPOINT_DATA_INIT_FILE" ]; then
|
||||
DATA_DIR_INITIALIZED="yes"
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
if [ -d "/data" ]; then
|
||||
echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_DATA_INIT_FILE" 2>/dev/null || true
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
if [ -f "$ENTRYPOINT_CONFIG_INIT_FILE" ]; then
|
||||
CONFIG_DIR_INITIALIZED="yes"
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
if [ -d "/config" ]; then
|
||||
echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_CONFIG_INIT_FILE" 2>/dev/null || true
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
if [ "$ENTRYPOINT_FIRST_RUN" != "no" ]; then
|
||||
# Only run initialization on first run or when directories are not initialized
|
||||
if [ "$ENTRYPOINT_FIRST_RUN" != "no" ] || [ "$CONFIG_DIR_INITIALIZED" = "no" ] || [ "$DATA_DIR_INITIALIZED" = "no" ]; then
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Setup bin directory - /config/bin > /usr/local/bin
|
||||
__initialize_custom_bin_dir
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Copy default system configs - /usr/local/share/template-files/defaults > /config/
|
||||
if [ "$CONFIG_DIR_INITIALIZED" = "no" ]; then
|
||||
__initialize_default_templates
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Copy custom config files - /usr/local/share/template-files/config > /config/
|
||||
if [ "$CONFIG_DIR_INITIALIZED" = "no" ]; then
|
||||
__initialize_config_dir
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Copy custom data files - /usr/local/share/template-files/data > /data/
|
||||
if [ "$DATA_DIR_INITIALIZED" = "no" ]; then
|
||||
__initialize_data_dir
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Initialize SSL certificates
|
||||
__initialize_ssl_certs
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Mark directories as initialized (only write if not already initialized)
|
||||
if [ -d "/config" ] && [ "$CONFIG_DIR_INITIALIZED" = "no" ]; then
|
||||
echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_CONFIG_INIT_FILE" 2>/dev/null || true
|
||||
CONFIG_DIR_INITIALIZED="yes"
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
if [ -d "/data" ] && [ "$DATA_DIR_INITIALIZED" = "no" ]; then
|
||||
echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_DATA_INIT_FILE" 2>/dev/null || true
|
||||
DATA_DIR_INITIALIZED="yes"
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
if [ -d "/config" ] && [ ! -f "$ENTRYPOINT_INIT_FILE" ]; then
|
||||
echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_INIT_FILE" 2>/dev/null || true
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# setup the smtp server
|
||||
__setup_mta
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
ENTRYPOINT_FIRST_RUN="no"
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# if no pid assume container restart - clean stale files on restart
|
||||
if [ -f "$ENTRYPOINT_PID_FILE" ]; then
|
||||
START_SERVICES="no"
|
||||
touch "$ENTRYPOINT_PID_FILE"
|
||||
# Check if the PID in the file is still running
|
||||
entrypoint_pid=$(cat "$ENTRYPOINT_PID_FILE" 2>/dev/null || echo "")
|
||||
if [ -n "$entrypoint_pid" ] && kill -0 "$entrypoint_pid" 2>/dev/null; then
|
||||
# Process is still running, don't restart services
|
||||
START_SERVICES="no"
|
||||
touch "$ENTRYPOINT_PID_FILE"
|
||||
else
|
||||
# PID file exists but process is dead - this is a restart
|
||||
START_SERVICES="yes"
|
||||
# Clean any stale PID files on restart
|
||||
rm -f /run/.start_init_scripts.pid /run/init.d/*.pid /run/*.pid 2>/dev/null || true
|
||||
fi
|
||||
else
|
||||
START_SERVICES=yes
|
||||
# Clean any stale PID files on first run
|
||||
rm -f /run/__start_init_scripts.pid /run/init.d/*.pid /run/*.pid 2>/dev/null || true
|
||||
rm -f /run/.start_init_scripts.pid /run/init.d/*.pid /run/*.pid 2>/dev/null || true
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
if [ "$ENTRYPOINT_MESSAGE" = "yes" ]; then
|
||||
__printf_space "40" "The containers ip address is:" "$CONTAINER_IP4_ADDRESS"
|
||||
fi
|
||||
[ "$ENTRYPOINT_MESSAGE" = "yes" ] && __printf_space "40" "The containers ip address is:" "$CONTAINER_IP4_ADDRESS"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Show configured listing processes
|
||||
if [ "$ENTRYPOINT_MESSAGE" = "yes" ] && [ -n "$ENV_PORTS" ]; then
|
||||
show_port=""
|
||||
for port in $ENV_PORTS; do
|
||||
if [ -n "$port" ]; then
|
||||
show_port+="$(printf '%s ' "${port// /}") "
|
||||
fi
|
||||
done
|
||||
for port in $ENV_PORTS; do [ -n "$port" ] && show_port+="$(printf '%s ' "${port// /}") "; done
|
||||
__printf_space "40" "The following ports are open:" "$show_port"
|
||||
unset port show_port
|
||||
fi
|
||||
@@ -528,6 +499,9 @@ if [ "$START_SERVICES" = "yes" ] || [ -z "$1" ]; then
|
||||
echo "$$" >"$ENTRYPOINT_PID_FILE"
|
||||
__start_init_scripts "/usr/local/etc/docker/init.d"
|
||||
CONTAINER_INIT="${CONTAINER_INIT:-no}"
|
||||
# Services started successfully - enter monitoring mode
|
||||
__no_exit
|
||||
exit $?
|
||||
fi
|
||||
START_SERVICES="no"
|
||||
fi
|
||||
@@ -537,7 +511,7 @@ export START_SERVICES CONTAINER_INIT ENTRYPOINT_PID_FILE
|
||||
case "$1" in
|
||||
init)
|
||||
shift 1
|
||||
echo "Container has been Initialized"
|
||||
__log_info "Container has been initialized"
|
||||
exit 0
|
||||
;;
|
||||
tail)
|
||||
@@ -568,7 +542,7 @@ logs)
|
||||
clean)
|
||||
log_files="$(find "/data/logs" -type f)"
|
||||
for log in "${log_files[@]}"; do
|
||||
echo "clearing $log"
|
||||
__log_info "Clearing log file: $log"
|
||||
printf '' >$log
|
||||
done
|
||||
;;
|
||||
@@ -581,7 +555,7 @@ logs)
|
||||
cron)
|
||||
shift 1
|
||||
__cron "$@" &
|
||||
echo "cron script is running with pid: $!"
|
||||
__log_info "Cron script is running with PID: $!"
|
||||
exit
|
||||
;;
|
||||
# backup data and config dirs
|
||||
@@ -609,7 +583,7 @@ healthcheck)
|
||||
[ "$healthEnabled" = "yes" ] || exit 0
|
||||
if [ -d "/run/healthcheck" ] && [ "$(ls -A "/run/healthcheck" | wc -l)" -ne 0 ]; then
|
||||
for service in /run/healthcheck/*; do
|
||||
name=$(basename -- $service)
|
||||
name="${service##*/}"
|
||||
services+="$name "
|
||||
done
|
||||
fi
|
||||
@@ -697,11 +671,7 @@ start)
|
||||
export PATH="/usr/local/etc/docker/init.d:$PATH"
|
||||
if [ $# -eq 0 ]; then
|
||||
scripts="$(ls -A "/usr/local/etc/docker/init.d")"
|
||||
if [ -n "$scripts" ]; then
|
||||
echo "$scripts"
|
||||
else
|
||||
echo "No scripts found in: /usr/local/etc/docker/init.d"
|
||||
fi
|
||||
[ -n "$scripts" ] && echo "$scripts" || echo "No scripts found in: /usr/local/etc/docker/init.d"
|
||||
exit
|
||||
elif [ "$1" = "all" ]; then
|
||||
shift $#
|
||||
@@ -720,11 +690,7 @@ start)
|
||||
if [ $# -eq 0 ]; then
|
||||
if [ ! -f "$ENTRYPOINT_PID_FILE" ]; then
|
||||
echo "$$" >"$ENTRYPOINT_PID_FILE"
|
||||
if [ "$START_SERVICES" = "no" ] && [ "$CONTAINER_INIT" = "yes" ]; then
|
||||
:
|
||||
else
|
||||
__start_init_scripts "/usr/local/etc/docker/init.d"
|
||||
fi
|
||||
[ "$START_SERVICES" = "no" ] && [ "$CONTAINER_INIT" = "yes" ] || __start_init_scripts "/usr/local/etc/docker/init.d"
|
||||
fi
|
||||
__no_exit
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user