Skip to content

Instantly share code, notes, and snippets.

@Buthrakaur
Last active March 7, 2024 13:32
Show Gist options
  • Select an option

  • Save Buthrakaur/4eb1ad2bbe07e0dc39d1bee5df039f39 to your computer and use it in GitHub Desktop.

Select an option

Save Buthrakaur/4eb1ad2bbe07e0dc39d1bee5df039f39 to your computer and use it in GitHub Desktop.

Revisions

  1. Buthrakaur revised this gist Mar 7, 2024. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions gitlab_runner_cleanup.sh
    Original file line number Diff line number Diff line change
    @@ -30,12 +30,18 @@ if [ "$FREE_SPACE_BYTES" -le "$THRESHOLD" ]; then
    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."
  2. Buthrakaur created this gist Mar 7, 2024.
    42 changes: 42 additions & 0 deletions gitlab_runner_cleanup.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    #!/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/*"

    # 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