This commit is contained in:
Lizandro Guarnizo
2026-01-28 02:23:36 -05:00
parent 37d6bf1e20
commit 6ebf5c9a22
30 changed files with 2264 additions and 118 deletions
+51 -11
View File
@@ -13,16 +13,25 @@ until redis-cli -h ${REDIS_HOST:-redis} ping 2>/dev/null; do
done
echo "✅ Redis conectado"
# Esperar a que MySQL esté disponible (solo si no es localhost ni IP interna)
if [ "${DB_HOST}" != "localhost" ] && [ "${DB_HOST}" != "127.0.0.1" ] && [ "${DB_HOST}" != "db" ]; then
echo "️ Usando base de datos externa (${DB_HOST}), omitiendo verificación de conectividad..."
else
echo "⏳ Esperando MySQL..."
until mysql -h ${DB_HOST:-db} -u ${DB_USER:-whatsapp_user} -p${DB_PASS} -e "SELECT 1" >/dev/null 2>&1; do
echo " MySQL no disponible, esperando..."
# Esperar a que MySQL esté disponible
if [ "${DB_HOST}" = "mysql" ] || [ "${DB_HOST}" = "db" ]; then
echo "⏳ Esperando MySQL local..."
MAX_RETRIES=30
RETRY=0
until mariadb -h "${DB_HOST:-mysql}" -u "${DB_USER:-whatsapp_user}" -p"${DB_PASS}" --skip-ssl -e "SELECT 1" >/dev/null 2>&1; do
RETRY=$((RETRY + 1))
if [ $RETRY -ge $MAX_RETRIES ]; then
echo "⚠️ MySQL no disponible después de $MAX_RETRIES intentos, continuando..."
break
fi
echo " MySQL no disponible, intento $RETRY/$MAX_RETRIES..."
sleep 2
done
echo "✅ MySQL conectado"
if [ $RETRY -lt $MAX_RETRIES ]; then
echo "✅ MySQL conectado"
fi
elif [ "${DB_HOST}" != "localhost" ] && [ "${DB_HOST}" != "127.0.0.1" ]; then
echo "️ Usando base de datos externa (${DB_HOST}), omitiendo verificación de conectividad..."
fi
# Crear directorios si no existen
@@ -30,12 +39,43 @@ mkdir -p /var/www/html/logs
mkdir -p /var/www/html/uploads
mkdir -p /var/cache/nginx
mkdir -p /run/php
mkdir -p /var/lib/nginx/tmp/client_body
mkdir -p /var/lib/nginx/tmp/proxy
mkdir -p /var/lib/nginx/tmp/fastcgi
mkdir -p /var/lib/nginx/tmp/uwsgi
mkdir -p /var/lib/nginx/tmp/scgi
# Establecer permisos
# Establecer permisos ANTES de iniciar servicios
chown -R www:www /var/www/html/logs
chown -R www:www /var/www/html/uploads
chmod -R 755 /var/www/html/logs
chmod -R 755 /var/www/html/uploads
chmod -R 775 /var/www/html/logs
chmod -R 775 /var/www/html/uploads
# IMPORTANTE: nginx necesita acceso a sus directorios temporales
# Usar grupo nginx para compartir acceso entre nginx y www
chown -R nginx:nginx /var/lib/nginx
chmod -R 775 /var/lib/nginx/tmp
# Generar certificados SSL si no existen
SSL_DIR="/etc/nginx/ssl"
if [ ! -f "$SSL_DIR/server.crt" ] || [ ! -f "$SSL_DIR/server.key" ]; then
echo "🔐 Generando certificados SSL autofirmados..."
mkdir -p "$SSL_DIR"
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout "$SSL_DIR/server.key" \
-out "$SSL_DIR/server.crt" \
-subj "/C=CO/ST=Cundinamarca/L=Bogota/O=U-Site/OU=WhatsApp Bot/CN=bot.u-s.app" \
-addext "subjectAltName=DNS:bot.u-s.app,DNS:localhost,DNS:*.u-s.app,IP:127.0.0.1" 2>/dev/null || \
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout "$SSL_DIR/server.key" \
-out "$SSL_DIR/server.crt" \
-subj "/C=CO/ST=Cundinamarca/L=Bogota/O=U-Site/OU=WhatsApp Bot/CN=bot.u-s.app"
chmod 600 "$SSL_DIR/server.key"
chmod 644 "$SSL_DIR/server.crt"
echo "✅ Certificados SSL generados para bot.u-s.app"
else
echo "✅ Certificados SSL existentes encontrados"
fi
# Ejecutar migraciones de BD (si existen)
if [ -f /var/www/html/database/migrate.php ]; then