Files
PyRIGS/scripts/cron-install.sh
Hang c1ac0065ee ci: update compose.yml for prod deployment
- Add Nginx as a reverse proxy
- Add cert-selfsign.sh for generating self-signed certificates
- Add certbot-issue.sh for Let's Encrypt certificate issuance and renewal
- Add cron-install.sh and cron-uninstall.sh for system cron management
- Add .env.example as an environment variable template
2026-08-23 23:10:30 +01:00

35 lines
1.5 KiB
Bash

#!/usr/bin/env bash
# Install system-level scheduled tasks (run as root on the deployment server)
# Usage: sudo ./scripts/cron-install.sh
#
# Writes two /etc/cron.d files:
# 1. pyrigs-certbot - certificate renewal check, daily at 03:00 / 15:00
# 2. pyrigs-django - cleanup and reminder jobs inside the pyrigs container
set -euo pipefail
REPO_DIR="$(cd "$(dirname "$0")/.." && pwd)"
CERTBOT_CRON="/etc/cron.d/pyrigs-certbot"
DJANGO_CRON="/etc/cron.d/pyrigs-django"
# 1. Certificate renewal: checked twice a day (officially recommended frequency);
# on successful renewal the deploy-hook in the official hook dir takes over
cat > "$CERTBOT_CRON" <<EOF
# Generated by scripts/cron-install.sh; remove with scripts/cron-uninstall.sh
0 3,15 * * * root certbot renew --quiet
EOF
# 2. Django scheduled tasks (replacing the former Heroku Scheduler jobs, run via exec inside the container)
cat > "$DJANGO_CRON" <<EOF
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# Generated by scripts/cron-install.sh; remove with scripts/cron-uninstall.sh
0 0 * * * root docker compose -f $REPO_DIR/compose.yml exec -T pyrigs sh -c "python manage.py cleanupregistration && python manage.py usercleanup" >> /var/log/pyrigs-cleanup.log 2>&1
0 8 * * * root docker compose -f $REPO_DIR/compose.yml exec -T pyrigs python manage.py send_reminders >> /var/log/pyrigs-reminders.log 2>&1
EOF
chmod 644 "$CERTBOT_CRON" "$DJANGO_CRON"
echo "Installed:"
echo " $CERTBOT_CRON"
echo " $DJANGO_CRON"