GitLab Runner Cleanup Setup

This utility installs a daily systemd timer on self-hosted GitLab CI/CD runners that automatically prunes accumulated Docker images, containers, volumes, and build cache, then runs fstrim to reclaim space on SSDs. Without periodic cleanup, cached Docker layers will slowly fill the runner's drive.

What It Does

Automated Installation

To install, run the following command on your GitLab runner. This will download and execute the installation script with sudo privileges.

Using curl:

curl -sL https://random.clusterlabs.dev/scripts/gitlab-runner-cleanup/install.sh | sudo bash

Using wget:

wget -qO- https://random.clusterlabs.dev/scripts/gitlab-runner-cleanup/install.sh | sudo bash

Download install.sh

Installation Script Content:


Automated Uninstallation

To remove the cleanup timer and script, run the corresponding command below.

Using curl:

curl -sL https://random.clusterlabs.dev/scripts/gitlab-runner-cleanup/uninstall.sh | sudo bash

Using wget:

wget -qO- https://random.clusterlabs.dev/scripts/gitlab-runner-cleanup/uninstall.sh | sudo bash

Download uninstall.sh

Uninstallation Script Content:


Monitoring and Verification

After installation, you can check the timer status and view cleanup logs.

Check Timer Status

sudo systemctl status gitlab-runner-cleanup.timer

View Logs

sudo journalctl -u gitlab-runner-cleanup.service -f

Run Cleanup Immediately

sudo systemctl start gitlab-runner-cleanup.service