The forge-server can accumulate cache files over time, leading to disk space issues. This document describes the disk space monitoring and cleanup mechanisms.
Critical Threshold: 90%
Warning Threshold: 80%
- Frequency: Every 5 minutes
- Action: Removes cache files older than 7 days
- Location:
/tmp/cache/and/tmp/forgerc_sites/
Location: scripts/disk-space-cleanup.sh
Features:
- Monitors disk usage on root filesystem (
/) - Performs routine cleanup of cache files older than 7 days
- Aggressive cleanup when disk usage exceeds 90%:
- Removes cache files older than 1 day
- Cleans old log files (30+ days)
- Truncates large Docker log files
- Sends Slack notifications for warnings and critical alerts
Manual Execution:
sudo /app/scripts/disk-space-cleanup.shTo run the cleanup script automatically every hour:
# Copy service and timer files
sudo cp systemd/disk-space-cleanup.service /etc/systemd/system/
sudo cp systemd/disk-space-cleanup.timer /etc/systemd/system/
# Enable and start the timer
sudo systemctl daemon-reload
sudo systemctl enable disk-space-cleanup.timer
sudo systemctl start disk-space-cleanup.timer
# Check status
sudo systemctl status disk-space-cleanup.timer
sudo systemctl list-timers disk-space-cleanup.timerdf -h /du -sh /tmp/cache/
du -sh /tmp/forgerc_sites/tail -f /var/log/disk-space-cleanup.logsudo systemctl status disk-space-cleanup.timer
sudo journalctl -u disk-space-cleanup.service -fIf disk space is critically low (90%+), you can manually trigger aggressive cleanup:
# Run the cleanup script
sudo /app/scripts/disk-space-cleanup.sh
# Or manually clean old cache files
find /tmp/cache -type f -mtime +1 -delete
find /tmp/forgerc_sites -type f -mtime +1 -delete
# Clean empty directories
find /tmp/cache -type d -empty -delete
find /tmp/forgerc_sites -type d -empty -deleteEdit deleter.js:
const CLEAR_INTERVAL = 5000*60; // 5 minutes (in milliseconds)
const CACHE_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000; // 7 daysEdit scripts/disk-space-cleanup.sh:
DISK_USAGE_THRESHOLD=80 # Alert at 80%
CRITICAL_THRESHOLD=90 # Critical at 90%
CACHE_MAX_AGE_DAYS=7 # Remove cache files older than 7 daysEdit systemd/disk-space-cleanup.timer:
OnUnitActiveSec=1h # Change to desired frequency (e.g., 30m, 2h)-
Check for large log files:
find /var/log -type f -size +100M -ls
-
Check Docker container logs:
docker ps docker logs <container-id> --tail 100
-
Check for large files in /tmp:
find /tmp -type f -size +100M -ls
-
Check system logs:
journalctl --disk-usage
-
Check script permissions:
ls -l /app/scripts/disk-space-cleanup.sh # Should be executable: -rwxr-xr-x -
Check systemd timer:
sudo systemctl status disk-space-cleanup.timer
-
Check for errors:
sudo journalctl -u disk-space-cleanup.service -n 50
- Monitor Regularly: Set up alerts for disk usage above 80%
- Regular Cleanups: Run cleanup script at least once per hour
- Log Rotation: Ensure log rotation is configured for application logs
- Docker Logs: Configure Docker log rotation to prevent log files from growing too large
- Cache Management: Monitor cache directory size and adjust cleanup frequency if needed
deleter.js- Automatic cache cleanupscripts/disk-space-cleanup.sh- Manual cleanup scriptsystemd/disk-space-cleanup.service- Systemd service filesystemd/disk-space-cleanup.timer- Systemd timer file