🗃️ Update codebase 🗃️

rootfs/usr/local/bin/entrypoint.sh
rootfs/usr/local/etc/docker/functions/entrypoint.sh
This commit is contained in:
casjay
2025-10-22 15:23:15 -04:00
parent 8e13168cc7
commit 5d69abbfd1
2 changed files with 255 additions and 209 deletions

View File

@@ -1,15 +1,15 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck shell=bash # shellcheck shell=bash
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
##@Version : 202509200513-git ##@Version : 202510221522-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) 2025 Jason Hempstead, Casjays Developments # @@Copyright : Copyright: (c) 2025 Jason Hempstead, Casjays Developments
# @@Created : Saturday, Sep 20, 2025 05:13 EDT # @@Created : Wednesday, Oct 22, 2025 15:22 EDT
# @@File : entrypoint.sh # @@File : entrypoint.sh
# @@Description : Entrypoint file for alpine # @@Description : Entrypoint file for entrypoint.sh
# @@Changelog : New script # @@Changelog : New script
# @@TODO : Better documentation # @@TODO : Better documentation
# @@Other : # @@Other :
@@ -17,30 +17,30 @@
# @@Terminal App : no # @@Terminal App : no
# @@sudo/root : no # @@sudo/root : no
# @@Template : other/docker-entrypoint # @@Template : other/docker-entrypoint
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2120,SC2155,SC2199,SC2317,SC2329 # shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2120,SC2155,SC2199,SC2317,SC2329
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# run trap command on exit # run trap command on exit
trap 'retVal=$?;[ "$SERVICE_IS_RUNNING" != "yes" ] && [ -f "$SERVICE_PID_FILE" ] && rm -Rf "$SERVICE_PID_FILE";exit $retVal' INT TERM PWR 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 # setup debugging - https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
[ -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:-}"
{ [ "$DEBUGGER" = "on" ] || [ -f "/config/.debug" ]; } && echo "Enabling debugging" && set -o pipefail -x$DEBUGGER_OPTIONS && export DEBUGGER="on" || set -o pipefail { [ "$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" 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="alpine" CONTAINER_NAME="entrypoint.sh"
SCRIPT_NAME="$(basename -- "$SCRIPT_FILE" 2>/dev/null)" SCRIPT_NAME="$(basename -- "$SCRIPT_FILE" 2>/dev/null)"
CONTAINER_NAME="${ENV_CONTAINER_NAME:-$CONTAINER_NAME}" CONTAINER_NAME="${ENV_CONTAINER_NAME:-$CONTAINER_NAME}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# remove whitespaces from beginning argument # remove whitespaces from beginning argument
while :; do [ "$1" = " " ] && shift 1 || break; done while :; do [ "$1" = " " ] && shift 1 || break; done
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
[ "$1" = "$SCRIPT_FILE" ] && shift 1 [ "$1" = "$SCRIPT_FILE" ] && shift 1
[ "$1" = "$SCRIPT_NAME" ] && shift 1 [ "$1" = "$SCRIPT_NAME" ] && shift 1
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# import the functions file # import the functions file
if [ -f "/usr/local/etc/docker/functions/entrypoint.sh" ]; then if [ -f "/usr/local/etc/docker/functions/entrypoint.sh" ]; then
. "/usr/local/etc/docker/functions/entrypoint.sh" . "/usr/local/etc/docker/functions/entrypoint.sh"
@@ -48,7 +48,7 @@ else
echo "Can not load functions from /usr/local/etc/docker/functions/entrypoint.sh" echo "Can not load functions from /usr/local/etc/docker/functions/entrypoint.sh"
exit 1 exit 1
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
case "$1" in case "$1" in
# Help message # Help message
-h | --help) -h | --help)
@@ -62,60 +62,60 @@ case "$1" in
shift shift
;; ;;
esac esac
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Create the default env files # Create the default env files
__create_env_file "/config/env/default.sh" "/root/env.sh" &>/dev/null __create_env_file "/config/env/default.sh" "/root/env.sh" &>/dev/null
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# import variables from files # import variables from files
for set_env in "/root/env.sh" "/usr/local/etc/docker/env"/*.sh "/config/env"/*.sh; do for set_env in "/root/env.sh" "/usr/local/etc/docker/env"/*.sh "/config/env"/*.sh; do
[ -f "$set_env" ] && . "$set_env" [ -f "$set_env" ] && . "$set_env"
done done
unset set_env unset set_env
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# User to use to launch service - IE: postgres # User to use to launch service - IE: postgres
RUNAS_USER="root" # normally root RUNAS_USER="root" # normally root
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Set user and group from env # Set user and group from env
SERVICE_USER="${PUID:-$SERVICE_USER}" SERVICE_USER="${PUID:-$SERVICE_USER}"
SERVICE_GROUP="${PGID:-$SERVICE_GROUP}" SERVICE_GROUP="${PGID:-$SERVICE_GROUP}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Set user and group ID # Set user and group ID
SERVICE_UID="${SERVICE_UID:-0}" # set the user id SERVICE_UID="${SERVICE_UID:-0}" # set the user id
SERVICE_GID="${SERVICE_GID:-0}" # set the group id SERVICE_GID="${SERVICE_GID:-0}" # set the group id
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# 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:-alpine}" # execute command as another user SERVICE_USER="${SERVICE_USER:-entrypoint.sh}" # execute command as another user
SERVICE_GROUP="${SERVICE_GROUP:-alpine}" # Set the service group SERVICE_GROUP="${SERVICE_GROUP:-entrypoint.sh}" # Set the service group
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Secondary ports # Secondary ports
SERVER_PORTS="" # specifiy other ports SERVER_PORTS="" # specifiy other ports
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Primary server port- will be added to server ports # Primary server port- will be added to server ports
WEB_SERVER_PORT="" # port : 80,443 WEB_SERVER_PORT="" # port : 80,443
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Healthcheck variables # Healthcheck variables
HEALTH_ENABLED="yes" # enable healthcheck [yes/no] HEALTH_ENABLED="yes" # enable healthcheck [yes/no]
SERVICES_LIST="tini" # comma seperated list of processes for the healthcheck SERVICES_LIST="tini" # comma seperated list of processes for the healthcheck
HEALTH_ENDPOINTS="" # url endpoints: [http://localhost/health,http://localhost/test] HEALTH_ENDPOINTS="" # url endpoints: [http://localhost/health,http://localhost/test]
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Update path var # Update path var
export PATH RUNAS_USER SERVICE_USER SERVICE_GROUP SERVICE_UID SERVICE_GID WWW_ROOT_DIR DATABASE_DIR export PATH RUNAS_USER SERVICE_USER SERVICE_GROUP SERVICE_UID SERVICE_GID WWW_ROOT_DIR DATABASE_DIR
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Custom variables # Custom variables
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# show message # show message
__run_message() { __run_message() {
return return
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
################## END OF CONFIGURATION ##################### ################## END OF CONFIGURATION #####################
# Lets get containers ip address # Lets get containers ip address
IP4_ADDRESS="$(__get_ip4)" IP4_ADDRESS="$(__get_ip4)"
IP6_ADDRESS="$(__get_ip6)" IP6_ADDRESS="$(__get_ip6)"
CONTAINER_IP4_ADDRESS="${CONTAINER_IP4_ADDRESS:-$IP4_ADDRESS}" CONTAINER_IP4_ADDRESS="${CONTAINER_IP4_ADDRESS:-$IP4_ADDRESS}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Startup variables # Startup variables
export INIT_DATE="${INIT_DATE:-$(date)}" export INIT_DATE="${INIT_DATE:-$(date)}"
export CONTAINER_INIT="${CONTAINER_INIT:-no}" export CONTAINER_INIT="${CONTAINER_INIT:-no}"
@@ -125,14 +125,14 @@ export ENTRYPOINT_FIRST_RUN="${ENTRYPOINT_FIRST_RUN:-yes}"
export DATA_DIR_INITIALIZED="${DATA_DIR_INITIALIZED:-no}" export DATA_DIR_INITIALIZED="${DATA_DIR_INITIALIZED:-no}"
export CONFIG_DIR_INITIALIZED="${CONFIG_DIR_INITIALIZED:-no}" export CONFIG_DIR_INITIALIZED="${CONFIG_DIR_INITIALIZED:-no}"
export CONTAINER_NAME="${ENV_CONTAINER_NAME:-$CONTAINER_NAME}" export CONTAINER_NAME="${ENV_CONTAINER_NAME:-$CONTAINER_NAME}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# System # System
export LANG="${LANG:-C.UTF-8}" export LANG="${LANG:-C.UTF-8}"
export LC_ALL="${LANG:-C.UTF-8}" export LC_ALL="${LANG:-C.UTF-8}"
export TZ="${TZ:-${TIMEZONE:-America/New_York}}" export TZ="${TZ:-${TIMEZONE:-America/New_York}}"
export HOSTNAME="$(hostname -s)" export HOSTNAME="$(hostname -s)"
export DOMAINNAME="$(hostname -d)" export DOMAINNAME="$(hostname -d)"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Default directories # Default directories
export SSL_DIR="${SSL_DIR:-/config/ssl}" export SSL_DIR="${SSL_DIR:-/config/ssl}"
export SSL_CA="${SSL_CERT:-/config/ssl/ca.crt}" export SSL_CA="${SSL_CERT:-/config/ssl/ca.crt}"
@@ -142,12 +142,12 @@ 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_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_CONF_DIR="${DEFAULT_CONF_DIR:-/usr/local/share/template-files/config}"
export DEFAULT_TEMPLATE_DIR="${DEFAULT_TEMPLATE_DIR:-/usr/local/share/template-files/defaults}" 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:-}"
export BACKUP_RUN_CRON="${BACKUP_RUN_CRON:-}" export BACKUP_RUN_CRON="${BACKUP_RUN_CRON:-}"
export BACKUP_DIR="${BACKUP_DIR:-/data/backups}" export BACKUP_DIR="${BACKUP_DIR:-/data/backups}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Additional # Additional
export PHP_INI_DIR="${PHP_INI_DIR:-$(__find_php_ini)}" export PHP_INI_DIR="${PHP_INI_DIR:-$(__find_php_ini)}"
export PHP_BIN_DIR="${PHP_BIN_DIR:-$(__find_php_bin)}" export PHP_BIN_DIR="${PHP_BIN_DIR:-$(__find_php_bin)}"
@@ -160,7 +160,7 @@ export ENTRYPOINT_PID_FILE="${ENTRYPOINT_PID_FILE:-$ENTRYPOINT_PID_FILE}"
export ENTRYPOINT_INIT_FILE="${ENTRYPOINT_INIT_FILE:-/config/.entrypoint.done}" export ENTRYPOINT_INIT_FILE="${ENTRYPOINT_INIT_FILE:-/config/.entrypoint.done}"
export ENTRYPOINT_DATA_INIT_FILE="${ENTRYPOINT_DATA_INIT_FILE:-/data/.docker_has_run}" export ENTRYPOINT_DATA_INIT_FILE="${ENTRYPOINT_DATA_INIT_FILE:-/data/.docker_has_run}"
export ENTRYPOINT_CONFIG_INIT_FILE="${ENTRYPOINT_CONFIG_INIT_FILE:-/config/.docker_has_run}" export ENTRYPOINT_CONFIG_INIT_FILE="${ENTRYPOINT_CONFIG_INIT_FILE:-/config/.docker_has_run}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -n "$CONTAINER_WEB_SERVER_WWW_REPO" ]; then if [ -n "$CONTAINER_WEB_SERVER_WWW_REPO" ]; then
www_temp_dir="/tmp/git/$(basename -- "$CONTAINER_WEB_SERVER_WWW_REPO")" www_temp_dir="/tmp/git/$(basename -- "$CONTAINER_WEB_SERVER_WWW_REPO")"
rm -Rf "${WWW_ROOT_DIR:?}"/* "${www_temp_dir:?}"/* rm -Rf "${WWW_ROOT_DIR:?}"/* "${www_temp_dir:?}"/*
@@ -170,42 +170,42 @@ if [ -n "$CONTAINER_WEB_SERVER_WWW_REPO" ]; then
rsync -ra "$www_temp_dir/" "$WWW_ROOT_DIR" --delete >/dev/null 2>&1 rsync -ra "$www_temp_dir/" "$WWW_ROOT_DIR" --delete >/dev/null 2>&1
rm -Rf "$www_temp_dir" rm -Rf "$www_temp_dir"
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# variables based on env/files # variables based on env/files
[ -f "/config/enable/ssl" ] && SSL_ENABLED="yes" [ -f "/config/enable/ssl" ] && SSL_ENABLED="yes"
[ -f "/config/enable/ssh" ] && SSH_ENABLED="yes" [ -f "/config/enable/ssh" ] && SSH_ENABLED="yes"
[ "$WEB_SERVER_PORT" = "443" ] && SSL_ENABLED="yes" [ "$WEB_SERVER_PORT" = "443" ] && SSL_ENABLED="yes"
[ "$CONTAINER_WEB_SERVER_PROTOCOL" = "https" ] && SSL_ENABLED="yes" [ "$CONTAINER_WEB_SERVER_PROTOCOL" = "https" ] && SSL_ENABLED="yes"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# export variables # export variables
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# is already Initialized # is already Initialized
[ -f "$ENTRYPOINT_DATA_INIT_FILE" ] && DATA_DIR_INITIALIZED="yes" || DATA_DIR_INITIALIZED="no" [ -f "$ENTRYPOINT_DATA_INIT_FILE" ] && DATA_DIR_INITIALIZED="yes" || DATA_DIR_INITIALIZED="no"
[ -f "$ENTRYPOINT_CONFIG_INIT_FILE" ] && CONFIG_DIR_INITIALIZED="yes" || CONFIG_DIR_INITIALIZED="no" [ -f "$ENTRYPOINT_CONFIG_INIT_FILE" ] && CONFIG_DIR_INITIALIZED="yes" || CONFIG_DIR_INITIALIZED="no"
{ [ -f "$ENTRYPOINT_PID_FILE" ] || [ -f "$ENTRYPOINT_INIT_FILE" ]; } && ENTRYPOINT_FIRST_RUN="no" || ENTRYPOINT_FIRST_RUN="yes" { [ -f "$ENTRYPOINT_PID_FILE" ] || [ -f "$ENTRYPOINT_INIT_FILE" ]; } && ENTRYPOINT_FIRST_RUN="no" || ENTRYPOINT_FIRST_RUN="yes"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# 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//\/*/}" # WEB_SERVER_PORTS="${WEB_SERVER_PORT//\/*/}" #
WEB_SERVER_PORTS="${WEB_SERVER_PORTS//\/*/}" # WEB_SERVER_PORTS="${WEB_SERVER_PORTS//\/*/}" #
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)"
WEB_SERVER_PORTS="$(__format_variables "$WEB_SERVER_PORTS" || false)" WEB_SERVER_PORTS="$(__format_variables "$WEB_SERVER_PORTS" || false)"
ENV_PORTS="$(__format_variables "$SERVER_PORTS" "$WEB_SERVER_PORTS" "$ENV_PORTS" "$SERVER_PORTS" || false)" ENV_PORTS="$(__format_variables "$SERVER_PORTS" "$WEB_SERVER_PORTS" "$ENV_PORTS" "$SERVER_PORTS" || false)"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Remove the commas from env # Remove the commas from env
HEALTH_ENDPOINTS="${HEALTH_ENDPOINTS//,/ }" HEALTH_ENDPOINTS="${HEALTH_ENDPOINTS//,/ }"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# create required directories # create required directories
mkdir -p "/run" mkdir -p "/run"
mkdir -p "/tmp" mkdir -p "/tmp"
@@ -218,11 +218,11 @@ mkdir -p "/run/init.d"
mkdir -p "/config/enable" mkdir -p "/config/enable"
mkdir -p "/config/secure" mkdir -p "/config/secure"
mkdir -p "/usr/local/etc/docker/exec" mkdir -p "/usr/local/etc/docker/exec"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# create required files # create required files
touch "/data/logs/start.log" touch "/data/logs/start.log"
touch "/data/logs/entrypoint.log" touch "/data/logs/entrypoint.log"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# fix permissions # fix permissions
chmod -f 777 "/run" chmod -f 777 "/run"
chmod -f 777 "/tmp" chmod -f 777 "/tmp"
@@ -236,40 +236,40 @@ chmod -f 777 "/config/enable"
chmod -f 777 "/config/secure" chmod -f 777 "/config/secure"
chmod -f 777 "/data/logs/entrypoint.log" chmod -f 777 "/data/logs/entrypoint.log"
chmod -f 777 "/usr/local/etc/docker/exec" chmod -f 777 "/usr/local/etc/docker/exec"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# lets ensure everyone can write to std* # lets ensure everyone can write to std*
[ -f "/dev/stdin" ] && chmod -f 777 "/dev/stdin" [ -f "/dev/stdin" ] && chmod -f 777 "/dev/stdin"
[ -f "/dev/stderr" ] && chmod -f 777 "/dev/stderr" [ -f "/dev/stderr" ] && chmod -f 777 "/dev/stderr"
[ -f "/dev/stdout" ] && chmod -f 777 "/dev/stdout" [ -f "/dev/stdout" ] && chmod -f 777 "/dev/stdout"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
cat <<EOF | tee /etc/profile.d/locales.shadow /etc/profile.d/locales.sh >/dev/null cat <<EOF | tee /etc/profile.d/locales.shadow /etc/profile.d/locales.sh >/dev/null
export LANG="\${LANG:-C.UTF-8}" export LANG="\${LANG:-C.UTF-8}"
export LC_ALL="\${LANG:-C.UTF-8}" export LC_ALL="\${LANG:-C.UTF-8}"
export TZ="\${TZ:-\${TIMEZONE:-America/New_York}}" export TZ="\${TZ:-\${TIMEZONE:-America/New_York}}"
EOF EOF
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Create the backup dir # Create the backup dir
[ -n "$BACKUP_DIR" ] && { [ -d "$BACKUP_DIR" ] || mkdir -p "$BACKUP_DIR"; } [ -n "$BACKUP_DIR" ] && { [ -d "$BACKUP_DIR" ] || mkdir -p "$BACKUP_DIR"; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -f "$ENTRYPOINT_INIT_FILE" ]; then if [ -f "$ENTRYPOINT_INIT_FILE" ]; then
ENTRYPOINT_MESSAGE="no" ENTRYPOINT_FIRST_RUN="no" ENTRYPOINT_MESSAGE="no" ENTRYPOINT_FIRST_RUN="no"
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
if [ "$ENTRYPOINT_FIRST_RUN" != "no" ]; then if [ "$ENTRYPOINT_FIRST_RUN" != "no" ]; then
# Show start message # Show start message
if [ "$CONFIG_DIR_INITIALIZED" = "no" ] || [ "$DATA_DIR_INITIALIZED" = "no" ]; then if [ "$CONFIG_DIR_INITIALIZED" = "no" ] || [ "$DATA_DIR_INITIALIZED" = "no" ]; then
[ "$ENTRYPOINT_MESSAGE" = "yes" ] && echo "Executing entrypoint script for alpine" [ "$ENTRYPOINT_MESSAGE" = "yes" ] && echo "Executing entrypoint script for entrypoint.sh"
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Set reusable variables # Set reusable variables
{ { [ -w "/etc" ] && [ ! -f "/etc/hosts" ]; } || [ -w "/etc/hosts" ]; } && UPDATE_FILE_HOSTS="yes" && touch "/etc/hosts" { { [ -w "/etc" ] && [ ! -f "/etc/hosts" ]; } || [ -w "/etc/hosts" ]; } && UPDATE_FILE_HOSTS="yes" && touch "/etc/hosts"
{ { [ -w "/etc" ] && [ ! -f "/etc/timezone" ]; } || [ -w "/etc/timezone" ]; } && UPDATE_FILE_TZ="yes" && touch "/etc/timezone" { { [ -w "/etc" ] && [ ! -f "/etc/timezone" ]; } || [ -w "/etc/timezone" ]; } && UPDATE_FILE_TZ="yes" && touch "/etc/timezone"
{ { [ -w "/etc" ] && [ ! -f "/etc/resolv.conf" ]; } || [ -w "/etc/resolv.conf" ]; } && UPDATE_FILE_RESOLV="yes" && touch "/etc/resolv.conf" { { [ -w "/etc" ] && [ ! -f "/etc/resolv.conf" ]; } || [ -w "/etc/resolv.conf" ]; } && UPDATE_FILE_RESOLV="yes" && touch "/etc/resolv.conf"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Set timezone # Set timezone
[ -n "$TZ" ] && [ "$UPDATE_FILE_TZ" = "yes" ] && echo "$TZ" >"/etc/timezone" [ -n "$TZ" ] && [ "$UPDATE_FILE_TZ" = "yes" ] && echo "$TZ" >"/etc/timezone"
[ -f "/usr/share/zoneinfo/$TZ" ] && [ "$UPDATE_FILE_TZ" = "yes" ] && ln -sf "/usr/share/zoneinfo/$TZ" "/etc/localtime" [ -f "/usr/share/zoneinfo/$TZ" ] && [ "$UPDATE_FILE_TZ" = "yes" ] && ln -sf "/usr/share/zoneinfo/$TZ" "/etc/localtime"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# if ipv6 add it to /etc/hosts # if ipv6 add it to /etc/hosts
if [ "$UPDATE_FILE_HOSTS" = "yes" ]; then if [ "$UPDATE_FILE_HOSTS" = "yes" ]; then
echo "# known hostname mappings" >"/etc/hosts" echo "# known hostname mappings" >"/etc/hosts"
@@ -280,87 +280,87 @@ if [ "$ENTRYPOINT_FIRST_RUN" != "no" ]; then
__printf_space "40" "127.0.0.1" "localhost" >>"/etc/hosts" __printf_space "40" "127.0.0.1" "localhost" >>"/etc/hosts"
fi fi
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# add .internal domain # add .internal domain
if [ "$UPDATE_FILE_HOSTS" = "yes" ] && [ -n "$HOSTNAME" ]; then if [ "$UPDATE_FILE_HOSTS" = "yes" ] && [ -n "$HOSTNAME" ]; then
__grep_test " $HOSTNAME" "/etc/hosts" || __printf_space "40" "${CONTAINER_IP4_ADDRESS:-127.0.0.1}" "$HOSTNAME" >>"/etc/hosts" __grep_test " $HOSTNAME" "/etc/hosts" || __printf_space "40" "${CONTAINER_IP4_ADDRESS:-127.0.0.1}" "$HOSTNAME" >>"/etc/hosts"
__grep_test " ${HOSTNAME%%.*}.internal" "/etc/hosts" || __printf_space "40" "${CONTAINER_IP4_ADDRESS:-127.0.0.1}" "${HOSTNAME%%.*}.internal" >>"/etc/hosts" __grep_test " ${HOSTNAME%%.*}.internal" "/etc/hosts" || __printf_space "40" "${CONTAINER_IP4_ADDRESS:-127.0.0.1}" "${HOSTNAME%%.*}.internal" >>"/etc/hosts"
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# add domainname # add domainname
if [ "$UPDATE_FILE_HOSTS" = "yes" ] && [ "$DOMAINNAME" != "internal" ] && [ -n "$DOMAINNAME" ] && [ "$HOSTNAME.$DOMAINNAME" != "$DOMAINNAME" ]; then if [ "$UPDATE_FILE_HOSTS" = "yes" ] && [ "$DOMAINNAME" != "internal" ] && [ -n "$DOMAINNAME" ] && [ "$HOSTNAME.$DOMAINNAME" != "$DOMAINNAME" ]; then
__grep_test " ${HOSTNAME%%.*}.$DOMAINNAME" "/etc/hosts" || __printf_space "40" "${CONTAINER_IP4_ADDRESS:-127.0.0.1}" "${HOSTNAME%%.*}.$DOMAINNAME" >>"/etc/hosts" __grep_test " ${HOSTNAME%%.*}.$DOMAINNAME" "/etc/hosts" || __printf_space "40" "${CONTAINER_IP4_ADDRESS:-127.0.0.1}" "${HOSTNAME%%.*}.$DOMAINNAME" >>"/etc/hosts"
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Set containers hostname # Set containers hostname
[ -n "$HOSTNAME" ] && [ "$UPDATE_FILE_HOSTS" = "yes" ] && echo "$HOSTNAME" >"/etc/hostname" [ -n "$HOSTNAME" ] && [ "$UPDATE_FILE_HOSTS" = "yes" ] && echo "$HOSTNAME" >"/etc/hostname"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -f "/etc/hostname" ]; then if [ -f "/etc/hostname" ]; then
[ -n "$(type -P hostname)" ] && hostname -F "/etc/hostname" &>/dev/null || HOSTNAME="$(<"/etc/hostname")" [ -n "$(type -P hostname)" ] && hostname -F "/etc/hostname" &>/dev/null || HOSTNAME="$(<"/etc/hostname")"
export HOSTNAME export HOSTNAME
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# import hosts file into container # import hosts file into container
[ -f "/usr/local/etc/hosts" ] && [ "$UPDATE_FILE_HOSTS" = "yes" ] && cat "/usr/local/etc/hosts" | grep -vF "$HOSTNAME" >>"/etc/hosts" [ -f "/usr/local/etc/hosts" ] && [ "$UPDATE_FILE_HOSTS" = "yes" ] && cat "/usr/local/etc/hosts" | grep -vF "$HOSTNAME" >>"/etc/hosts"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# import resolv.conf file into container # import resolv.conf file into container
[ "$CUSTOM_DNS" != "yes" ] && [ -f "/usr/local/etc/resolv.conf" ] && [ "$UPDATE_FILE_RESOLV" = "yes" ] && cat "/usr/local/etc/resolv.conf" >"/etc/resolv.conf" [ "$CUSTOM_DNS" != "yes" ] && [ -f "/usr/local/etc/resolv.conf" ] && [ "$UPDATE_FILE_RESOLV" = "yes" ] && cat "/usr/local/etc/resolv.conf" >"/etc/resolv.conf"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -n "$HOME" ] && [ -d "/usr/local/etc/skel" ]; then if [ -n "$HOME" ] && [ -d "/usr/local/etc/skel" ]; then
[ -d "$HOME" ] && cp -Rf "/usr/local/etc/skel/." "$HOME/" [ -d "$HOME" ] && cp -Rf "/usr/local/etc/skel/." "$HOME/"
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Delete any .gitkeep files # Delete any .gitkeep files
[ -d "/data" ] && rm -Rf "/data/.gitkeep" "/data"/*/*.gitkeep [ -d "/data" ] && rm -Rf "/data/.gitkeep" "/data"/*/*.gitkeep
[ -d "/config" ] && rm -Rf "/config/.gitkeep" "/config"/*/*.gitkeep [ -d "/config" ] && rm -Rf "/config/.gitkeep" "/config"/*/*.gitkeep
[ -f "/usr/local/bin/.gitkeep" ] && rm -Rf "/usr/local/bin/.gitkeep" [ -f "/usr/local/bin/.gitkeep" ] && rm -Rf "/usr/local/bin/.gitkeep"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# 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/ # Copy default system configs - /usr/local/share/template-files/defaults > /config/
__initialize_default_templates __initialize_default_templates
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Copy custom config files - /usr/local/share/template-files/config > /config/ # Copy custom config files - /usr/local/share/template-files/config > /config/
__initialize_config_dir __initialize_config_dir
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Copy custom data files - /usr/local/share/template-files/data > /data/ # Copy custom data files - /usr/local/share/template-files/data > /data/
__initialize_data_dir __initialize_data_dir
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__initialize_ssl_certs __initialize_ssl_certs
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -f "$ENTRYPOINT_INIT_FILE" ]; then if [ -f "$ENTRYPOINT_INIT_FILE" ]; then
ENTRYPOINT_FIRST_RUN="no" ENTRYPOINT_FIRST_RUN="no"
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -d "/config" ]; then if [ -d "/config" ]; then
echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_INIT_FILE" echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_INIT_FILE"
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Check if this is a new container # Check if this is a new container
if [ -f "$ENTRYPOINT_DATA_INIT_FILE" ]; then if [ -f "$ENTRYPOINT_DATA_INIT_FILE" ]; then
DATA_DIR_INITIALIZED="yes" DATA_DIR_INITIALIZED="yes"
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -d "/data" ]; then if [ -d "/data" ]; then
echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_DATA_INIT_FILE" echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_DATA_INIT_FILE"
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -f "$ENTRYPOINT_CONFIG_INIT_FILE" ]; then if [ -f "$ENTRYPOINT_CONFIG_INIT_FILE" ]; then
CONFIG_DIR_INITIALIZED="yes" CONFIG_DIR_INITIALIZED="yes"
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -d "/config" ]; then if [ -d "/config" ]; then
echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_CONFIG_INIT_FILE" echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_CONFIG_INIT_FILE"
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
if [ "$ENTRYPOINT_FIRST_RUN" != "no" ]; then if [ "$ENTRYPOINT_FIRST_RUN" != "no" ]; then
# setup the smtp server # setup the smtp server
__setup_mta __setup_mta
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# if no pid assume container restart - clean stale files on restart # if no pid assume container restart - clean stale files on restart
if [ -f "$ENTRYPOINT_PID_FILE" ]; then if [ -f "$ENTRYPOINT_PID_FILE" ]; then
START_SERVICES="no" START_SERVICES="no"
@@ -370,14 +370,14 @@ else
# Clean any stale PID files on first run # 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 fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
if [ ! -f "/run/__start_init_scripts.pid" ]; then if [ ! -f "/run/__start_init_scripts.pid" ]; then
START_SERVICES="yes" START_SERVICES="yes"
touch /run/__start_init_scripts.pid touch /run/__start_init_scripts.pid
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
[ "$ENTRYPOINT_MESSAGE" = "yes" ] && __printf_space "40" "Container ip address is:" "$CONTAINER_IP4_ADDRESS" [ "$ENTRYPOINT_MESSAGE" = "yes" ] && __printf_space "40" "The containers ip address is:" "$CONTAINER_IP4_ADDRESS"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Show configured listing processes # Show configured listing processes
if [ "$ENTRYPOINT_MESSAGE" = "yes" ] && [ -n "$ENV_PORTS" ]; then if [ "$ENTRYPOINT_MESSAGE" = "yes" ] && [ -n "$ENV_PORTS" ]; then
show_port="" show_port=""
@@ -385,22 +385,22 @@ if [ "$ENTRYPOINT_MESSAGE" = "yes" ] && [ -n "$ENV_PORTS" ]; then
__printf_space "40" "The following ports are open:" "$show_port" __printf_space "40" "The following ports are open:" "$show_port"
unset port show_port unset port show_port
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# execute init script # execute init script
if [ -f "/tmp/init" ]; then sh "/tmp/init"; fi if [ -f "/tmp/init" ]; then sh "/tmp/init"; fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# create user if needed # create user if needed
__create_service_user "$SERVICE_USER" "$SERVICE_GROUP" "${WORK_DIR:-/home/$SERVICE_USER}" "${SERVICE_UID:-}" "${SERVICE_GID:-}" __create_service_user "$SERVICE_USER" "$SERVICE_GROUP" "${WORK_DIR:-/home/$SERVICE_USER}" "${SERVICE_UID:-}" "${SERVICE_GID:-}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Modify user if needed # Modify user if needed
__set_user_group_id $SERVICE_USER ${SERVICE_UID:-} ${SERVICE_GID:-} __set_user_group_id $SERVICE_USER ${SERVICE_UID:-} ${SERVICE_GID:-}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Show message # Show message
__run_message __run_message
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Just start services # Just start services
START_SERVICES="${START_SERVICES:-SYSTEM_INIT}" START_SERVICES="${START_SERVICES:-SYSTEM_INIT}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Start all services if no pidfile # Start all services if no pidfile
if [ "$START_SERVICES" = "yes" ] && [ "$1" != "backup" ] && [ "$1" != "healthcheck" ] && [ "$1" != "cron" ] && [ "$1" != "tail" ] && [ "$1" != "logs" ] && [ "$1" != "cron" ]; then if [ "$START_SERVICES" = "yes" ] && [ "$1" != "backup" ] && [ "$1" != "healthcheck" ] && [ "$1" != "cron" ] && [ "$1" != "tail" ] && [ "$1" != "logs" ] && [ "$1" != "cron" ]; then
[ "$1" = "start" ] && shift 1 [ "$1" = "start" ] && shift 1
@@ -412,7 +412,7 @@ if [ "$START_SERVICES" = "yes" ] && [ "$1" != "backup" ] && [ "$1" != "healthche
START_SERVICES="no" START_SERVICES="no"
CONTAINER_INIT="${CONTAINER_INIT:-no}" CONTAINER_INIT="${CONTAINER_INIT:-no}"
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Begin options # Begin options
case "$1" in case "$1" in
init) init)
@@ -598,8 +598,8 @@ start)
exit $? exit $?
;; ;;
esac esac
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# end of entrypoint # end of entrypoint
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# ex: ts=2 sw=2 et filetype=sh # ex: ts=2 sw=2 et filetype=sh

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck shell=bash # shellcheck shell=bash
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
##@Version : 202407241259-git ##@Version : 202407241259-git
# @@Author : Jason Hempstead # @@Author : Jason Hempstead
# @@Contact : git-admin@casjaysdev.pro # @@Contact : git-admin@casjaysdev.pro
@@ -17,15 +17,15 @@
# @@Terminal App : no # @@Terminal App : no
# @@sudo/root : no # @@sudo/root : no
# @@Template : functions/docker-entrypoint # @@Template : functions/docker-entrypoint
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2120,SC2155,SC2199,SC2317,SC2329 # shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2120,SC2155,SC2199,SC2317,SC2329
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# setup debugging - https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html # setup debugging - https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
[ -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")" || true
{ [ "$DEBUGGER" = "on" ] || [ -f "/config/.debug" ]; } && echo "Enabling debugging" && set -xo pipefail -x$DEBUGGER_OPTIONS && export DEBUGGER="on" || set -o pipefail { [ "$DEBUGGER" = "on" ] || [ -f "/config/.debug" ]; } && set -xo pipefail -x$DEBUGGER_OPTIONS && export DEBUGGER="on" || set -o pipefail
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__remove_extra_spaces() { sed 's/\( \)*/\1/g;s|^ ||g'; } __remove_extra_spaces() { sed 's/\( \)*/\1/g;s|^ ||g'; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__printf_space() { __printf_space() {
local pad=$(printf '%0.1s' " "{1..60}) local pad=$(printf '%0.1s' " "{1..60})
local padlength=$1 local padlength=$1
@@ -37,7 +37,7 @@ __printf_space() {
message+="$(printf '%s\n' "$string2") " message+="$(printf '%s\n' "$string2") "
printf '%s\n' "$message" printf '%s\n' "$message"
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__rm() { [ -n "$1" ] && [ -e "$1" ] && rm -Rf "${1:?}"; } __rm() { [ -n "$1" ] && [ -e "$1" ] && rm -Rf "${1:?}"; }
__grep_test() { grep -sh "$1" "$2" | grep -qwF "${3:-$1}" || return 1; } __grep_test() { grep -sh "$1" "$2" | grep -qwF "${3:-$1}" || return 1; }
__netstat() { [ -f "$(type -P netstat)" ] && netstat "$@" || return 10; } __netstat() { [ -f "$(type -P netstat)" ] && netstat "$@" || return 10; }
@@ -45,41 +45,59 @@ __cd() { { [ -d "$1" ] || mkdir -p "$1"; } && builtin cd "$1" || return 1; }
__is_in_file() { [ -e "$2" ] && grep -Rsq "$1" "$2" && return 0 || 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; } __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; } __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; } __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; } __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; } __ps() { [ -f "$(type -P ps)" ] && ps "$@" 2>/dev/null | sed 's|:||g' | grep -Fw " ${1:-$SERVICE_NAME}$" || return 10; }
__is_dir_empty() { if [ -n "$1" ]; then [ "$(ls -A "$1" 2>/dev/null | wc -l)" -eq 0 ] && return 0 || return 1; else return 1; fi; } __is_dir_empty() { if [ -n "$1" ]; then [ "$(ls -A "$1" 2>/dev/null | wc -l)" -eq 0 ] && return 0 || return 1; else return 1; fi; }
__get_ip6() { ip a 2>/dev/null | grep -w 'inet6' | awk '{print $2}' | grep -vE '^::1|^fe' | sed 's|/.*||g' | head -n1 | grep '.' || echo ''; } __get_ip6() { ip a 2>/dev/null | grep -w 'inet6' | awk '{print $2}' | grep -vE '^::1|^fe' | sed 's|/.*||g' | head -n1 | grep '.' || echo ''; }
__get_ip4() { ip a 2>/dev/null | grep -w 'inet' | awk '{print $2}' | grep -vE '^127.0.0' | sed 's|/.*||g' | head -n1 | grep '.' || echo '127.0.0.1'; } __get_ip4() { ip a 2>/dev/null | grep -w 'inet' | awk '{print $2}' | grep -vE '^127.0.0' | sed 's|/.*||g' | head -n1 | grep '.' || echo '127.0.0.1'; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__pgrep() { __pgrep() {
local count=3 local count=3
local srvc="${1:-SERVICE_NAME}" local srvc="${1:-SERVICE_NAME}"
while [ $count -ge 0 ]; do 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 sleep 1
count=$((count - 1)) count=$((count - 1))
done done
[ $count -ne 0 ] && return 0 || return 10 return 10
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__find_file_relative() { __find_file_relative() {
[ -e "$1" ] || return 0 [ -e "$1" ] || return 0
find "$1"/* -not -path '*env/*' -not -path '.git*' -type f 2>/dev/null | sed 's|'$1'/||g' | sort -u | grep -v '^$' | grep '.' || false find "$1"/* -not -path '*env/*' -not -path '.git*' -type f 2>/dev/null | sed 's|'$1'/||g' | sort -u | grep -v '^$' | grep '.' || false
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__find_directory_relative() { __find_directory_relative() {
[ -d "$1" ] || return 0 [ -d "$1" ] || return 0
find "$1"/* -not -path '*env/*' -not -path '.git*' -type d 2>/dev/null | sed 's|'$1'/||g' | sort -u | grep -v '^$' | grep '.' || false 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; } __pid_exists() {
__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; } local result=""
__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; } 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; } __format_variables() { printf '%s\n' "${@//,/ }" | tr ' ' '\n' | sort -RVu | grep -v '^$' | tr '\n' ' ' | __clean_variables | grep '.' || return 0; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__clean_variables() { __clean_variables() {
local var="$*" local var="$*"
var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters
@@ -87,7 +105,7 @@ __clean_variables() {
var="$(printf '%s\n' "$var" | sed 's/\( \)*/\1/g;s|^ ||g')" var="$(printf '%s\n' "$var" | sed 's/\( \)*/\1/g;s|^ ||g')"
printf '%s' "$var" | grep -v '^$' printf '%s' "$var" | grep -v '^$'
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__no_exit() { __no_exit() {
local monitor_interval="${SERVICE_MONITOR_INTERVAL:-60}" local monitor_interval="${SERVICE_MONITOR_INTERVAL:-60}"
local failure_threshold="${SERVICE_FAILURE_THRESHOLD:-3}" local failure_threshold="${SERVICE_FAILURE_THRESHOLD:-3}"
@@ -127,7 +145,7 @@ __no_exit() {
wait wait
" "
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__trim() { __trim() {
local var="${*//;/ }" local var="${*//;/ }"
var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters
@@ -135,14 +153,14 @@ __trim() {
var="$(echo "$var" | __remove_extra_spaces | sed "s| |; |g;s|;$| |g" | __remove_extra_spaces)" var="$(echo "$var" | __remove_extra_spaces | sed "s| |; |g;s|;$| |g" | __remove_extra_spaces)"
printf '%s' "$var" | sed 's|;||g' | grep -v '^$' printf '%s' "$var" | sed 's|;||g' | grep -v '^$'
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__banner() { __banner() {
local message="$*" local message="$*"
local total_width=80 local total_width=80
local content_width=$((total_width - 14)) # Account for "# - - - " and " - - - #" local content_width=$((total_width - 14)) # Account for "# - - - " and " - - - #"
printf '# - - - %-*s - - - #\n' "$content_width" "$message" printf '# - - - %-*s - - - #\n' "$content_width" "$message"
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__service_banner() { __service_banner() {
local icon="${1:-🔧}" local icon="${1:-🔧}"
local message="${2:-Processing}" local message="${2:-Processing}"
@@ -154,23 +172,23 @@ __service_banner() {
local text_width=$((content_width - icon_width * 2 - 2)) # Account for both icons and spaces local text_width=$((content_width - icon_width * 2 - 2)) # Account for both icons and spaces
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 | grep '.' || echo ''; } __find_php_bin() { find -L '/usr'/*bin -maxdepth 4 -name 'php-fpm*' 2>/dev/null | head -n1 | grep '.' || echo ''; }
__find_php_ini() { find -L '/etc' -maxdepth 4 -name 'php.ini' 2>/dev/null | head -n1 | sed 's|/php.ini||g' | grep '.' || echo ''; } __find_php_ini() { find -L '/etc' -maxdepth 4 -name 'php.ini' 2>/dev/null | head -n1 | sed 's|/php.ini||g' | grep '.' || echo ''; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__find_nginx_conf() { find -L '/etc' -maxdepth 4 -name 'nginx.conf' 2>/dev/null | head -n1 | grep '.' || echo ''; } __find_nginx_conf() { find -L '/etc' -maxdepth 4 -name 'nginx.conf' 2>/dev/null | head -n1 | grep '.' || echo ''; }
__find_caddy_conf() { find -L '/etc' -maxdepth 4 -type f -iname 'caddy.conf' 2>/dev/null | head -n1 | grep '.' || echo ''; } __find_caddy_conf() { find -L '/etc' -maxdepth 4 -type f -iname 'caddy.conf' 2>/dev/null | head -n1 | grep '.' || echo ''; }
__find_lighttpd_conf() { find -L '/etc' -maxdepth 4 -type f -iname 'lighttpd.conf' 2>/dev/null | head -n1 | grep '.' || echo ''; } __find_lighttpd_conf() { find -L '/etc' -maxdepth 4 -type f -iname 'lighttpd.conf' 2>/dev/null | head -n1 | grep '.' || echo ''; }
__find_cherokee_conf() { find -L '/etc' -maxdepth 4 -type f -iname 'cherokee.conf' 2>/dev/null | head -n1 | grep '.' || echo ''; } __find_cherokee_conf() { find -L '/etc' -maxdepth 4 -type f -iname 'cherokee.conf' 2>/dev/null | head -n1 | grep '.' || echo ''; }
__find_httpd_conf() { find -L '/etc' -maxdepth 4 -type f -iname 'httpd.conf' -o -iname 'apache2.conf' 2>/dev/null | head -n1 | grep '.' || echo ''; } __find_httpd_conf() { find -L '/etc' -maxdepth 4 -type f -iname 'httpd.conf' -o -iname 'apache2.conf' 2>/dev/null | head -n1 | grep '.' || echo ''; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__find_mysql_conf() { find -L '/etc' -maxdepth 4 -type f -name 'my.cnf' 2>/dev/null | head -n1 | grep '.' || echo ''; } __find_mysql_conf() { find -L '/etc' -maxdepth 4 -type f -name 'my.cnf' 2>/dev/null | head -n1 | grep '.' || echo ''; }
__find_pgsql_conf() { find -L '/var/lib' '/etc' -maxdepth 8 -type f -name 'postgresql.conf' 2>/dev/null | head -n1 | grep '.' || echo ''; } __find_pgsql_conf() { find -L '/var/lib' '/etc' -maxdepth 8 -type f -name 'postgresql.conf' 2>/dev/null | head -n1 | grep '.' || echo ''; }
__find_couchdb_conf() { return; } __find_couchdb_conf() { return; }
__find_mongodb_conf() { return; } __find_mongodb_conf() { return; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__random_password() { cat "/dev/urandom" | tr -dc '0-9a-zA-Z' | head -c${1:-16} && echo ""; } __random_password() { cat "/dev/urandom" | tr -dc '0-9a-zA-Z' | head -c${1:-16} && echo ""; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__init_working_dir() { __init_working_dir() {
local service_name="$SERVICE_NAME" # get service name local service_name="$SERVICE_NAME" # get service name
local workdir="$(eval echo "${WORK_DIR:-}")" # expand variables local workdir="$(eval echo "${WORK_DIR:-}")" # expand variables
@@ -188,15 +206,15 @@ __init_working_dir() {
[ -n "$workdir" ] && { [ -d "$workdir" ] || mkdir -p "$workdir"; } [ -n "$workdir" ] && { [ -d "$workdir" ] || mkdir -p "$workdir"; }
[ "$SERVICE_USER" = "root" ] || [ -d "$home" ] && chmod -f 777 "$home" [ "$SERVICE_USER" = "root" ] || [ -d "$home" ] && chmod -f 777 "$home"
[ "$SERVICE_USER" = "root" ] || [ -d "$workdir" ] && chmod -f 777 "$workdir" [ "$SERVICE_USER" = "root" ] || [ -d "$workdir" ] && chmod -f 777 "$workdir"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# cd to dir # cd to dir
__cd "${workdir:-$home}" __cd "${workdir:-$home}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
echo "Setting the working directory to: $PWD" echo "Setting the working directory to: $PWD"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
export WORK_DIR="$workdir" HOME="$home" export WORK_DIR="$workdir" HOME="$home"
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__exec_service() { __exec_service() {
local count=6 local count=6
echo "Starting $1" echo "Starting $1"
@@ -206,7 +224,7 @@ __exec_service() {
__pgrep $1 && touch "/run/init.d/$1.pid" && break || count=$((count - 1)) __pgrep $1 && touch "/run/init.d/$1.pid" && break || count=$((count - 1))
done done
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__update_ssl_certs() { __update_ssl_certs() {
[ -f "/config/env/ssl.sh" ] && . "/config/env/ssl.sh" [ -f "/config/env/ssl.sh" ] && . "/config/env/ssl.sh"
if [ -f "$SSL_CERT" ] && [ -f "$SSL_KEY" ]; then if [ -f "$SSL_CERT" ] && [ -f "$SSL_KEY" ]; then
@@ -216,7 +234,7 @@ __update_ssl_certs() {
[ -f "$SSL_CERT" ] && cp -Rf "$SSL_CERT" "/etc/ssl/$SSL_CERT" [ -f "$SSL_CERT" ] && cp -Rf "$SSL_CERT" "/etc/ssl/$SSL_CERT"
fi fi
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__certbot() { __certbot() {
[ -n "$(type -P 'certbot')" ] || return 1 [ -n "$(type -P 'certbot')" ] || return 1
local options="$1" local options="$1"
@@ -277,7 +295,7 @@ __certbot() {
[ $statusCode -eq 0 ] && __update_ssl_certs [ $statusCode -eq 0 ] && __update_ssl_certs
return $statusCode return $statusCode
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__display_user_info() { __display_user_info() {
if [ -n "$user_name" ] || [ -n "$user_pass" ] || [ -n "$root_user_name" ] || [ -n "$root_user_pass" ]; then if [ -n "$user_name" ] || [ -n "$user_pass" ] || [ -n "$root_user_name" ] || [ -n "$root_user_pass" ]; then
__banner "User info" __banner "User info"
@@ -288,7 +306,7 @@ __display_user_info() {
__banner "" __banner ""
fi fi
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__init_config_etc() { __init_config_etc() {
local copy="no" local copy="no"
local name="$(find "/etc/$SERVICE_NAME" -maxdepth 0 2>/dev/null | head -n1)" local name="$(find "/etc/$SERVICE_NAME" -maxdepth 0 2>/dev/null | head -n1)"
@@ -303,7 +321,7 @@ __init_config_etc() {
__copy_templates "$etc_dir" "$conf_dir" __copy_templates "$etc_dir" "$conf_dir"
fi fi
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
} }
__create_ssl_cert() { __create_ssl_cert() {
local SSL_DIR="${SSL_DIR:-/etc/ssl}" local SSL_DIR="${SSL_DIR:-/etc/ssl}"
@@ -335,7 +353,7 @@ __create_ssl_cert() {
return 2 return 2
fi fi
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__init_apache() { __init_apache() {
local etc_dir="" conf_dir="" conf_dir="" www_dir="" apache_bin="" local etc_dir="" conf_dir="" conf_dir="" www_dir="" apache_bin=""
etc_dir="/etc/${1:-apache2}" etc_dir="/etc/${1:-apache2}"
@@ -345,7 +363,7 @@ __init_apache() {
# #
return 0 return 0
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__init_nginx() { __init_nginx() {
local etc_dir="/etc/${1:-nginx}" local etc_dir="/etc/${1:-nginx}"
local conf_dir="/config/${1:-nginx}" local conf_dir="/config/${1:-nginx}"
@@ -353,14 +371,14 @@ __init_nginx() {
local nginx_bin="$(type -P 'nginx')" local nginx_bin="$(type -P 'nginx')"
return 0 return 0
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__init_php() { __init_php() {
local etc_dir="/etc/${1:-php}" local etc_dir="/etc/${1:-php}"
local conf_dir="/config/${1:-php}" local conf_dir="/config/${1:-php}"
local php_bin="${PHP_BIN_DIR:-$(__find_php_bin)}" local php_bin="${PHP_BIN_DIR:-$(__find_php_bin)}"
return 0 return 0
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__init_mysql() { __init_mysql() {
local db_dir="/data/db/mysql" local db_dir="/data/db/mysql"
local etc_dir="${home:-/etc/${1:-mysql}}" local etc_dir="${home:-/etc/${1:-mysql}}"
@@ -373,28 +391,28 @@ __init_mysql() {
local mysqld_bin="$(type -P 'mysqld')" local mysqld_bin="$(type -P 'mysqld')"
return 0 return 0
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__init_mongodb() { __init_mongodb() {
local home="${MONGODB_CONFIG_FILE:-$(__find_mongodb_conf)}" local home="${MONGODB_CONFIG_FILE:-$(__find_mongodb_conf)}"
local user_name="${INITDB_ROOT_USERNAME:-root}" local user_name="${INITDB_ROOT_USERNAME:-root}"
local user_pass="${MONGO_INITDB_ROOT_PASSWORD:-$_ROOT_PASSWORD}" local user_pass="${MONGO_INITDB_ROOT_PASSWORD:-$_ROOT_PASSWORD}"
return return
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__init_postgres() { __init_postgres() {
local home="${PGSQL_CONFIG_FILE:-$(__find_pgsql_conf)}" local home="${PGSQL_CONFIG_FILE:-$(__find_pgsql_conf)}"
local user_name="${POSTGRES_USER:-root}" local user_name="${POSTGRES_USER:-root}"
local user_pass="${POSTGRES_PASSWORD:-$POSTGRES_ROOT_PASSWORD}" local user_pass="${POSTGRES_PASSWORD:-$POSTGRES_ROOT_PASSWORD}"
return return
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__init_couchdb() { __init_couchdb() {
local home="${COUCHDB_CONFIG_FILE:-$(__find_couchdb_conf)}" local home="${COUCHDB_CONFIG_FILE:-$(__find_couchdb_conf)}"
local user_name="${COUCHDB_USER:-root}" local user_name="${COUCHDB_USER:-root}"
local user_pass="${COUCHDB_PASSWORD:-$SET_RANDOM_PASS}" local user_pass="${COUCHDB_PASSWORD:-$SET_RANDOM_PASS}"
return return
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Show available init functions # Show available init functions
__init_help() { __init_help() {
echo ' echo '
@@ -404,7 +422,7 @@ __create_ssl_cert
' '
return return
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__run_once() { __run_once() {
if [ "$CONFIG_DIR_INITIALIZED" = "false" ] || [ "$DATA_DIR_INITIALIZED" = "false" ] || [ ! -f "/config/.docker_has_run" ]; then if [ "$CONFIG_DIR_INITIALIZED" = "false" ] || [ "$DATA_DIR_INITIALIZED" = "false" ] || [ ! -f "/config/.docker_has_run" ]; then
return 0 return 0
@@ -412,7 +430,7 @@ __run_once() {
return 1 return 1
fi fi
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# run program ever n minutes # run program ever n minutes
__cron() { __cron() {
trap 'retVal=$?;[ -f "/run/cron/$bin.run" ] && rm -Rf "/run/cron/$bin.run";[ -f "/run/cron/$bin.pid" ] && rm -Rf "/run/cron/$bin.pid";exit ${retVal:-0}' SIGINT ERR EXIT trap 'retVal=$?;[ -f "/run/cron/$bin.run" ] && rm -Rf "/run/cron/$bin.run";[ -f "/run/cron/$bin.pid" ] && rm -Rf "/run/cron/$bin.pid";exit ${retVal:-0}' SIGINT ERR EXIT
@@ -431,19 +449,19 @@ __cron() {
[ -f "/run/cron/$bin.run" ] || break [ -f "/run/cron/$bin.run" ] || break
done 2>/dev/stderr >>"/data/logs/cron.log" done 2>/dev/stderr >>"/data/logs/cron.log"
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__replace() { __replace() {
local search="$1" replace="$2" file="${3:-$2}" local search="$1" replace="$2" file="${3:-$2}"
[ -e "$file" ] || return 1 [ -e "$file" ] || return 1
__sed "$search" "$replace" "$file" || return 0 __sed "$search" "$replace" "$file" || return 0
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__find_replace() { __find_replace() {
local search="$1" replace="$2" file="${3:-$2}" local search="$1" replace="$2" file="${3:-$2}"
[ -e "$file" ] || return 1 [ -e "$file" ] || return 1
find "$file" -type f -not -path '.git*' -exec sed -i "s|$search|$replace|g" {} \; 2>/dev/null find "$file" -type f -not -path '.git*' -exec sed -i "s|$search|$replace|g" {} \; 2>/dev/null
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# /config > /etc # /config > /etc
__copy_templates() { __copy_templates() {
local from="$1" to="$2" local from="$1" to="$2"
@@ -453,7 +471,7 @@ __copy_templates() {
__file_copy "$from" "$to" __file_copy "$from" "$to"
fi fi
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# /config/file > /etc/file # /config/file > /etc/file
__symlink() { __symlink() {
local from="$1" to="$2" local from="$1" to="$2"
@@ -462,7 +480,7 @@ __symlink() {
ln -sf "$to" "$from" && echo "Created symlink to $from > $to" ln -sf "$to" "$from" && echo "Created symlink to $from > $to"
fi fi
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__file_copy() { __file_copy() {
local from="$1" local from="$1"
local dest="$2" local dest="$2"
@@ -492,7 +510,7 @@ __file_copy() {
fi fi
fi fi
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__generate_random_uids() { __generate_random_uids() {
local set_random_uid="$(seq 100 999 | sort -R | head -n 1)" local set_random_uid="$(seq 100 999 | sort -R | head -n 1)"
while :; do while :; do
@@ -504,7 +522,7 @@ __generate_random_uids() {
fi fi
done done
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__setup_directories() { __setup_directories() {
APPLICATION_DIRS="${APPLICATION_DIRS//,/ }" APPLICATION_DIRS="${APPLICATION_DIRS//,/ }"
APPLICATION_FILES="${APPLICATION_FILES//,/ }" APPLICATION_FILES="${APPLICATION_FILES//,/ }"
@@ -537,7 +555,7 @@ __setup_directories() {
fi fi
done done
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# set user on files/folders # set user on files/folders
__fix_permissions() { __fix_permissions() {
change_user="${1:-${SERVICE_USER:-root}}" change_user="${1:-${SERVICE_USER:-root}}"
@@ -562,14 +580,14 @@ __fix_permissions() {
fi fi
fi fi
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__get_gid() { grep "^$1:" /etc/group | awk -F ':' '{print $3}' || false; } __get_gid() { grep "^$1:" /etc/group | awk -F ':' '{print $3}' || false; }
__get_uid() { grep "^$1:" /etc/passwd | awk -F ':' '{print $3}' || false; } __get_uid() { grep "^$1:" /etc/passwd | awk -F ':' '{print $3}' || false; }
__check_for_uid() { cat "/etc/passwd" 2>/dev/null | awk -F ':' '{print $3}' | sort -u | grep -q "^$1$" || false; } __check_for_uid() { cat "/etc/passwd" 2>/dev/null | awk -F ':' '{print $3}' | sort -u | grep -q "^$1$" || false; }
__check_for_guid() { cat "/etc/group" 2>/dev/null | awk -F ':' '{print $3}' | sort -u | grep -q "^$1$" || false; } __check_for_guid() { cat "/etc/group" 2>/dev/null | awk -F ':' '{print $3}' | sort -u | grep -q "^$1$" || false; }
__check_for_user() { cat "/etc/passwd" 2>/dev/null | awk -F ':' '{print $1}' | sort -u | grep -q "^$1$" || false; } __check_for_user() { cat "/etc/passwd" 2>/dev/null | awk -F ':' '{print $1}' | sort -u | grep -q "^$1$" || false; }
__check_for_group() { cat "/etc/group" 2>/dev/null | awk -F ':' '{print $1}' | sort -u | grep -q "^$1$" || false; } __check_for_group() { cat "/etc/group" 2>/dev/null | awk -F ':' '{print $1}' | sort -u | grep -q "^$1$" || false; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# check if process is already running # check if process is already running
__proc_check() { __proc_check() {
cmd_bin="$(type -P "${1:-$EXEC_CMD_BIN}")" cmd_bin="$(type -P "${1:-$EXEC_CMD_BIN}")"
@@ -577,14 +595,13 @@ __proc_check() {
if __pgrep "$cmd_bin" || __pgrep "$cmd_name"; then if __pgrep "$cmd_bin" || __pgrep "$cmd_name"; then
SERVICE_IS_RUNNING="yes" SERVICE_IS_RUNNING="yes"
touch "$SERVICE_PID_FILE" touch "$SERVICE_PID_FILE"
echo "$cmd_name is already running"
return 0 return 0
else else
return 1 return 1
fi fi
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__set_user_group_id() { __set_user_group_id() {
local exitStatus=0 local exitStatus=0
local set_user="${1:-$SERVICE_USER}" local set_user="${1:-$SERVICE_USER}"
@@ -597,16 +614,16 @@ __set_user_group_id() {
[ -n "$set_user" ] && [ "$set_user" != "root" ] || return [ -n "$set_user" ] && [ "$set_user" != "root" ] || return
if grep -shq "^$set_user:" "/etc/passwd" "/etc/group"; then if grep -shq "^$set_user:" "/etc/passwd" "/etc/group"; then
if __check_for_guid "$set_gid"; then if __check_for_guid "$set_gid"; then
groupmod -g "${set_gid}" $set_user 2>/dev/stderr | tee -p -a "/data/logs/init.txt" >/dev/null && chown -Rf ":$set_gid" groupmod -g "${set_gid}" $set_user 2>/dev/stderr | tee -p -a "/data/logs/init.txt" >/dev/null
fi fi
if __check_for_uid "$set_uid"; then if __check_for_uid "$set_uid"; then
usermod -u "${set_uid}" -g "${set_gid}" $set_user 2>/dev/stderr | tee -p -a "/data/logs/init.txt" >/dev/null && chown -Rf $set_uid:$set_gid usermod -u "${set_uid}" -g "${set_gid}" $set_user 2>/dev/stderr | tee -p -a "/data/logs/init.txt" >/dev/null
fi fi
fi fi
export SERVICE_UID="$set_uid" export SERVICE_UID="$set_uid"
export SERVICE_GID="$set_gid" export SERVICE_GID="$set_gid"
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__create_service_user() { __create_service_user() {
local exitStatus=0 local exitStatus=0
local create_user="${1:-$SERVICE_USER}" local create_user="${1:-$SERVICE_USER}"
@@ -617,7 +634,9 @@ __create_service_user() {
local random_id="$(__generate_random_uids)" local random_id="$(__generate_random_uids)"
local create_home_dir="${create_home_dir:-/home/$create_user}" local create_home_dir="${create_home_dir:-/home/$create_user}"
grep -shq "^$create_user:" "/etc/passwd" && grep -shq "^$create_group:" "/etc/group" && return grep -shq "^$create_user:" "/etc/passwd" && grep -shq "^$create_group:" "/etc/group" && return
[ "$create_user" = "root" ] && [ "$create_group" = "root" ] && return 0 if [ "$create_user" = "root" ] && [ "$create_group" = "root" ]; then
return 0
fi
if [ "$RUNAS_USER" != "root" ] && [ "$RUNAS_USER" != "" ]; then if [ "$RUNAS_USER" != "root" ] && [ "$RUNAS_USER" != "" ]; then
create_user="$RUNAS_USER" create_user="$RUNAS_USER"
create_group="$RUNAS_USER" create_group="$RUNAS_USER"
@@ -636,17 +655,17 @@ __create_service_user() {
break break
fi fi
done done
if ! __check_for_group "$create_group"; then if [ -n "$create_group" ] && ! __check_for_group "$create_group"; then
echo "creating system group $create_group" echo "creating system group $create_group"
groupadd --force --system -g $create_gid $create_group 2>/dev/stderr | tee -p -a "/data/logs/init.txt" >/dev/null groupadd --force --system -g $create_gid $create_group 2>/dev/stderr | tee -a "/data/logs/init.txt" >/dev/null
fi
if ! __check_for_user "$create_user"; then
echo "creating system user $create_user"
useradd --system -u $create_uid -g $create_group -c "Account for $create_user" -d "$create_home_dir" -s /bin/false $create_user 2>/dev/stderr | tee -p -a "/data/logs/init.txt" >/dev/null
fi
grep -shq "$create_group" "/etc/group" || exitStatus=$((exitStatus + 1)) grep -shq "$create_group" "/etc/group" || exitStatus=$((exitStatus + 1))
grep -shq "$create_user" "/etc/passwd" || exitStatus=$((exitCode + 1)) fi
if [ $exitStatus -eq 0 ]; then if [ -n "$create_user" ] && ! __check_for_user "$create_user"; then
echo "creating system user $create_user"
useradd --system --uid $create_uid --gid $create_group --comment "Account for $create_user" --home-dir "$create_home_dir" --shell /bin/false $create_user 2>/dev/stderr | tee -a "/data/logs/init.txt" >/dev/null
grep -shq "$create_user" "/etc/passwd" || exitStatus=$((exitStatus + 1))
fi
if [ $exitStatus -eq 0 ] && [ -n "$create_group" ] && [ -n "$create_user" ]; then
export WORK_DIR="${create_home_dir:-}" export WORK_DIR="${create_home_dir:-}"
if [ -n "$WORK_DIR" ]; then if [ -n "$WORK_DIR" ]; then
[ -d "$WORK_DIR" ] || mkdir -p "$WORK_DIR" [ -d "$WORK_DIR" ] || mkdir -p "$WORK_DIR"
@@ -657,20 +676,22 @@ __create_service_user() {
elif [ -f "/etc/sudoers" ] && ! grep -qs "$create_user" "/etc/sudoers"; then elif [ -f "/etc/sudoers" ] && ! grep -qs "$create_user" "/etc/sudoers"; then
echo "$create_user ALL=(ALL) NOPASSWD: ALL" >"/etc/sudoers" echo "$create_user ALL=(ALL) NOPASSWD: ALL" >"/etc/sudoers"
fi fi
export SERVICE_UID="$create_uid" exitStatus=0
export SERVICE_GID="$create_gid" SERVICE_UID="$create_uid"
export SERVICE_USER="$create_user" SERVICE_GID="$create_gid"
export SERVICE_GROUP="$create_group" SERVICE_USER="$create_user"
SERVICE_GROUP="$create_group"
else else
export USER_UID=0 SERVICE_UID=0
export USER_GID=0 SERVICE_GID=0
export SERVICE_USER=root SERVICE_USER=root
export SERVICE_GROUP=root SERVICE_GROUP=root
exitStatus=2 exitStatus=2
fi fi
export SERVICE_UID SERVICE_GID SERVICE_USER SERVICE_GROUP
return $exitStatus return $exitStatus
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__create_env_file() { __create_env_file() {
local dir="" local dir=""
local envStatus=0 local envStatus=0
@@ -690,7 +711,7 @@ EOF
rm -f "$sample_file" rm -f "$sample_file"
return $envStatus return $envStatus
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__exec_command() { __exec_command() {
local bin="" local bin=""
local arg=("$@") local arg=("$@")
@@ -713,7 +734,7 @@ __exec_command() {
fi fi
return $exitCode return $exitCode
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Setup the server init scripts # Setup the server init scripts
__start_init_scripts() { __start_init_scripts() {
[ "$1" = " " ] && shift 1 [ "$1" = " " ] && shift 1
@@ -724,6 +745,7 @@ __start_init_scripts() {
local retstatus="0" local retstatus="0"
local initStatus="0" local initStatus="0"
local critical_failures="0" local critical_failures="0"
local pidFile="/run/__start_init_scripts.pid"
local init_dir="${1:-/usr/local/etc/docker/init.d}" local init_dir="${1:-/usr/local/etc/docker/init.d}"
local init_count="$(ls -A "$init_dir"/* 2>/dev/null | grep -v '\.sample' | wc -l)" local init_count="$(ls -A "$init_dir"/* 2>/dev/null | grep -v '\.sample' | wc -l)"
local exit_on_failure="${EXIT_ON_SERVICE_FAILURE:-true}" local exit_on_failure="${EXIT_ON_SERVICE_FAILURE:-true}"
@@ -734,7 +756,7 @@ __start_init_scripts() {
rm -f /run/*.pid /run/init.d/*.pid 2>/dev/null || true rm -f /run/*.pid /run/init.d/*.pid 2>/dev/null || true
fi fi
touch /run/__start_init_scripts.pid touch "$pidFile"
if [ "$init_count" -eq 0 ] || [ ! -d "$init_dir" ]; then if [ "$init_count" -eq 0 ] || [ ! -d "$init_dir" ]; then
mkdir -p "/data/logs/init" mkdir -p "/data/logs/init"
@@ -752,6 +774,7 @@ __start_init_scripts() {
for init in "$init_dir"/*.sh; do for init in "$init_dir"/*.sh; do
if [ -x "$init" ]; then if [ -x "$init" ]; then
touch "$pidFile"
name="$(basename "$init")" name="$(basename "$init")"
service="$(printf '%s' "$name" | sed 's/^[^-]*-//;s|.sh$||g')" service="$(printf '%s' "$name" | sed 's/^[^-]*-//;s|.sh$||g')"
__service_banner "🔧" "Executing service script:" "$(basename "$init")" __service_banner "🔧" "Executing service script:" "$(basename "$init")"
@@ -777,19 +800,42 @@ __start_init_scripts() {
__service_banner "✅" "Service $service started successfully -" "no PID tracking" __service_banner "✅" "Service $service started successfully -" "no PID tracking"
fi fi
else else
# Service uses PID tracking - get actual PID # Service uses PID tracking - verify actual running processes
retPID=$(__get_pid "$service") 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 if [ -n "$retPID" ] && [ "$retPID" != "0" ]; then
# Found actual running process
initStatus="0" 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 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" initStatus="0"
__service_banner "✅" "Service $service started successfully -" "PID file" __service_banner "✅" "Service $service started successfully -" "PID: $file_pid (from file)"
else elif [ -n "$file_pid" ]; then
initStatus="1" initStatus="1"
critical_failures=$((critical_failures + 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 fi
fi fi
@@ -819,7 +865,7 @@ __start_init_scripts() {
printf '%s\n' "$SERVICE_NAME started on $(date)" >"/data/logs/start.log" printf '%s\n' "$SERVICE_NAME started on $(date)" >"/data/logs/start.log"
return $retstatus return $retstatus
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__setup_mta() { __setup_mta() {
[ -d "/etc/ssmtp" ] || [ -d "/etc/postfix" ] || return [ -d "/etc/ssmtp" ] || [ -d "/etc/postfix" ] || return
if [ ! -d "/config/ssmtp" ] || [ ! -d "/config/postfix" ]; then if [ ! -d "/config/ssmtp" ] || [ ! -d "/config/postfix" ]; then
@@ -926,7 +972,7 @@ EOF
[ -f "/root/dead.letter" ] && __rm "/root/dead.letter" [ -f "/root/dead.letter" ] && __rm "/root/dead.letter"
return $exitCode return $exitCode
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__initialize_web_health() { __initialize_web_health() {
local www_dir="${1:-${WWW_ROOT_DIR:-/usr/local/share/httpd/default}}" local www_dir="${1:-${WWW_ROOT_DIR:-/usr/local/share/httpd/default}}"
if [ -d "$www_dir" ]; then if [ -d "$www_dir" ]; then
@@ -935,7 +981,7 @@ __initialize_web_health() {
__find_replace "REPLACE_LAST_UPDATED_ON_MESSAGE" "${LAST_UPDATED_ON_MESSAGE:-$(date +'Last updated on: %Y-%m-%d at %H:%M:%S')}" "/usr/local/share/httpd" __find_replace "REPLACE_LAST_UPDATED_ON_MESSAGE" "${LAST_UPDATED_ON_MESSAGE:-$(date +'Last updated on: %Y-%m-%d at %H:%M:%S')}" "/usr/local/share/httpd"
fi fi
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# file_dir # file_dir
__initialize_replace_variables() { __initialize_replace_variables() {
local set_dir="" get_dir="$*" local set_dir="" get_dir="$*"
@@ -978,7 +1024,7 @@ __initialize_replace_variables() {
mkdir -p "${TMP_DIR:-/tmp/$SERVICE_NAME}" "${RUN_DIR:-/run/$SERVICE_NAME}" "${LOG_DIR:-/data/logs/$SERVICE_NAME}" mkdir -p "${TMP_DIR:-/tmp/$SERVICE_NAME}" "${RUN_DIR:-/run/$SERVICE_NAME}" "${LOG_DIR:-/data/logs/$SERVICE_NAME}"
chmod -f 777 "${TMP_DIR:-/tmp/$SERVICE_NAME}" "${RUN_DIR:-/run/$SERVICE_NAME}" "${LOG_DIR:-/data/logs/$SERVICE_NAME}" chmod -f 777 "${TMP_DIR:-/tmp/$SERVICE_NAME}" "${RUN_DIR:-/run/$SERVICE_NAME}" "${LOG_DIR:-/data/logs/$SERVICE_NAME}"
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__initialize_database() { __initialize_database() {
[ "$IS_DATABASE_SERVICE" = "yes" ] || [ "$USES_DATABASE_SERVICE" = "yes" ] || return 0 [ "$IS_DATABASE_SERVICE" = "yes" ] || [ "$USES_DATABASE_SERVICE" = "yes" ] || return 0
local dir="${1:-$ETC_DIR}" local dir="${1:-$ETC_DIR}"
@@ -1009,7 +1055,7 @@ __initialize_database() {
__find_replace "REPLACE_DATABASE_DIR" "$DATABASE_DIR" "/etc" __find_replace "REPLACE_DATABASE_DIR" "$DATABASE_DIR" "/etc"
fi fi
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__initialize_db_users() { __initialize_db_users() {
[ "$IS_DATABASE_SERVICE" = "yes" ] || [ "$USES_DATABASE_SERVICE" = "yes" ] || return 0 [ "$IS_DATABASE_SERVICE" = "yes" ] || [ "$USES_DATABASE_SERVICE" = "yes" ] || return 0
db_normal_user="${DATABASE_USER_NORMAL:-$user_name}" db_normal_user="${DATABASE_USER_NORMAL:-$user_name}"
@@ -1022,7 +1068,7 @@ __initialize_db_users() {
export DATABASE_PASS_ROOT="$db_admin_pass" export DATABASE_PASS_ROOT="$db_admin_pass"
export db_normal_user db_normal_pass db_admin_user db_admin_pass export db_normal_user db_normal_pass db_admin_user db_admin_pass
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__initialize_system_etc() { __initialize_system_etc() {
local conf_dir="$1" local conf_dir="$1"
local dir="" local dir=""
@@ -1049,7 +1095,7 @@ __initialize_system_etc() {
done done
fi fi
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__initialize_custom_bin_dir() { __initialize_custom_bin_dir() {
local SET_USR_BIN="" local SET_USR_BIN=""
[ -d "/data/bin" ] && SET_USR_BIN+="$(__find /data/bin f) " [ -d "/data/bin" ] && SET_USR_BIN+="$(__find /data/bin f) "
@@ -1067,7 +1113,7 @@ __initialize_custom_bin_dir() {
unset create_bin_template create_bin_name SET_USR_BIN unset create_bin_template create_bin_name SET_USR_BIN
fi fi
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__initialize_default_templates() { __initialize_default_templates() {
if [ -n "$DEFAULT_TEMPLATE_DIR" ]; then if [ -n "$DEFAULT_TEMPLATE_DIR" ]; then
if [ "$CONFIG_DIR_INITIALIZED" = "false" ] && [ -d "/config" ]; then if [ "$CONFIG_DIR_INITIALIZED" = "false" ] && [ -d "/config" ]; then
@@ -1087,7 +1133,7 @@ __initialize_default_templates() {
fi fi
fi fi
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__initialize_config_dir() { __initialize_config_dir() {
if [ -n "$DEFAULT_CONF_DIR" ]; then if [ -n "$DEFAULT_CONF_DIR" ]; then
if [ "$CONFIG_DIR_INITIALIZED" = "false" ] && [ -d "/config" ]; then if [ "$CONFIG_DIR_INITIALIZED" = "false" ] && [ -d "/config" ]; then
@@ -1107,7 +1153,7 @@ __initialize_config_dir() {
fi fi
fi fi
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__initialize_data_dir() { __initialize_data_dir() {
if [ -d "/data" ]; then if [ -d "/data" ]; then
if [ "$DATA_DIR_INITIALIZED" = "false" ] && [ -n "$DEFAULT_DATA_DIR" ]; then if [ "$DATA_DIR_INITIALIZED" = "false" ] && [ -n "$DEFAULT_DATA_DIR" ]; then
@@ -1127,7 +1173,7 @@ __initialize_data_dir() {
fi fi
fi fi
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__initialize_www_root() { __initialize_www_root() {
local WWW_INIT="" local WWW_INIT=""
local WWW_TEMPLATE="" local WWW_TEMPLATE=""
@@ -1140,7 +1186,7 @@ __initialize_www_root() {
fi fi
__initialize_web_health "$WWW_ROOT_DIR" __initialize_web_health "$WWW_ROOT_DIR"
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__is_htdocs_mounted() { __is_htdocs_mounted() {
WWW_ROOT_DIR="${WWW_ROOT_DIR:-/data/htdocs}" WWW_ROOT_DIR="${WWW_ROOT_DIR:-/data/htdocs}"
[ -n "$ENV_WWW_ROOT_DIR" ] && WWW_ROOT_DIR="$ENV_WWW_ROOT_DIR" [ -n "$ENV_WWW_ROOT_DIR" ] && WWW_ROOT_DIR="$ENV_WWW_ROOT_DIR"
@@ -1167,7 +1213,7 @@ __is_htdocs_mounted() {
[ -d "$WWW_ROOT_DIR" ] || mkdir -p "$WWW_ROOT_DIR" [ -d "$WWW_ROOT_DIR" ] || mkdir -p "$WWW_ROOT_DIR"
export WWW_ROOT_DIR="${WWW_ROOT_DIR:-/usr/local/share/httpd/default}" export WWW_ROOT_DIR="${WWW_ROOT_DIR:-/usr/local/share/httpd/default}"
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__initialize_ssl_certs() { __initialize_ssl_certs() {
[ "$SSL_ENABLED" = "yes" ] && __certbot [ "$SSL_ENABLED" = "yes" ] && __certbot
if [ -d "/config/letsencrypt" ]; then if [ -d "/config/letsencrypt" ]; then
@@ -1194,7 +1240,7 @@ __initialize_ssl_certs() {
fi fi
type update-ca-certificates &>/dev/null && update-ca-certificates &>/dev/null type update-ca-certificates &>/dev/null && update-ca-certificates &>/dev/null
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__start_php_dev_server() { __start_php_dev_server() {
if [ "$2" = "yes" ]; then if [ "$2" = "yes" ]; then
if [ -d "/usr/local/share/httpd" ]; then if [ -d "/usr/local/share/httpd" ]; then
@@ -1207,7 +1253,7 @@ __start_php_dev_server() {
fi fi
fi fi
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__check_service() { __check_service() {
if [ "$1" = "check" ]; then if [ "$1" = "check" ]; then
shift $# shift $#
@@ -1215,7 +1261,7 @@ __check_service() {
exit $? exit $?
fi fi
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
__switch_to_user() { __switch_to_user() {
if [ "$RUNAS_USER" = "root" ]; then if [ "$RUNAS_USER" = "root" ]; then
su_exec="" su_exec=""
@@ -1238,7 +1284,7 @@ __switch_to_user() {
fi fi
export su_exec export su_exec
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# usage backup "days" "hours" # usage backup "days" "hours"
__backup() { __backup() {
local dirs="" backup_dir backup_name backup_exclude runTime cronTime maxDays local dirs="" backup_dir backup_name backup_exclude runTime cronTime maxDays
@@ -1276,7 +1322,7 @@ __backup() {
[ -n "$cronTime" ] && runTime=$((cronTime * 3600)) || return $exitStatus [ -n "$cronTime" ] && runTime=$((cronTime * 3600)) || return $exitStatus
sleep $runTime && __backup "$maxDays" "$cronTime" sleep $runTime && __backup "$maxDays" "$cronTime"
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# set variables from function calls # set variables from function calls
export INIT_DATE="${INIT_DATE:-$(date)}" export INIT_DATE="${INIT_DATE:-$(date)}"
export START_SERVICES="${START_SERVICES:-yes}" export START_SERVICES="${START_SERVICES:-yes}"
@@ -1284,13 +1330,13 @@ export ENTRYPOINT_MESSAGE="${ENTRYPOINT_MESSAGE:-yes}"
export ENTRYPOINT_FIRST_RUN="${ENTRYPOINT_FIRST_RUN:-yes}" export ENTRYPOINT_FIRST_RUN="${ENTRYPOINT_FIRST_RUN:-yes}"
export DATA_DIR_INITIALIZED="${DATA_DIR_INITIALIZED:-false}" export DATA_DIR_INITIALIZED="${DATA_DIR_INITIALIZED:-false}"
export CONFIG_DIR_INITIALIZED="${CONFIG_DIR_INITIALIZED:-false}" export CONFIG_DIR_INITIALIZED="${CONFIG_DIR_INITIALIZED:-false}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# System # System
export LANG="${LANG:-C.UTF-8}" export LANG="${LANG:-C.UTF-8}"
export LC_ALL="${LANG:-C.UTF-8}" export LC_ALL="${LANG:-C.UTF-8}"
export TZ="${TZ:-${TIMEZONE:-America/New_York}}" export TZ="${TZ:-${TIMEZONE:-America/New_York}}"
export HOSTNAME="${FULL_DOMAIN_NAME:-${SERVER_HOSTNAME:-$HOSTNAME}}" export HOSTNAME="${FULL_DOMAIN_NAME:-${SERVER_HOSTNAME:-$HOSTNAME}}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Default directories # Default directories
export SSL_DIR="${SSL_DIR:-/config/ssl}" export SSL_DIR="${SSL_DIR:-/config/ssl}"
export SSL_CA="${SSL_CERT:-/config/ssl/ca.crt}" export SSL_CA="${SSL_CERT:-/config/ssl/ca.crt}"
@@ -1300,15 +1346,15 @@ 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_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_CONF_DIR="${DEFAULT_CONF_DIR:-/usr/local/share/template-files/config}"
export DEFAULT_TEMPLATE_DIR="${DEFAULT_TEMPLATE_DIR:-/usr/local/share/template-files/defaults}" 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:-}"
export BACKUP_RUN_CRON="${BACKUP_RUN_CRON:-}" export BACKUP_RUN_CRON="${BACKUP_RUN_CRON:-}"
export BACKUP_DIR="${BACKUP_DIR:-/data/backups}" export BACKUP_DIR="${BACKUP_DIR:-/data/backups}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
CONTAINER_IP4_ADDRESS="${CONTAINER_IP4_ADDRESS:-$(__get_ip4)}" CONTAINER_IP4_ADDRESS="${CONTAINER_IP4_ADDRESS:-$(__get_ip4)}"
CONTAINER_IP6_ADDRESS="${CONTAINER_IP6_ADDRESS:-$(__get_ip6)}" CONTAINER_IP6_ADDRESS="${CONTAINER_IP6_ADDRESS:-$(__get_ip6)}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# Additional # Additional
export WORK_DIR="${ENV_WORK_DIR:-$WORK_DIR}" export WORK_DIR="${ENV_WORK_DIR:-$WORK_DIR}"
export SET_RANDOM_PASS="${SET_RANDOM_PASS:-$(__random_password 16)}" export SET_RANDOM_PASS="${SET_RANDOM_PASS:-$(__random_password 16)}"
@@ -1326,15 +1372,15 @@ export ENTRYPOINT_PID_FILE="${ENTRYPOINT_PID_FILE:-/run/init.d/entrypoint.pid}"
export ENTRYPOINT_INIT_FILE="${ENTRYPOINT_INIT_FILE:-/config/.entrypoint.done}" export ENTRYPOINT_INIT_FILE="${ENTRYPOINT_INIT_FILE:-/config/.entrypoint.done}"
export ENTRYPOINT_DATA_INIT_FILE="${ENTRYPOINT_DATA_INIT_FILE:-/data/.docker_has_run}" export ENTRYPOINT_DATA_INIT_FILE="${ENTRYPOINT_DATA_INIT_FILE:-/data/.docker_has_run}"
export ENTRYPOINT_CONFIG_INIT_FILE="${ENTRYPOINT_CONFIG_INIT_FILE:-/config/.docker_has_run}" export ENTRYPOINT_CONFIG_INIT_FILE="${ENTRYPOINT_CONFIG_INIT_FILE:-/config/.docker_has_run}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# is already Initialized # is already Initialized
[ -z "$DATA_DIR_INITIALIZED" ] && { [ -f "$ENTRYPOINT_DATA_INIT_FILE" ] && DATA_DIR_INITIALIZED="true" || DATA_DIR_INITIALIZED="false"; } [ -z "$DATA_DIR_INITIALIZED" ] && { [ -f "$ENTRYPOINT_DATA_INIT_FILE" ] && DATA_DIR_INITIALIZED="true" || DATA_DIR_INITIALIZED="false"; }
[ -z "$CONFIG_DIR_INITIALIZED" ] && { [ -f "$ENTRYPOINT_CONFIG_INIT_FILE" ] && CONFIG_DIR_INITIALIZED="true" || CONFIG_DIR_INITIALIZED="false"; } [ -z "$CONFIG_DIR_INITIALIZED" ] && { [ -f "$ENTRYPOINT_CONFIG_INIT_FILE" ] && CONFIG_DIR_INITIALIZED="true" || CONFIG_DIR_INITIALIZED="false"; }
[ -z "$ENTRYPOINT_FIRST_RUN" ] && { { [ -f "$ENTRYPOINT_PID_FILE" ] || [ -f "$ENTRYPOINT_INIT_FILE" ]; } && ENTRYPOINT_FIRST_RUN="no" || ENTRYPOINT_FIRST_RUN="true"; } [ -z "$ENTRYPOINT_FIRST_RUN" ] && { { [ -f "$ENTRYPOINT_PID_FILE" ] || [ -f "$ENTRYPOINT_INIT_FILE" ]; } && ENTRYPOINT_FIRST_RUN="no" || ENTRYPOINT_FIRST_RUN="true"; }
export ENTRYPOINT_DATA_INIT_FILE DATA_DIR_INITIALIZED ENTRYPOINT_CONFIG_INIT_FILE CONFIG_DIR_INITIALIZED export ENTRYPOINT_DATA_INIT_FILE DATA_DIR_INITIALIZED ENTRYPOINT_CONFIG_INIT_FILE CONFIG_DIR_INITIALIZED
export ENTRYPOINT_PID_FILE ENTRYPOINT_INIT_FILE ENTRYPOINT_FIRST_RUN export ENTRYPOINT_PID_FILE ENTRYPOINT_INIT_FILE ENTRYPOINT_FIRST_RUN
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# export the functions # export the functions
export -f __get_pid __start_init_scripts __is_running __certbot __update_ssl_certs __create_ssl_cert export -f __get_pid __start_init_scripts __is_running __certbot __update_ssl_certs __create_ssl_cert
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - -
# end of functions # end of functions