Files
panel/setup-cron.sh

53 lines
1.6 KiB
Bash

#!/bin/bash
# Manual script to setup/restart cron jobs
# Use this if cron wasn't started properly by the docker entrypoint
echo "🔧 Setting up cron jobs..."
# Ensure cron service is running
if command -v service &> /dev/null; then
service cron start 2>/dev/null || true
fi
# Set up daily backup cron job (runs at 2 AM daily)
echo "⏰ Setting up daily backup cron job (2 AM)..."
echo "0 2 * * * cd /app && /usr/local/bin/node backup-db.mjs >> /app/data/backup.log 2>&1" > /etc/cron.d/backup-cron
chmod 0644 /etc/cron.d/backup-cron
# Set up daily due date reminders cron job (runs at 3 AM daily)
echo "⏰ Setting up daily due date reminders cron job (3 AM)..."
echo "0 3 * * * cd /app && /usr/local/bin/node send-due-date-reminders.mjs >> /app/data/reminders.log 2>&1" > /etc/cron.d/reminders-cron
chmod 0644 /etc/cron.d/reminders-cron
# Combine both cron jobs into crontab
cat /etc/cron.d/backup-cron /etc/cron.d/reminders-cron > /tmp/combined-cron.tmp
crontab /tmp/combined-cron.tmp
rm /tmp/combined-cron.tmp
# Verify cron jobs are installed
echo ""
echo "✅ Cron jobs installed:"
crontab -l
# Check if cron daemon is running
echo ""
if pgrep -x "cron" > /dev/null || pgrep -x "crond" > /dev/null; then
echo "✅ Cron daemon is running"
else
echo "⚠️ Cron daemon is NOT running. Starting it..."
if command -v cron &> /dev/null; then
cron
echo "✅ Cron daemon started"
elif command -v crond &> /dev/null; then
crond
echo "✅ Cron daemon started"
else
echo "❌ Could not start cron daemon"
exit 1
fi
fi
echo ""
echo "🎉 Cron setup complete!"