config-email/sync/install-cron.sh

40 lines
1.2 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# Install Email Rules Sync as a cron job
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SYNC_SCRIPT="$SCRIPT_DIR/sync.js"
echo "📦 Installing Email Rules Sync Cron Job..."
echo ""
# Make sync script executable
chmod +x "$SYNC_SCRIPT"
# Create cron job to run every 30 minutes (as fallback - main sync is event-driven)
CRON_JOB="*/30 * * * * cd $SCRIPT_DIR && sudo /usr/bin/node sync.js >> /tmp/email-rules-sync.log 2>&1"
# Check if cron job already exists
if crontab -l 2>/dev/null | grep -q "email-rules-sync"; then
echo "⚠️ Cron job already exists. Updating..."
(crontab -l 2>/dev/null | grep -v "email-rules-sync"; echo "$CRON_JOB") | crontab -
else
echo " Adding new cron job..."
(crontab -l 2>/dev/null; echo "$CRON_JOB") | crontab -
fi
echo ""
echo "✅ Cron job installed successfully!"
echo ""
echo "The sync script will run every 30 minutes as a fallback."
echo "Main synchronization is event-driven (triggered by API changes)."
echo "Logs are written to: /tmp/email-rules-sync.log"
echo ""
echo "To view current cron jobs:"
echo " crontab -l"
echo ""
echo "To view logs:"
echo " tail -f /tmp/email-rules-sync.log"
echo ""
echo "To run sync manually:"
echo " cd $SCRIPT_DIR && npm start"