#!/bin/bash set -e # --- Shutdown Handler --- # This function will be called when the container receives a shutdown signal cleanup() { echo "SIGTERM received, initiating backup..." /usr/local/bin/backup.sh # Execute the backup script echo "Backup script finished. Exiting." exit 0 } # Trap the SIGTERM signal (sent by 'podman-compose down') and call the cleanup function trap 'cleanup' SIGTERM # --- Startup Logic --- # Check if the target directory is a git repo. If not, clone it. if [ ! -d "/var/www/html/.git" ]; then echo "No git repository found. Cloning..." # Clone the specified branch of the repository git clone --branch ${GIT_BRANCH} ${GIT_REPO_URL} . else echo "Git repository found. Pulling latest changes..." git pull origin ${GIT_BRANCH} fi echo "Starting PHP built-in web server..." # Use 'exec' to replace the script process with the PHP server process. # This is crucial for the trap to work correctly. exec php -S 0.0.0.0:2025