retention php debian image + mysqldump/mariadb-dump auto detect

This commit is contained in:
xiaomlove
2025-05-17 17:09:46 +07:00
parent be07e64bd6
commit 44dac027ac
5 changed files with 177 additions and 83 deletions

View File

@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
# 定义颜色
COLOR_RED='\033[0;31m'
@@ -24,6 +24,31 @@ echo_error() {
echo -e "${COLOR_RED}[ERROR]${COLOR_RESET} $*"
}
wait_for_service() {
name="$1"
host="$2"
port="$3"
maxWaitSeconds="$4"
waited=0
echo_info "🔍 Checking $name at $host:$port..."
until nc -z "$host" "$port" >/dev/null 2>&1; do
if [ "$waited" -ge "$maxWaitSeconds" ]; then
echo_error "$name not available after ${maxWaitSeconds}s. Exiting."
exit 1
fi
echo_info "⏳ Waiting for $name... (${waited}s elapsed)"
sleep 2
waited=$((waited + 2))
done
echo_success "$name is available."
}
wait_for_service "MySQL" mysql 3306 30
wait_for_service "Redis" redis 6379 30
# 正式开始
echo_info "Starting container for SERVICE_NAME=$SERVICE_NAME..."
@@ -36,30 +61,6 @@ VENDOR_DIR="${ROOT_PATH}/vendor"
chown -R www-data:www-data $ROOT_PATH
mysql_timeout=30
until nc -z mysql 3306; do
echo_info "Waiting for MySQL to be ready..."
sleep 2
((mysql_timeout--))
if [ $mysql_timeout -le 0 ]; then
echo "❌ MySQL connection timeout."
exit 1
fi
done
echo_success "MySQL is ready."
redis_timeout=30
until nc -z redis 6379; do
echo_info "Waiting for Redis to be ready..."
sleep 2
((redis_timeout--))
if [ $redis_timeout -le 0 ]; then
echo "❌ Redis connection timeout."
exit 1
fi
done
echo_success "Redis is ready."
if [ "$SERVICE_NAME" = "php" ]; then
if [ ! -f "$ENV_FILE" ]; then
echo_info ".env file: $ENV_FILE not exists, copy $SOURCE_DIR to $TARGET_DIR ..."