System Maintenance¶
Guide for maintaining a Bifolk production installation.
Target Audience: System administrators
Health Checks¶
Quick Check¶
# Containers running
docker ps | grep bifolk
# Application responding
curl -I http://localhost:8000
# Django system check
docker compose exec bifolk-app python manage.py check --database default
# Recent logs
docker logs bifolk-app --tail 50
Health Check Schedule¶
| Frequency | Tasks |
|---|---|
| Daily | Containers running, no critical errors in logs, web interface accessible |
| Weekly | Database connectivity, disk space > 20%, no performance issues |
| Monthly | Full health check, review user accounts, verify backup success |
Viewing Logs¶
Application Logs¶
# Last 100 lines
docker logs bifolk-app --tail 100
# Follow logs in real-time (Ctrl+C to stop)
docker logs bifolk-app --follow
# Search for errors
docker logs bifolk-app 2>&1 | grep -i error
# Save logs to file
docker logs bifolk-app > bifolk-app-logs-$(date +%Y%m%d).log
Database Logs¶
# Recent database logs
docker logs bifolk-db --tail 100
# All services
docker compose logs --tail 50
Log Rotation¶
Log rotation is already configured at the container level in the Docker Compose files. Each service is set to:
- Log driver: json-file
- Max size: 10 MB per log file
- Max files: 3 rotated files
No manual configuration is required — logs are automatically rotated and limited.
Tip
If you need to change log rotation settings system-wide, you can configure /etc/docker/daemon.json as an alternative. However, the Compose configuration takes precedence for individual containers:
After editing, restart Docker: sudo systemctl restart docker
Database Maintenance¶
Vacuum and Analyze (PostgreSQL)¶
# Vacuum and analyze all tables
docker compose exec bifolk-db psql -U bifolk -d bifolk -c "VACUUM ANALYZE;"
# Full vacuum (requires exclusive locks, use during maintenance windows)
docker compose exec bifolk-db psql -U bifolk -d bifolk -c "VACUUM FULL ANALYZE;"
Database Size¶
# Total database size
docker compose exec bifolk-db psql -U bifolk -d bifolk -c \
"SELECT pg_size_pretty(pg_database_size('bifolk')) AS database_size;"
# Largest tables
docker compose exec bifolk-db psql -U bifolk -d bifolk -c "
SELECT tablename, pg_size_pretty(pg_total_relation_size(schemaname||'.'||tablename)) AS size
FROM pg_tables
WHERE schemaname NOT IN ('pg_catalog', 'information_schema')
ORDER BY pg_total_relation_size(schemaname||'.'||tablename) DESC
LIMIT 10;"
Clear Sessions¶
Static and Media Files¶
Static Files¶
# Collect static files
docker compose exec bifolk-app python manage.py collectstatic --no-input
# Clear and recollect
docker compose exec bifolk-app python manage.py collectstatic --no-input --clear
Media Files¶
# Check media file usage
docker compose exec bifolk-app du -sh /bifolk/media/
# Fix permissions if uploads fail
docker compose exec bifolk-app chown -R django:django /bifolk/media
Disk Space¶
# Host filesystem
df -h
# Docker disk usage
docker system df
# Clean unused Docker resources
docker system prune -f
docker image prune -a -f
Warning
Only run docker volume prune if you are certain no important data is stored in unnamed volumes.
Scheduled Maintenance¶
Cron Examples¶
# Weekly database vacuum (Sunday 2 AM)
0 2 * * 0 docker compose exec -T bifolk-db psql -U bifolk -d bifolk -c "VACUUM ANALYZE;" >> /var/log/bifolk-vacuum.log 2>&1
# Weekly session cleanup (Sunday 3 AM)
0 3 * * 0 docker compose exec -T bifolk-app python manage.py clearsessions >> /var/log/bifolk-maintenance.log 2>&1
# Weekly Docker cleanup (Sunday 4 AM)
0 4 * * 0 docker system prune -f >> /var/log/docker-cleanup.log 2>&1
Emergency Procedures¶
Application Down¶
# Check logs
docker logs bifolk-app --tail 100
# Restart container
docker restart bifolk-app
# If persistent, rebuild
docker compose down && docker compose up -d --build
Database Issues¶
# Check database health
docker compose exec bifolk-db pg_isready -U bifolk
# Restart database
docker restart bifolk-db
Disk Full¶
# Find large files
du -sh /* 2>/dev/null | sort -h
# Clean Docker resources
docker system prune -a -f
Related Documentation¶
- Backup & Restore - Backup procedures
- Troubleshooting - Common issues and solutions
- Upgrading - Version upgrades