Skip to main content

Server Maintenance: Deep Cleaning a Hybrid Ecosystem (Debian + Docker + YunoHost)

As someone self-hosting a hybrid ecosystem (YunoHost for core apps, Docker for custom deployments), I have learnt that "digital cruft" is inevitable. Over time, servers accumulate bloated system logs, old backup archives, and unused Docker image layers.

This guide documents the maintenance routine I use to keep my VPS healthy. In a recent session, this specific workflow helped reclaim ~129 GB of storage and ~2 GB of RAM by identifying forgotten processes (like an unused Algorand node) and vacuuming old caches.

1. Initial Assessment (The Diagnosis)

Before running destructive commands, I always establish a baseline. It is crucial not to operate on blind faith.

  • Check Disk Usage: df -h /
  • Check RAM/System Stats: htop or neofetch
  • Check Docker Consumption: docker system df

Note: If "Reclaimable" space in Docker is high (e.g., >20%), that is your primary target.

2. Docker Hygiene (The Big Sweeper)

Docker is often the largest consumer of disk space. However, never use general system cleaners (like BleachBit) on Docker directories (/var/lib/docker), as this will corrupt your containers. Use native tools only.

Step A: Analyse and Stop

Identify containers that are "exited" but still reserving space or ports.

docker ps -a --filter "status=exited"

If you see old experiments you no longer need, delete them.

Step B: The Prune Commands

  • Safe Prune: Removes dangling images (no tags) and stopped containers.
docker system prune

  • Deep Prune (Aggressive): I use this only when I am sure I do not need old versions of images (e.g., after a successful upgrade). It removes all images not currently attached to a running container.
docker image prune -a -f

  • Volume Prune: Removes "orphaned" storage volumes.
docker volume prune

3. System Deep Clean (Debian & Logs)

For the underlying Debian system, I use a combination of standard apt commands and bleachbit via the Command Line Interface (CLI).

The "Safe" BleachBit CLI Method

Warning: Do not run "Deep Scan" or "Free Disk Space" on a production VPS; it strains I/O excessively. Use specific flags to target caches and logs only.

sudo apt update && sudo apt install bleachbit -y

# Run the cleaning routine
sudo bleachbit --clean \
apt.autoclean \
apt.autoremove \
apt.clean \
deepscan.tmp \
journald.clean \
system.cache \
system.rotated_logs \
system.tmp \
system.trash

Vacuuming System Journals

Systemd journals can grow to gigabytes on YunoHost. This command forces a cleanup, keeping only the last 2 days of logs:

sudo journalctl --vacuum-time=2d

4. YunoHost Specific Maintenance

YunoHost requires specific care because aggressive cleaning can delete database backups or configuration files.

Managing Backups

YunoHost creates "pre-upgrade" hooks automatically. These pile up.

  1. List archives: yunohost backup list
  2. Delete old archives manually: yunohost backup delete <archive_name>
  3. Clear download cache: rm -rf /var/cache/yunohost/download/*

Efficient Domain Management (Chaining Commands)

When reorganising subdomains on obulou.org, using the web interface is slow. I prefer chaining commands in the terminal using the semicolon ;. This allows the server to process removal, addition, and rebooting in one sequence.

Example workflow:

# Remove deprecated domains, add a new service, and reboot
sudo yunohost domain remove old-app.obulou.org; \
sudo yunohost domain remove test.obulou.org; \
sudo yunohost domain add new-service.obulou.org; \
sudo reboot

5. Results & Validation

After completing the steps above, run df -h / again.

Real-world Metric:

  • Before Cleanup: 196.42 GB used (50%)
  • After Cleanup: 67.11 GB used (17%)
  • Total Reclaimed: 129.31 GB

Summary Checklist

  1. Audit: Run htop and docker ps to find forgotten active processes.
  2. Docker: Prune unused images and volumes using native commands.
  3. System: Run BleachBit CLI for apt/tmp/logs (avoiding Docker paths).
  4. YunoHost: clear old backups and chain domain commands for efficiency.