135 lines
3.7 KiB
Bash
Executable File
135 lines
3.7 KiB
Bash
Executable File
#!/bin/bash
|
|
# bash is required to pass ENV vars with dots as sh cannot
|
|
|
|
set -o errexit
|
|
set -o pipefail
|
|
set -o nounset
|
|
|
|
pid=0 # Initialize pid to 0
|
|
|
|
echoerr() { echo "$@" 1>&2; }
|
|
|
|
echoerr "Entrypoint PID $$"
|
|
|
|
## Pre execution handler
|
|
pre_execution_handler() {
|
|
export CA_ENABLED=true # Force CA_ENABLED to true
|
|
if [ -d /docker-custom-entrypoint.d/ ]; then
|
|
if [ -d /docker-custom-entrypoint.d/pre-default/ ]; then
|
|
find /docker-custom-entrypoint.d/pre-default/ -type f -name "*.sh" \
|
|
-exec chmod +x {} \;
|
|
sync
|
|
for f in /docker-custom-entrypoint.d/pre-default/*.sh; do
|
|
if [[ -f "$f" && -x $(realpath "$f") ]]; then
|
|
echo "Running $f"
|
|
"$f"
|
|
fi
|
|
done
|
|
fi
|
|
fi
|
|
|
|
# Removed 'set -x' as it was only for pre-execution scripts
|
|
# set -x # Enable debug output for pre-execution scripts
|
|
echo "CA_ENABLED is: $CA_ENABLED"
|
|
for f in /docker-entrypoint.d/*.sh; do
|
|
echo "Running $f"
|
|
"$f"
|
|
done
|
|
|
|
if [ -d /docker-custom-entrypoint.d/ ]; then
|
|
find /docker-custom-entrypoint.d/ -type f -name "*.sh" \
|
|
-exec chmod +x {} \;
|
|
sync
|
|
for f in /docker-custom-entrypoint.d/*.sh; do
|
|
if [[ -f "$f" && -x $(realpath "$f") ]]; then
|
|
echo "Running $f"
|
|
"$f"
|
|
fi
|
|
done
|
|
fi
|
|
}
|
|
|
|
## Post startup handler
|
|
post_startup_handler() {
|
|
if [ -d /docker-custom-entrypoint.d/ ]; then
|
|
if [ -d /docker-custom-entrypoint.d/post-startup/ ]; then
|
|
find /docker-custom-entrypoint.d/post-startup/ -type f -name "*.sh" \
|
|
-exec chmod +x {} \;
|
|
sync
|
|
for f in /docker-custom-entrypoint.d/post-startup/*.sh; do
|
|
if [[ -f "$f" && -x $(realpath "$f") ]]; then
|
|
echo "Running $f"
|
|
"$f"
|
|
fi
|
|
done
|
|
fi
|
|
fi
|
|
}
|
|
|
|
## Post execution handler
|
|
post_execution_handler() {
|
|
if [ -d /docker-custom-entrypoint.d/ ]; then
|
|
if [ -d /docker-custom-entrypoint.d/post-execution/ ]; then
|
|
find /docker-custom-entrypoint.d/post-execution/ -type f -name "*.sh" \
|
|
-exec chmod +x {} \;
|
|
sync
|
|
for f in /docker-custom-entrypoint.d/post-execution/*.sh; do
|
|
if [[ -f "$f" && -x $(realpath "$f") ]]; then
|
|
echo "Running $f"
|
|
"$f"
|
|
fi
|
|
done
|
|
fi
|
|
fi
|
|
}
|
|
|
|
## Sigterm Handler
|
|
sigterm_handler() {
|
|
echoerr "Catching SIGTERM"
|
|
if [ $pid -ne 0 ]; then
|
|
echoerr "sigterm_handler for PID '${pid}' triggered"
|
|
if [ -d /docker-custom-entrypoint.d/ ]; then
|
|
if [ -d /docker-custom-entrypoint.d/sigterm-handler/ ]; then
|
|
find /docker-custom-entrypoint.d/sigterm-handler/ -type f -name "*.sh" \
|
|
-exec chmod +x {} \;
|
|
sync
|
|
for f in /docker-custom-entrypoint.d/sigterm-handler/*.sh; do
|
|
if [[ -f "$f" && -x $(realpath "$f") ]]; then
|
|
echo "Running $f"
|
|
"$f"
|
|
fi
|
|
done
|
|
fi
|
|
fi
|
|
kill -15 "$pid"
|
|
wait "$pid"
|
|
post_execution_handler
|
|
fi
|
|
exit 143; # 128 + 15 -- SIGTERM
|
|
}
|
|
|
|
## Setup signal trap
|
|
trap sigterm_handler SIGTERM
|
|
|
|
## Initialization
|
|
pre_execution_handler
|
|
|
|
## Start Process
|
|
echoerr "DEBUG: Attempting to start Puppetserver in foreground."
|
|
# run process in foreground
|
|
# set -x # Enable debug output - moved to be after pid capture
|
|
/opt/puppetlabs/bin/puppetserver foreground "$@" &
|
|
pid=$! # Capture the PID of the background process
|
|
echoerr "DEBUG: Puppetserver started with PID $pid."
|
|
set -x # Enable debug output after pid capture
|
|
|
|
wait "$pid" # Wait for the puppetserver process to finish
|
|
return_code=$?
|
|
echoerr "DEBUG: Puppetserver exited with code $return_code."
|
|
exit $return_code
|
|
|
|
# The following lines will not be reached if exec is successful
|
|
# If exec fails, the script will continue here, which indicates an issue
|
|
# echoerr "ERROR: Puppetserver failed to start in foreground."
|
|
# exit 1
|