Maintenance Mode Commands
Commands for managing maintenance mode and Cloudflare integration.
Maintenance Mode
maintenance
Manage maintenance mode for your application.
python manage.py maintenance [ACTION] [OPTIONS]Actions:
enable- Enable maintenance modedisable- Disable maintenance modestatus- Show maintenance status
Options:
--cloudflare- Sync with Cloudflare
Examples:
# Enable maintenance mode
python manage.py maintenance enable
# Enable with Cloudflare sync
python manage.py maintenance enable --cloudflare
# Disable maintenance mode
python manage.py maintenance disable
# Disable with Cloudflare sync
python manage.py maintenance disable --cloudflare
# Check status
python manage.py maintenance statusCloudflare Integration
sync_cloudflare
Sync maintenance mode with Cloudflare.
python manage.py sync_cloudflare [OPTIONS]Options:
--enable- Enable Cloudflare maintenance--disable- Disable Cloudflare maintenance
Examples:
# Enable Cloudflare maintenance page
python manage.py sync_cloudflare --enable
# Disable Cloudflare maintenance page
python manage.py sync_cloudflare --disableWhat it does:
- Updates Cloudflare page rules
- Activates maintenance page
- Preserves admin access
- Logs all changes
Scheduled Maintenance
process_scheduled_maintenance
Process scheduled maintenance windows automatically.
python manage.py process_scheduled_maintenanceFeatures:
- Checks scheduled maintenance windows
- Automatically enables/disables maintenance
- Sends notifications
- Logs all actions
Cron Setup:
# Check every 5 minutes
*/5 * * * * cd /path/to/project && python manage.py process_scheduled_maintenance
# Check every minute for precise timing
* * * * * cd /path/to/project && python manage.py process_scheduled_maintenanceCommon Workflows
Manual Maintenance
# 1. Enable maintenance
python manage.py maintenance enable --cloudflare
# 2. Perform updates
python manage.py migrate_all
python manage.py collectstatic --noinput
# 3. Disable maintenance
python manage.py maintenance disable --cloudflareScheduled Maintenance
# Schedule maintenance in Django admin
# Then let cron handle it automaticallyEmergency Maintenance
# Quick enable
python manage.py maintenance enable --cloudflare
# Check status
python manage.py maintenance statusConfiguration
Django Configuration
# config.py
class MyConfig(DjangoConfig):
# Enable maintenance app
enable_maintenance: bool = True
# Cloudflare configuration
cloudflare_api_key: str = env.cloudflare.api_key
cloudflare_zone_id: str = env.cloudflare.zone_idEnvironment Variables
# config.dev.yaml
cloudflare:
api_key: "your_cloudflare_api_key"
zone_id: "your_zone_id"
email: "[email protected]"Best Practices
1. Always Use Cloudflare Sync
# ✅ GOOD - Syncs with Cloudflare
python manage.py maintenance enable --cloudflare
# ⚠️ LIMITED - Only Django, no CDN
python manage.py maintenance enable2. Test Maintenance Page First
# Enable, test, then disable
python manage.py maintenance enable
# Test page appearance
python manage.py maintenance disable3. Schedule During Low Traffic
# Schedule for 2 AM - 4 AM
# Add to Django admin maintenance schedule4. Monitor Scheduled Tasks
# Check cron logs
tail -f /var/log/syslog | grep maintenanceRelated Documentation
- Quick Reference - Fast command lookup
- Maintenance App Guide - Complete documentation
Maintenance mode without downtime stress! 🔧