🐛 Update entrypoint.sh and functions library from current template 🐛

Stale copies called __initialize_default_templates, __initialize_config_dir,
and __initialize_data_dir which are not in the old functions library,
causing container startup failures. Replaced with current template
versions (202606041210-git) which no longer call those missing functions.
- rootfs/usr/local/bin/entrypoint.sh: update to current template
- rootfs/usr/local/etc/docker/functions/entrypoint.sh: update to current template

rootfs/usr/local/bin/entrypoint.sh
rootfs/usr/local/etc/docker/functions/entrypoint.sh
This commit is contained in:
2026-06-05 18:26:30 -04:00
parent 2e2d83b0cb
commit 62fac76033
2 changed files with 155 additions and 191 deletions
+23 -40
View File
@@ -1,15 +1,15 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck shell=bash # shellcheck shell=bash
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
##@Version : 202605260122-git ##@Version : 202606041210-git
# @@Author : Jason Hempstead # @@Author : Jason Hempstead
# @@Contact : jason@casjaysdev.pro # @@Contact : jason@casjaysdev.pro
# @@License : LICENSE.md # @@License : WTFPL
# @@ReadME : entrypoint.sh --help # @@ReadME : entrypoint.sh --help
# @@Copyright : Copyright: (c) 2026 Jason Hempstead, Casjays Developments # @@Copyright : Copyright: (c) 2026 Jason Hempstead, Casjays Developments
# @@Created : Sunday, May 31, 2026 11:04 EDT # @@Created : Friday, Jun 05, 2026 18:22 EDT
# @@File : entrypoint.sh # @@File : entrypoint.sh
# @@Description : Entrypoint file for rust # @@Description : Entrypoint file for alpine
# @@Changelog : New script # @@Changelog : New script
# @@TODO : Better documentation # @@TODO : Better documentation
# @@Other : # @@Other :
@@ -28,18 +28,18 @@ trap 'retVal=$?;[ "$SERVICE_IS_RUNNING" != "yes" ] && [ -f "$SERVICE_PID_FILE" ]
[ -f "/config/.debug" ] && [ -z "$DEBUGGER_OPTIONS" ] && export DEBUGGER_OPTIONS="$(<"/config/.debug")" || DEBUGGER_OPTIONS="${DEBUGGER_OPTIONS:-}" [ -f "/config/.debug" ] && [ -z "$DEBUGGER_OPTIONS" ] && export DEBUGGER_OPTIONS="$(<"/config/.debug")" || DEBUGGER_OPTIONS="${DEBUGGER_OPTIONS:-}"
if [ "$DEBUGGER" = "on" ] || [ -f "/config/.debug" ]; then if [ "$DEBUGGER" = "on" ] || [ -f "/config/.debug" ]; then
echo "Enabling debugging" echo "Enabling debugging"
set -o pipefail set -eo pipefail
[ -n "$DEBUGGER_OPTIONS" ] && set -"$DEBUGGER_OPTIONS" [ -n "$DEBUGGER_OPTIONS" ] && set -"$DEBUGGER_OPTIONS"
export DEBUGGER="on" export DEBUGGER="on"
else else
set -o pipefail set -eo pipefail
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
PATH="/usr/local/etc/docker/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin" PATH="/usr/local/etc/docker/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin"
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Set bash options # Set bash options
SCRIPT_FILE="$0" SCRIPT_FILE="$0"
CONTAINER_NAME="rust" CONTAINER_NAME="alpine"
SCRIPT_NAME="${SCRIPT_FILE##*/}" SCRIPT_NAME="${SCRIPT_FILE##*/}"
CONTAINER_NAME="${ENV_CONTAINER_NAME:-$CONTAINER_NAME}" CONTAINER_NAME="${ENV_CONTAINER_NAME:-$CONTAINER_NAME}"
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -95,8 +95,8 @@ SERVICE_UID="${SERVICE_UID:-0}"
SERVICE_GID="${SERVICE_GID:-0}" SERVICE_GID="${SERVICE_GID:-0}"
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# User and group in which the service switches to - IE: nginx,apache,mysql,postgres # User and group in which the service switches to - IE: nginx,apache,mysql,postgres
#SERVICE_USER="${SERVICE_USER:-rust}" # execute command as another user #SERVICE_USER="${SERVICE_USER:-alpine}" # execute command as another user
#SERVICE_GROUP="${SERVICE_GROUP:-rust}" # Set the service group #SERVICE_GROUP="${SERVICE_GROUP:-alpine}" # Set the service group
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Secondary ports # Secondary ports
# specifiy other ports # specifiy other ports
@@ -155,9 +155,6 @@ export SSL_CA="${SSL_CA:-/config/ssl/ca.crt}"
export SSL_KEY="${SSL_KEY:-/config/ssl/localhost.pem}" export SSL_KEY="${SSL_KEY:-/config/ssl/localhost.pem}"
export SSL_CERT="${SSL_CERT:-/config/ssl/localhost.crt}" export SSL_CERT="${SSL_CERT:-/config/ssl/localhost.crt}"
export LOCAL_BIN_DIR="${LOCAL_BIN_DIR:-/usr/local/bin}" export LOCAL_BIN_DIR="${LOCAL_BIN_DIR:-/usr/local/bin}"
export DEFAULT_DATA_DIR="${DEFAULT_DATA_DIR:-/usr/local/share/template-files/data}"
export DEFAULT_CONF_DIR="${DEFAULT_CONF_DIR:-/usr/local/share/template-files/config}"
export DEFAULT_TEMPLATE_DIR="${DEFAULT_TEMPLATE_DIR:-/usr/local/share/template-files/defaults}"
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Backup settings # Backup settings
export BACKUP_MAX_DAYS="${BACKUP_MAX_DAYS:-}" export BACKUP_MAX_DAYS="${BACKUP_MAX_DAYS:-}"
@@ -214,15 +211,15 @@ else
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# clean ENV_PORTS variables # clean ENV_PORTS variables
ENV_PORTS="${ENV_PORTS//,/ }" # ENV_PORTS="${ENV_PORTS//,/ }"
ENV_PORTS="${ENV_PORTS//\/*/}" # ENV_PORTS="${ENV_PORTS//\/*/}"
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# clean SERVER_PORTS variables # clean SERVER_PORTS variables
SERVER_PORTS="${SERVER_PORTS//,/ }" # SERVER_PORTS="${SERVER_PORTS//,/ }"
SERVER_PORTS="${SERVER_PORTS//\/*/}" # SERVER_PORTS="${SERVER_PORTS//\/*/}"
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# clean WEB_SERVER_PORTS variables # clean WEB_SERVER_PORTS variables
WEB_SERVER_PORTS="${WEB_SERVER_PORT//,/ } ${ENV_WEB_SERVER_PORTS//,/ }" # WEB_SERVER_PORTS="${WEB_SERVER_PORT//,/ } ${ENV_WEB_SERVER_PORTS//,/ }"
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# rewrite and merge variables # rewrite and merge variables
ENV_PORTS="$(__format_variables "$ENV_PORTS" || false)" ENV_PORTS="$(__format_variables "$ENV_PORTS" || false)"
@@ -294,7 +291,7 @@ fi
if [ "$ENTRYPOINT_FIRST_RUN" != "no" ]; then if [ "$ENTRYPOINT_FIRST_RUN" != "no" ]; then
if [ "$CONFIG_DIR_INITIALIZED" = "no" ] || [ "$DATA_DIR_INITIALIZED" = "no" ]; then if [ "$CONFIG_DIR_INITIALIZED" = "no" ] || [ "$DATA_DIR_INITIALIZED" = "no" ]; then
if [ "$ENTRYPOINT_MESSAGE" = "yes" ]; then if [ "$ENTRYPOINT_MESSAGE" = "yes" ]; then
echo "Executing entrypoint script for rust" echo "Executing entrypoint script for alpine"
fi fi
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -407,21 +404,6 @@ if [ "$ENTRYPOINT_FIRST_RUN" != "no" ] || [ "$CONFIG_DIR_INITIALIZED" = "no" ] |
# Setup bin directory - /config/bin > /usr/local/bin # Setup bin directory - /config/bin > /usr/local/bin
__initialize_custom_bin_dir __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 certificates
__initialize_ssl_certs __initialize_ssl_certs
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -506,11 +488,9 @@ if [ "$START_SERVICES" = "yes" ] || [ -z "$1" ]; then
echo "$$" >"$ENTRYPOINT_PID_FILE" echo "$$" >"$ENTRYPOINT_PID_FILE"
__start_init_scripts "/usr/local/etc/docker/init.d" __start_init_scripts "/usr/local/etc/docker/init.d"
CONTAINER_INIT="${CONTAINER_INIT:-no}" CONTAINER_INIT="${CONTAINER_INIT:-no}"
# Only block in monitoring mode when no user command was given # Services started successfully - enter monitoring mode
if [ $# -eq 0 ]; then __no_exit
__no_exit exit $?
exit $?
fi
fi fi
START_SERVICES="no" START_SERVICES="no"
fi fi
@@ -676,8 +656,11 @@ start)
# Execute primary command # Execute primary command
*) *)
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
# No args: run the default Rust workflow (fmt → clippy → test → build) if [ ! -f "$ENTRYPOINT_PID_FILE" ]; then
__exec_command rust-workflow echo "$$" >"$ENTRYPOINT_PID_FILE"
[ "$START_SERVICES" = "no" ] && [ "$CONTAINER_INIT" = "yes" ] || __start_init_scripts "/usr/local/etc/docker/init.d"
fi
__no_exit
else else
__exec_command "$@" __exec_command "$@"
fi fi
@@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck shell=bash # shellcheck shell=bash
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
##@Version : 202606041110-git ##@Version : 202606041215-git
# @@Author : Jason Hempstead # @@Author : Jason Hempstead
# @@Contact : git-admin@casjaysdev.pro # @@Contact : git-admin@casjaysdev.pro
# @@License : LICENSE.md # @@License : LICENSE.md
@@ -25,11 +25,11 @@ if [ -f "/config/.debug" ] && [ -z "$DEBUGGER_OPTIONS" ]; then
export DEBUGGER_OPTIONS="$(<"/config/.debug")" export DEBUGGER_OPTIONS="$(<"/config/.debug")"
fi fi
if [ "$DEBUGGER" = "on" ] || [ -f "/config/.debug" ]; then if [ "$DEBUGGER" = "on" ] || [ -f "/config/.debug" ]; then
set -o pipefail set -eo pipefail
[ -n "$DEBUGGER_OPTIONS" ] && set -"$DEBUGGER_OPTIONS" [ -n "$DEBUGGER_OPTIONS" ] && set -"$DEBUGGER_OPTIONS"
export DEBUGGER="on" export DEBUGGER="on"
else else
set -o pipefail set -eo pipefail
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__remove_extra_spaces() { sed -E 's/ +/ /g; s|^ ||'; } __remove_extra_spaces() { sed -E 's/ +/ /g; s|^ ||'; }
@@ -257,7 +257,8 @@ __trim() {
__banner() { __banner() {
local message="$*" local message="$*"
local total_width=80 local total_width=80
local content_width=$((total_width - 14)) # Account for "# - - - " and " - - - #" # Account for "# - - - " and " - - - #"
local content_width=$((total_width - 14))
printf '# - - - %-*s - - - #\n' "$content_width" "$message" printf '# - - - %-*s - - - #\n' "$content_width" "$message"
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -267,36 +268,73 @@ __service_banner() {
local service="${3:-service}" local service="${3:-service}"
local full_message="$message $service" local full_message="$message $service"
local total_width=80 local total_width=80
local content_width=$((total_width - 14)) # Account for "# - - - " and " - - - #" # Account for "# - - - " and " - - - #"
local icon_width=2 # Most emojis are 2 chars wide local content_width=$((total_width - 14))
local text_width=$((content_width - icon_width * 2 - 2)) # Account for both icons and spaces # Most emojis are 2 chars wide
local icon_width=2
# Account for both icons and spaces
local text_width=$((content_width - icon_width * 2 - 2))
printf '# - - - %s %-*s %s - - - #\n' "$icon" "$text_width" "$full_message" "$icon" printf '# - - - %s %-*s %s - - - #\n' "$icon" "$text_width" "$full_message" "$icon"
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__find_php_bin() { find -L '/usr'/*bin -maxdepth 4 -name 'php-fpm*' 2>/dev/null | head -n1; } __find_php_bin() {
command -v php-fpm &>/dev/null || command -v php &>/dev/null || return 0
find -L '/usr'/*bin -maxdepth 4 -name 'php-fpm*' 2>/dev/null | head -n1
}
__find_php_ini() { __find_php_ini() {
command -v php &>/dev/null || return 0
local f local f
f=$(find -L '/etc' -maxdepth 4 -name 'php.ini' 2>/dev/null | head -n1) f=$(find -L '/etc' -maxdepth 4 -name 'php.ini' 2>/dev/null | head -n1)
[ -n "$f" ] && printf '%s\n' "${f%/php.ini}" [ -n "$f" ] && printf '%s\n' "${f%/php.ini}"
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__find_nginx_conf() { find -L '/etc' -maxdepth 4 -name 'nginx.conf' 2>/dev/null | head -n1; } __find_nginx_conf() {
__find_caddy_conf() { find -L '/etc' -maxdepth 4 -type f -iname 'caddy.conf' 2>/dev/null | head -n1; } command -v nginx &>/dev/null || return 0
__find_lighttpd_conf() { find -L '/etc' -maxdepth 4 -type f -iname 'lighttpd.conf' 2>/dev/null | head -n1; } find -L '/etc' -maxdepth 4 -name 'nginx.conf' 2>/dev/null | head -n1
__find_cherokee_conf() { find -L '/etc' -maxdepth 4 -type f -iname 'cherokee.conf' 2>/dev/null | head -n1; } }
__find_httpd_conf() { find -L '/etc' -maxdepth 4 -type f -iname 'httpd.conf' -o -iname 'apache2.conf' 2>/dev/null | head -n1; } __find_caddy_conf() {
command -v caddy &>/dev/null || return 0
find -L '/etc' -maxdepth 4 -type f -iname 'caddy.conf' 2>/dev/null | head -n1
}
__find_lighttpd_conf() {
command -v lighttpd &>/dev/null || return 0
find -L '/etc' -maxdepth 4 -type f -iname 'lighttpd.conf' 2>/dev/null | head -n1
}
__find_cherokee_conf() {
command -v cherokee &>/dev/null || command -v cherokee-admin &>/dev/null || return 0
find -L '/etc' -maxdepth 4 -type f -iname 'cherokee.conf' 2>/dev/null | head -n1
}
__find_httpd_conf() {
command -v httpd &>/dev/null || command -v apache2 &>/dev/null || return 0
find -L '/etc' -maxdepth 4 -type f \( -iname 'httpd.conf' -o -iname 'apache2.conf' \) 2>/dev/null | head -n1
}
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__find_mysql_conf() { find -L '/etc' -maxdepth 4 -type f -name 'my.cnf' 2>/dev/null | head -n1; } __find_mysql_conf() {
__find_pgsql_conf() { find -L '/var/lib' '/etc' -maxdepth 8 -type f -name 'postgresql.conf' 2>/dev/null | head -n1; } command -v mysqld &>/dev/null || command -v mariadbd &>/dev/null || command -v mysql &>/dev/null || return 0
__find_couchdb_conf() { return; } find -L '/etc' -maxdepth 4 -type f -name 'my.cnf' 2>/dev/null | head -n1
__find_mongodb_conf() { return; } }
__find_pgsql_conf() {
command -v postgres &>/dev/null || command -v pg_ctl &>/dev/null || return 0
find -L '/var/lib' '/etc' -maxdepth 8 -type f -name 'postgresql.conf' 2>/dev/null | head -n1
}
__find_couchdb_conf() {
command -v couchdb &>/dev/null || return 0
find -L '/opt/couchdb/etc' '/etc/couchdb' -maxdepth 4 -type f \( -name 'local.ini' -o -name 'default.ini' \) 2>/dev/null | head -n1
}
__find_mongodb_conf() {
command -v mongod &>/dev/null || return 0
find -L '/etc/mongodb' '/etc' -maxdepth 4 -type f \( -name 'mongod.conf' -o -name 'mongodb.conf' \) 2>/dev/null | head -n1
}
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__random_password() { tr -dc '0-9a-zA-Z' < /dev/urandom | head -c${1:-16} && echo ""; } __random_password() { tr -dc '0-9a-zA-Z' < /dev/urandom | head -c${1:-16} && echo ""; }
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__init_working_dir() { __init_working_dir() {
local service_name="$SERVICE_NAME" # get service name # get service name
local workdir="$(eval echo "${WORK_DIR:-}")" # expand variables local service_name="$SERVICE_NAME"
local home="$(eval echo "${workdir//\/root/\/tmp\/docker}")" # expand variables # expand variables
local workdir="$(eval echo "${WORK_DIR:-}")"
# expand variables
local home="$(eval echo "${workdir//\/root/\/tmp\/docker}")"
# set working directories # set working directories
[ "$home" = "$workdir" ] && workdir="" [ "$home" = "$workdir" ] && workdir=""
[ "$home" = "/root" ] && home="/tmp/$service_name" [ "$home" = "/root" ] && home="/tmp/$service_name"
@@ -426,70 +464,105 @@ __create_ssl_cert() {
fi fi
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__init_apache() { __init_service_conf() {
local etc_dir="" conf_dir="" conf_dir="" www_dir="" apache_bin="" # Seed /config/$svc/ from build-time baked /etc sources on first container start.
etc_dir="/etc/${1:-apache2}" # Copy only — no symlinks. Symlinking /etc back to /config/ is the service's own
conf_dir="/config/${1:-apache2}" # responsibility, done inside __update_conf_files in each init.d/*.sh script so
www_dir="${WWW_ROOT_DIR:-/data/htdocs}" # each service controls its exact paths and variable substitution order.
apache_bin="$(type -P 'httpd' || type -P 'apache2')"
# #
# Usage: __init_service_conf <conf_dir> <primary_etc_dir> [extra_etc_path ...]
#
# primary_etc_dir directory → contents copied into conf_dir/ when conf_dir is empty
# extra_etc_path directory → copied into conf_dir/<name>/ when that subdir is empty
# extra_etc_path file → copied to conf_dir/<filename> when absent
local conf_dir="$1"
local primary_etc="$2"
shift 2
local src name
mkdir -p "$conf_dir"
if [ -d "$primary_etc" ] && __is_dir_empty "$conf_dir"; then
__copy_templates "$primary_etc/." "$conf_dir/"
fi
for src in "$@"; do
[ -e "$src" ] || continue
name="${src##*/}"
if [ -d "$src" ] && __is_dir_empty "$conf_dir/$name"; then
mkdir -p "$conf_dir/$name"
__copy_templates "$src/." "$conf_dir/$name/"
elif [ -f "$src" ] && [ ! -f "$conf_dir/$name" ]; then
cp -f "$src" "$conf_dir/$name"
fi
done
}
# - - - - - - - - - - - - - - - - - - - - - - - - -
__init_apache() {
command -v httpd &>/dev/null || command -v apache2 &>/dev/null || return 0
local svc="${1:-apache2}"
__init_service_conf "/config/$svc" "/etc/$svc"
return 0 return 0
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__init_nginx() { __init_nginx() {
local etc_dir="/etc/${1:-nginx}" command -v nginx &>/dev/null || return 0
local conf_dir="/config/${1:-nginx}" local svc="${1:-nginx}"
local www_dir="${WWW_ROOT_DIR:-/data/htdocs}" __init_service_conf "/config/$svc" "/etc/$svc"
local nginx_bin="$(type -P 'nginx')"
return 0 return 0
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__init_php() { __init_php() {
local etc_dir="/etc/${1:-php}" command -v php &>/dev/null || return 0
local conf_dir="/config/${1:-php}" local php_etc="${PHP_INI_DIR:-$(__find_php_ini)}"
local php_bin="${PHP_BIN_DIR:-$(__find_php_bin)}" __init_service_conf "/config/php" "${php_etc:-/etc/php}" \
"/etc/php.ini" "/etc/php-fpm" "/etc/php-fpm.conf"
return 0 return 0
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__init_mysql() { __init_mysql() {
local db_dir="/data/db/mysql" command -v mysqld &>/dev/null || command -v mariadbd &>/dev/null || return 0
local etc_dir="${home:-/etc/${1:-mysql}}" local svc="${1:-mysql}"
local db_user="${SERVICE_USER:-mysql}" __init_service_conf "/config/$svc" "/etc/$svc" "/etc/my.ini" "/etc/my.cnf"
local conf_dir="/config/${1:-mysql}" [ -d "${DATABASE_DIR:-/data/db/$svc}" ] || mkdir -p "${DATABASE_DIR:-/data/db/$svc}"
local user_name="${MARIADB_USER:-root}"
local user_pass="${MARIADB_PASSWORD:-$MARIADB_ROOT_PASSWORD}"
local user_db="${MARIADB_DATABASE}"
local root_pass="$MARIADB_ROOT_PASSWORD"
local mysqld_bin="$(type -P 'mysqld')"
return 0 return 0
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__init_mongodb() { __init_mongodb() {
local home="${MONGODB_CONFIG_FILE:-$(__find_mongodb_conf)}" command -v mongod &>/dev/null || return 0
local user_name="${INITDB_ROOT_USERNAME:-root}" __init_service_conf "/config/mongodb" "/etc/mongodb" "/etc/mongod.conf"
local user_pass="${MONGO_INITDB_ROOT_PASSWORD:-$_ROOT_PASSWORD}" return 0
return
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__init_postgres() { __init_postgres() {
local home="${PGSQL_CONFIG_FILE:-$(__find_pgsql_conf)}" command -v postgres &>/dev/null || command -v pg_ctl &>/dev/null || return 0
local user_name="${POSTGRES_USER:-root}" local pg_etc
local user_pass="${POSTGRES_PASSWORD:-$POSTGRES_ROOT_PASSWORD}" pg_etc="${PGSQL_CONFIG_FILE:+${PGSQL_CONFIG_FILE%/*}}"
return [ -n "$pg_etc" ] || pg_etc="$(__find_pgsql_conf)"
[ -n "$pg_etc" ] && pg_etc="${pg_etc%/*}"
[ -n "$pg_etc" ] && __init_service_conf "/config/postgres" "$pg_etc"
return 0
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__init_couchdb() { __init_couchdb() {
local home="${COUCHDB_CONFIG_FILE:-$(__find_couchdb_conf)}" command -v couchdb &>/dev/null || return 0
local user_name="${COUCHDB_USER:-root}" __init_service_conf "/config/couchdb" "/etc/couchdb"
local user_pass="${COUCHDB_PASSWORD:-$SET_RANDOM_PASS}" return 0
return
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Show available init functions # Show available init functions
__init_help() { __init_help() {
echo ' echo '
__update_ssl_certs Config seeding (copy /etc → /config, no symlinks):
__create_ssl_cert __init_service_conf <conf_dir> <primary_etc_dir> [extra_etc_path ...]
__init_apache [svc] seeds /config/apache2 from /etc/apache2
__init_nginx [svc] seeds /config/nginx from /etc/nginx
__init_php seeds /config/php from /etc/php* + /etc/php.ini + /etc/php-fpm
__init_mysql [svc] seeds /config/mysql from /etc/mysql + /etc/my.{ini,cnf}
__init_mongodb seeds /config/mongodb from /etc/mongodb + /etc/mongod.conf
__init_postgres seeds /config/postgres from pg data dir
__init_couchdb seeds /config/couchdb from /etc/couchdb
SSL:
__update_ssl_certs
__create_ssl_cert
' '
return return
} }
@@ -912,10 +985,10 @@ __start_init_scripts() {
[ "$1" = " " ] && shift 1 [ "$1" = " " ] && shift 1
if [ "$DEBUGGER" = "on" ]; then if [ "$DEBUGGER" = "on" ]; then
echo "Enabling debugging" echo "Enabling debugging"
set -o pipefail set -eo pipefail
[ -n "$DEBUGGER_OPTIONS" ] && set -"$DEBUGGER_OPTIONS" [ -n "$DEBUGGER_OPTIONS" ] && set -"$DEBUGGER_OPTIONS"
else else
set -o pipefail set -eo pipefail
fi fi
local retPID="" local retPID=""
local basename="" local basename=""
@@ -1299,95 +1372,6 @@ __initialize_custom_bin_dir() {
fi fi
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__initialize_default_templates() {
local errors=0
if [ -n "$DEFAULT_TEMPLATE_DIR" ]; then
if [ "$CONFIG_DIR_INITIALIZED" = "no" ] && [ -d "/config" ]; then
[ -d "$DEFAULT_TEMPLATE_DIR" ] || return 0
__log_info "Copying default config files $DEFAULT_TEMPLATE_DIR > /config"
for create_config_template in "$DEFAULT_TEMPLATE_DIR"/*; do
if [ -e "$create_config_template" ]; then
create_template_name="${create_config_template##*/}"
if [ -d "$create_config_template" ]; then
mkdir -p "/config/$create_template_name/" || errors=$((errors + 1))
if __is_dir_empty "/config/$create_template_name"; then
if ! cp -Rf "$create_config_template/." "/config/$create_template_name/" 2>/dev/null; then
__log_warn "Failed to copy template directory: $create_template_name"
errors=$((errors + 1))
fi
fi
elif [ -f "$create_config_template" ]; then
if [ ! -e "/config/$create_template_name" ]; then
if ! cp -Rf "$create_config_template" "/config/$create_template_name" 2>/dev/null; then
__log_warn "Failed to copy template file: $create_template_name"
errors=$((errors + 1))
fi
fi
fi
fi
done
unset create_config_template create_template_name
__log_debug "Template initialization completed with $errors errors"
fi
fi
return 0
}
# - - - - - - - - - - - - - - - - - - - - - - - - -
__initialize_config_dir() {
local errors=0
if [ -n "$DEFAULT_CONF_DIR" ]; then
if [ "$CONFIG_DIR_INITIALIZED" = "no" ] && [ -d "/config" ]; then
[ -d "$DEFAULT_CONF_DIR" ] || return 0
__log_info "Copying custom config files: $DEFAULT_CONF_DIR > /config"
for create_config_template in "$DEFAULT_CONF_DIR"/*; do
if [ -e "$create_config_template" ]; then
create_config_name="${create_config_template##*/}"
if [ -d "$create_config_template" ]; then
mkdir -p "/config/$create_config_name" || errors=$((errors + 1))
if __is_dir_empty "/config/$create_config_name"; then
if ! cp -Rf "$create_config_template/." "/config/$create_config_name/" 2>/dev/null; then
__log_warn "Failed to copy config directory: $create_config_name"
errors=$((errors + 1))
fi
fi
elif [ -f "$create_config_template" ]; then
if [ ! -e "/config/$create_config_name" ]; then
if ! cp -Rf "$create_config_template" "/config/$create_config_name" 2>/dev/null; then
__log_warn "Failed to copy config file: $create_config_name"
errors=$((errors + 1))
fi
fi
fi
fi
done
unset create_config_template create_config_name
__log_debug "Config initialization completed with $errors errors"
fi
fi
return 0
}
# - - - - - - - - - - - - - - - - - - - - - - - - -
__initialize_data_dir() {
[ "$DATA_DIR_INITIALIZED" = "no" ] || return 0
if [ -d "/data" ]; then
if [ -n "$DEFAULT_DATA_DIR" ]; then
[ -d "$DEFAULT_DATA_DIR" ] || return 0
__log_info "Copying data files $DEFAULT_DATA_DIR > /data"
for create_data_template in "$DEFAULT_DATA_DIR"/*; do
create_data_name="${create_data_template##*/}"
if [ -n "$create_data_template" ]; then
if [ -d "$create_data_template" ]; then
mkdir -p "/data/$create_data_name"
__is_dir_empty "/data/$create_data_name" && cp -Rf "$create_data_template/." "/data/$create_data_name/" 2>/dev/null
elif [ -e "$create_data_template" ]; then
[ -e "/data/$create_data_name" ] || cp -Rf "$create_data_template" "/data/$create_data_name" 2>/dev/null
fi
fi
done
unset create_data_template
fi
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__initialize_www_root() { __initialize_www_root() {
local WWW_INIT="" local WWW_INIT=""
@@ -1401,7 +1385,7 @@ __initialize_www_root() {
WWW_INIT="false" WWW_INIT="false"
fi fi
if [ "$WWW_INIT" = "true" ] && [ -d "$WWW_TEMPLATE" ]; then if [ "$WWW_INIT" = "true" ] && [ -d "$WWW_TEMPLATE" ]; then
cp -Rf "$DEFAULT_DATA_DIR/data/htdocs/." "$WWW_ROOT_DIR/" 2>/dev/null cp -Rf "$WWW_TEMPLATE/." "$WWW_ROOT_DIR/" 2>/dev/null
fi fi
__initialize_web_health "$WWW_ROOT_DIR" __initialize_web_health "$WWW_ROOT_DIR"
} }
@@ -1581,9 +1565,6 @@ export SSL_CA="${SSL_CA:-/config/ssl/ca.crt}"
export SSL_KEY="${SSL_KEY:-/config/ssl/localhost.pem}" export SSL_KEY="${SSL_KEY:-/config/ssl/localhost.pem}"
export SSL_CERT="${SSL_CERT:-/config/ssl/localhost.crt}" export SSL_CERT="${SSL_CERT:-/config/ssl/localhost.crt}"
export LOCAL_BIN_DIR="${LOCAL_BIN_DIR:-/usr/local/bin}" export LOCAL_BIN_DIR="${LOCAL_BIN_DIR:-/usr/local/bin}"
export DEFAULT_DATA_DIR="${DEFAULT_DATA_DIR:-/usr/local/share/template-files/data}"
export DEFAULT_CONF_DIR="${DEFAULT_CONF_DIR:-/usr/local/share/template-files/config}"
export DEFAULT_TEMPLATE_DIR="${DEFAULT_TEMPLATE_DIR:-/usr/local/share/template-files/defaults}"
# - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Backup settings # Backup settings
export BACKUP_MAX_DAYS="${BACKUP_MAX_DAYS:-}" export BACKUP_MAX_DAYS="${BACKUP_MAX_DAYS:-}"