Files
email_reports/docker-entrypoint.sh
Frank John Begornia 2eeec4377f
All checks were successful
Deploy Production Email Reports (Unified) / deploy (push) Successful in 57s
Send test emails to webmaster only during startup
2026-01-02 02:07:52 +08:00

91 lines
2.3 KiB
Bash

#!/bin/sh
set -e
echo "Email Reports Container Starting..."
echo "Current time: $(date)"
echo "Timezone: $(date +%Z)"
# Verify crontab is configured
echo ""
echo "Cron schedule:"
crontab -l || echo "Warning: No crontab found"
# Create log file if it doesn't exist
touch /var/log/cron.log
chmod 666 /var/log/cron.log
# Create email log if it doesn't exist
touch /app/email.log
chmod 666 /app/email.log
# Test PHP
echo ""
echo "Testing PHP..."
php -v || { echo "PHP test failed"; exit 1; }
# Test database connectivity (optional - won't fail if not reachable)
echo ""
echo "Environment variables loaded:"
echo " DB_HOST_CREW: ${DB_HOST_CREW:-not set}"
echo " DB_NAME_CREW: ${DB_NAME_CREW:-not set}"
echo " DB_USER_CREW: ${DB_USER_CREW:-not set}"
echo " DB_HOST_MERCHBAY: ${DB_HOST_MERCHBAY:-not set}"
echo " DB_NAME_MERCHBAY: ${DB_NAME_MERCHBAY:-not set}"
echo " DB_USER_MERCHBAY: ${DB_USER_MERCHBAY:-not set}"
echo " SMTP_HOST: ${SMTP_HOST:-not set}"
echo ""
# Test DNS resolution for database hosts
echo "Testing database host DNS resolution..."
if [ -n "${DB_HOST_CREW}" ]; then
echo -n " Crew DB (${DB_HOST_CREW}): "
getent hosts "${DB_HOST_CREW}" > /dev/null 2>&1 && echo "✓ Resolved" || echo "✗ Cannot resolve"
fi
if [ -n "${DB_HOST_MERCHBAY}" ]; then
echo -n " MerchBay DB (${DB_HOST_MERCHBAY}): "
getent hosts "${DB_HOST_MERCHBAY}" > /dev/null 2>&1 && echo "✓ Resolved" || echo "✗ Cannot resolve"
fi
echo ""
# Start crond in background
echo ""
echo "Starting cron daemon..."
echo "Logs will be written to:"
echo " - Cron output: /var/log/cron.log"
echo " - Email logs: /app/email.log"
echo ""
# Start crond in background
crond -l 2
# Verify crond started
sleep 2
if ! ps aux | grep -v grep | grep -q crond; then
echo "ERROR: crond failed to start"
exit 1
fi
echo "✓ Cron daemon is running"
echo ""
# Send test emails for both brands
echo "Sending test emails to verify configuration..."
echo ""
echo "[Testing Crew Sportswear]"
TEST_EMAIL=true BRAND=crew php /app/send_report.php
echo ""
echo "[Testing MerchBay]"
TEST_EMAIL=true BRAND=merchbay php /app/send_report.php
echo ""
echo "✓ Test emails sent to webmaster@crewsportswear.com"
echo ""
echo "Container is ready. Tailing logs..."
echo "Press Ctrl+C to stop (but don't - this keeps the container alive!)"
echo ""
# Keep container alive by tailing logs
tail -f /var/log/cron.log /app/email.log