feat: Improve cron job setup for automatic database cleanup with better error handling

This commit is contained in:
Arunavo Ray
2025-05-24 17:37:36 +05:30
parent 90944a40c6
commit 773842fa72

View File

@@ -227,26 +227,28 @@ fi
if command -v crontab >/dev/null 2>&1; then if command -v crontab >/dev/null 2>&1; then
echo "Setting up automatic database cleanup cron jobs..." echo "Setting up automatic database cleanup cron jobs..."
# Install cron if not already installed # Install cron if not already installed
if ! command -v cron >/dev/null 2>&1; then if ! command -v crond >/dev/null 2>&1; then
echo "Installing cron..." echo "Installing cron..."
apt-get update && apt-get install -y cron apk add --no-cache dcron
fi fi
# Install the cron job # Try to install the cron job, but don't fail if it doesn't work
crontab /app/data/cron/cleanup-cron if crontab /app/data/cron/cleanup-cron 2>/dev/null; then
echo "✅ Cron job installed successfully"
# Start cron service # Start cron service (Alpine uses crond)
if command -v service >/dev/null 2>&1; then if command -v crond >/dev/null 2>&1; then
service cron start crond -b
echo "Cron service started" echo "Cron daemon started"
elif command -v cron >/dev/null 2>&1; then
cron
echo "Cron daemon started"
else else
echo "Warning: Could not start cron service. Automatic database cleanup will not run." echo "⚠️ Warning: Could not start cron service. Automatic database cleanup will not run."
fi fi
else else
echo "Warning: crontab command not found. Automatic database cleanup will not be set up." echo "⚠️ Warning: Could not install cron job (permission issue). Automatic database cleanup will not be set up."
echo "Consider setting up external scheduled tasks to run cleanup scripts."
fi
else
echo "⚠️ Warning: crontab command not found. Automatic database cleanup will not be set up."
echo "Consider setting up external scheduled tasks to run cleanup scripts." echo "Consider setting up external scheduled tasks to run cleanup scripts."
fi fi