mirror of
https://github.com/casjaysdevdocker/nginx
synced 2026-06-24 14:01:04 -04:00
♻️ Migrate nginx to /config/ source-of-truth architecture ♻️
Migrate nginx Docker image to the new build-time config architecture.
- rootfs/root/docker/setup/03-files.sh: rewrite to canonical form with /tmp/bin, /tmp/var, /tmp/etc, /tmp/usr handlers; remove template-files copy block
- rootfs/usr/local/etc/docker/functions/entrypoint.sh: update to latest template with __init_service_conf, __find_php_ini, __find_php_bin helpers
- rootfs/usr/local/etc/docker/init.d/*.sh: fix $(basename) UUOC → ${var##*/}; move inline comments above code lines; remove commented-out dead code
- rootfs/usr/local/share/template-files/: delete entire directory; config files now deployed via /tmp/etc/ at build time
rootfs/root/docker/setup/03-files.sh
rootfs/usr/local/etc/docker/functions/entrypoint.sh
rootfs/usr/local/etc/docker/init.d/99-nginx.sh
rootfs/usr/local/share/template-files/config/env/default.sample
rootfs/usr/local/share/template-files/config/env/examples/00-directory.sh
rootfs/usr/local/share/template-files/config/env/examples/addresses.sh
rootfs/usr/local/share/template-files/config/env/examples/certbot.sh
rootfs/usr/local/share/template-files/config/env/examples/couchdb.sh
rootfs/usr/local/share/template-files/config/env/examples/dockerd.sh
rootfs/usr/local/share/template-files/config/env/examples/global.sh
rootfs/usr/local/share/template-files/config/env/examples/healthcheck.sh
rootfs/usr/local/share/template-files/config/env/examples/mariadb.sh
rootfs/usr/local/share/template-files/config/env/examples/mongodb.sh
rootfs/usr/local/share/template-files/config/env/examples/networking.sh
rootfs/usr/local/share/template-files/config/env/examples/other.sh
rootfs/usr/local/share/template-files/config/env/examples/php.sh
rootfs/usr/local/share/template-files/config/env/examples/postgres.sh
rootfs/usr/local/share/template-files/config/env/examples/redis.sh
rootfs/usr/local/share/template-files/config/env/examples/services.sh
rootfs/usr/local/share/template-files/config/env/examples/ssl.sh
rootfs/usr/local/share/template-files/config/env/examples/supabase.sh
rootfs/usr/local/share/template-files/config/env/examples/webservers.sh
rootfs/usr/local/share/template-files/config/env/examples/zz-entrypoint.sh
rootfs/usr/local/share/template-files/config/.gitkeep
rootfs/usr/local/share/template-files/data/.gitkeep
rootfs/usr/local/share/template-files/defaults/.gitkeep
This commit is contained in:
@@ -43,7 +43,7 @@ __script_exit() {
|
||||
fi
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
SCRIPT_NAME="$(basename -- "$SCRIPT_FILE" 2>/dev/null)"
|
||||
SCRIPT_NAME="${SCRIPT_FILE##*/}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# exit if __start_init_scripts function hasn't been Initialized
|
||||
if [ ! -f "/run/.start_init_scripts.pid" ]; then
|
||||
@@ -75,8 +75,10 @@ RESET_ENV="no"
|
||||
WWW_ROOT_DIR="/usr/local/share/httpd/default"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Default predefined variables
|
||||
DATA_DIR="/data/nginx" # set data directory
|
||||
CONF_DIR="/config/nginx" # set config directory
|
||||
# set data directory
|
||||
DATA_DIR="/data/nginx"
|
||||
# set config directory
|
||||
CONF_DIR="/config/nginx"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# set the containers etc directory
|
||||
ETC_DIR="/etc/nginx"
|
||||
@@ -84,9 +86,12 @@ ETC_DIR="/etc/nginx"
|
||||
# set the var dir
|
||||
VAR_DIR=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
TMP_DIR="/tmp/nginx" # set the temp dir
|
||||
RUN_DIR="/run/nginx" # set scripts pid dir
|
||||
LOG_DIR="/data/logs/nginx" # set log directory
|
||||
# set the temp dir
|
||||
TMP_DIR="/tmp/nginx"
|
||||
# set scripts pid dir
|
||||
RUN_DIR="/run/nginx"
|
||||
# set log directory
|
||||
LOG_DIR="/data/logs/nginx"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set the working dir
|
||||
WORK_DIR=""
|
||||
@@ -95,24 +100,32 @@ WORK_DIR=""
|
||||
SERVICE_PORT="80"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# User to use to launch service - IE: postgres
|
||||
RUNAS_USER="root" # normally root
|
||||
# normally root
|
||||
RUNAS_USER="root"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# User and group in which the service switches to - IE: nginx,apache,mysql,postgres
|
||||
SERVICE_USER="nginx" # execute command as another user
|
||||
SERVICE_GROUP="nginx" # Set the service group
|
||||
# execute command as another user
|
||||
SERVICE_USER="nginx"
|
||||
# Set the service group
|
||||
SERVICE_GROUP="nginx"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set password length
|
||||
RANDOM_PASS_USER=""
|
||||
RANDOM_PASS_ROOT=""
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set user and group ID
|
||||
SERVICE_UID="0" # set the user id
|
||||
SERVICE_GID="0" # set the group id
|
||||
# set the user id
|
||||
SERVICE_UID="0"
|
||||
# set the group id
|
||||
SERVICE_GID="0"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# execute command variables - keep single quotes variables will be expanded later
|
||||
EXEC_CMD_BIN='nginx' # command to execute
|
||||
EXEC_CMD_ARGS='-c $ETC_DIR/nginx.conf' # command arguments
|
||||
EXEC_PRE_SCRIPT='' # execute script before
|
||||
# command to execute
|
||||
EXEC_CMD_BIN='nginx'
|
||||
# command arguments
|
||||
EXEC_CMD_ARGS='-c $ETC_DIR/nginx.conf'
|
||||
# execute script before
|
||||
EXEC_PRE_SCRIPT=''
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Is this service a web server
|
||||
IS_WEB_SERVER="yes"
|
||||
@@ -140,20 +153,28 @@ IP4_ADDRESS="$(__get_ip4)"
|
||||
IP6_ADDRESS="$(__get_ip6)"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Where to save passwords to
|
||||
ROOT_FILE_PREFIX="/config/secure/auth/root" # directory to save username/password for root user
|
||||
USER_FILE_PREFIX="/config/secure/auth/user" # directory to save username/password for normal user
|
||||
# directory to save username/password for root user
|
||||
ROOT_FILE_PREFIX="/config/secure/auth/root"
|
||||
# directory to save username/password for normal user
|
||||
USER_FILE_PREFIX="/config/secure/auth/user"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# root/admin user info password/random]
|
||||
root_user_name="${NGINX_ROOT_USER_NAME:-}" # root user name
|
||||
root_user_pass="${NGINX_ROOT_PASS_WORD:-}" # root user password
|
||||
# root user name
|
||||
root_user_name="${NGINX_ROOT_USER_NAME:-}"
|
||||
# root user password
|
||||
root_user_pass="${NGINX_ROOT_PASS_WORD:-}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Normal user info [password/random]
|
||||
user_name="${NGINX_USER_NAME:-}" # normal user name
|
||||
user_pass="${NGINX_USER_PASS_WORD:-}" # normal user password
|
||||
# normal user name
|
||||
user_name="${NGINX_USER_NAME:-}"
|
||||
# normal user password
|
||||
user_pass="${NGINX_USER_PASS_WORD:-}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Load variables from config
|
||||
[ -f "/config/env/nginx.script.sh" ] && . "/config/env/nginx.script.sh" # Generated by my dockermgr script
|
||||
[ -f "/config/env/nginx.sh" ] && . "/config/env/nginx.sh" # Overwrite the variabes
|
||||
# Generated by my dockermgr script
|
||||
[ -f "/config/env/nginx.script.sh" ] && . "/config/env/nginx.script.sh"
|
||||
# Overwrite the variabes
|
||||
[ -f "/config/env/nginx.sh" ] && . "/config/env/nginx.sh"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Additional predefined variables
|
||||
|
||||
@@ -204,8 +225,10 @@ __execute_prerun() {
|
||||
__run_pre_execute_checks() {
|
||||
# Set variables
|
||||
local exitStatus=0
|
||||
local pre_execute_checks_MessageST="Running preexecute check for $SERVICE_NAME" # message to show at start
|
||||
local pre_execute_checks_MessageEnd="Finished preexecute check for $SERVICE_NAME" # message to show at completion
|
||||
# message to show at start
|
||||
local pre_execute_checks_MessageST="Running preexecute check for $SERVICE_NAME"
|
||||
# message to show at completion
|
||||
local pre_execute_checks_MessageEnd="Finished preexecute check for $SERVICE_NAME"
|
||||
__banner "$pre_execute_checks_MessageST"
|
||||
# Put command to execute in parentheses
|
||||
{
|
||||
@@ -228,8 +251,10 @@ __run_pre_execute_checks() {
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# use this function to update config files - IE: change port
|
||||
__update_conf_files() {
|
||||
local exitCode=0 # default exit code
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
|
||||
# default exit code
|
||||
local exitCode=0
|
||||
# set hostname
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# delete files
|
||||
#__rm ""
|
||||
@@ -254,8 +279,10 @@ __update_conf_files() {
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# function to run before executing
|
||||
__pre_execute() {
|
||||
local exitCode=0 # default exit code
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
|
||||
# default exit code
|
||||
local exitCode=0
|
||||
# set hostname
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}"
|
||||
# execute if directories is empty
|
||||
# __is_dir_empty "$CONF_DIR" && true
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
@@ -274,12 +301,18 @@ __pre_execute() {
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# function to run after executing
|
||||
__post_execute() {
|
||||
local pid="" # init pid var
|
||||
local retVal=0 # set default exit code
|
||||
local ctime=${POST_EXECUTE_WAIT_TIME:-1} # how long to wait before executing
|
||||
local waitTime=$((ctime * 60)) # convert minutes to seconds
|
||||
local postMessageST="Running post commands for $SERVICE_NAME" # message to show at start
|
||||
local postMessageEnd="Finished post commands for $SERVICE_NAME" # message to show at completion
|
||||
# init pid var
|
||||
local pid=""
|
||||
# set default exit code
|
||||
local retVal=0
|
||||
# how long to wait before executing
|
||||
local ctime=${POST_EXECUTE_WAIT_TIME:-1}
|
||||
# convert minutes to seconds
|
||||
local waitTime=$((ctime * 60))
|
||||
# message to show at start
|
||||
local postMessageST="Running post commands for $SERVICE_NAME"
|
||||
# message to show at completion
|
||||
local postMessageEnd="Finished post commands for $SERVICE_NAME"
|
||||
# wait
|
||||
sleep $waitTime
|
||||
# execute commands after waiting
|
||||
@@ -314,7 +347,8 @@ __pre_message() {
|
||||
# use this function to setup ssl support
|
||||
__update_ssl_conf() {
|
||||
local exitCode=0
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
|
||||
# set hostname
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}"
|
||||
# execute commands
|
||||
|
||||
# allow custom functions
|
||||
@@ -369,17 +403,28 @@ EOF
|
||||
# script to start server
|
||||
__run_start_script() {
|
||||
local runExitCode=0
|
||||
local workdir="$(eval echo "${WORK_DIR:-}")" # expand variables
|
||||
local cmd="$(eval echo "${EXEC_CMD_BIN:-}")" # expand variables
|
||||
local args="$(eval echo "${EXEC_CMD_ARGS:-}")" # expand variables
|
||||
local name="$(eval echo "${EXEC_CMD_NAME:-}")" # expand variables
|
||||
local pre="$(eval echo "${EXEC_PRE_SCRIPT:-}")" # expand variables
|
||||
local extra_env="$(eval echo "${CMD_ENV//,/ }")" # expand variables
|
||||
local lc_type="$(eval echo "${LANG:-${LC_ALL:-$LC_CTYPE}}")" # expand variables
|
||||
local home="$(eval echo "${workdir//\/root/\/tmp\/docker}")" # expand variables
|
||||
local path="$(eval echo "$PATH")" # expand variables
|
||||
local message="$(eval echo "")" # expand variables
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname
|
||||
# expand variables
|
||||
local workdir="$(eval echo "${WORK_DIR:-}")"
|
||||
# expand variables
|
||||
local cmd="$(eval echo "${EXEC_CMD_BIN:-}")"
|
||||
# expand variables
|
||||
local args="$(eval echo "${EXEC_CMD_ARGS:-}")"
|
||||
# expand variables
|
||||
local name="$(eval echo "${EXEC_CMD_NAME:-}")"
|
||||
# expand variables
|
||||
local pre="$(eval echo "${EXEC_PRE_SCRIPT:-}")"
|
||||
# expand variables
|
||||
local extra_env="$(eval echo "${CMD_ENV//,/ }")"
|
||||
# expand variables
|
||||
local lc_type="$(eval echo "${LANG:-${LC_ALL:-$LC_CTYPE}}")"
|
||||
# expand variables
|
||||
local home="$(eval echo "${workdir//\/root/\/tmp\/docker}")"
|
||||
# expand variables
|
||||
local path="$(eval echo "$PATH")"
|
||||
# expand variables
|
||||
local message="$(eval echo "")"
|
||||
# set hostname
|
||||
local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}"
|
||||
[ -f "$CONF_DIR/$SERVICE_NAME.exec_cmd.sh" ] && . "$CONF_DIR/$SERVICE_NAME.exec_cmd.sh"
|
||||
#
|
||||
if [ -z "$cmd" ]; then
|
||||
@@ -496,13 +541,19 @@ __run_secure_function() {
|
||||
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" && . "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh"
|
||||
__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh" && . "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
SERVICE_EXIT_CODE=0 # default exit code
|
||||
# default exit code
|
||||
SERVICE_EXIT_CODE=0
|
||||
# application specific
|
||||
EXEC_CMD_NAME="$(basename -- "$EXEC_CMD_BIN")" # set the binary name
|
||||
SERVICE_PID_FILE="/run/init.d/$EXEC_CMD_NAME.pid" # set the pid file location
|
||||
SERVICE_PID_NUMBER="$(__pgrep)" # check if running
|
||||
EXEC_CMD_BIN="$(type -P "$EXEC_CMD_BIN" || echo "$EXEC_CMD_BIN")" # set full path
|
||||
EXEC_PRE_SCRIPT="$(type -P "$EXEC_PRE_SCRIPT" || echo "$EXEC_PRE_SCRIPT")" # set full path
|
||||
# set the binary name
|
||||
EXEC_CMD_NAME="${EXEC_CMD_BIN##*/}"
|
||||
# set the pid file location
|
||||
SERVICE_PID_FILE="/run/init.d/$EXEC_CMD_NAME.pid"
|
||||
# check if running
|
||||
SERVICE_PID_NUMBER="$(__pgrep)"
|
||||
# set full path
|
||||
EXEC_CMD_BIN="$(type -P "$EXEC_CMD_BIN" || echo "$EXEC_CMD_BIN")"
|
||||
# set full path
|
||||
EXEC_PRE_SCRIPT="$(type -P "$EXEC_PRE_SCRIPT" || echo "$EXEC_PRE_SCRIPT")"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Only run check
|
||||
__check_service "$1" && SERVICE_IS_RUNNING=yes
|
||||
|
||||
Reference in New Issue
Block a user