Skip to content

Instantly share code, notes, and snippets.

@Buthrakaur
Last active March 7, 2024 13:32
Show Gist options
  • Save Buthrakaur/4eb1ad2bbe07e0dc39d1bee5df039f39 to your computer and use it in GitHub Desktop.
Save Buthrakaur/4eb1ad2bbe07e0dc39d1bee5df039f39 to your computer and use it in GitHub Desktop.
gitlab runner cleanup script
#!/bin/bash
# cron setup:
# copy this script to ~
# chmod +x ~/gitlab_runner_cleanup.sh
# crontab -e
# # add following line:
# 0 3 * * * ~/gitlab_runner_cleanup.sh >> ~/gitlab_runner_cleanup.log 2>&1
# Threshold for disk space, set to 5GB (5 * 1024 * 1024 * 1024 bytes)
THRESHOLD=$((5*1024*1024*1024))
# Check free disk space on the root partition
FREE_SPACE=$(df -k / | tail -n 1 | awk '{print $4}')
# Convert KB to Bytes for comparison
FREE_SPACE_BYTES=$(($FREE_SPACE * 1024))
if [ "$FREE_SPACE_BYTES" -le "$THRESHOLD" ]; then
echo "Free space is below threshold, performing cleanup..."
# Path to GitLab Runner's directories
GITLAB_RUNNER_HOME=~
# Clean up cache
echo "Cleaning up cache..."
rm -rf "${GITLAB_RUNNER_HOME}/cache/*"
# Clean up builds
echo "Cleaning up builds..."
rm -rf "${GITLAB_RUNNER_HOME}/builds/*"
# Clean up XCode cache
rm -rf ~/Library/Developer/Xcode/DerivedData
rm -rf ~/Library/Developer/Xcode/Archives/*
# Add additional cleanup for other directories if needed
# echo "Cleaning up additional directories..."
# rm -rf "/path/to/other/directories/*"
rm "${GITLAB_RUNNER_HOME}/gitlab-runner*.log"
echo "Cleanup completed."
else
echo "Disk space is sufficient."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment