Skip to content

Instantly share code, notes, and snippets.

@stefanotorresi
Created September 28, 2018 12:17
Show Gist options
  • Save stefanotorresi/907be4ab1fa1dd0674da43f340127d31 to your computer and use it in GitHub Desktop.
Save stefanotorresi/907be4ab1fa1dd0674da43f340127d31 to your computer and use it in GitHub Desktop.
Gitlab CI runner cleanup script
#!/bin/bash
set -euo pipefail
export PATH=$PATH:/usr/local/bin:/usr/local/sbin
echo "*****"
date +%F\ %T
echo "stopping gitlab-runner service..."
systemctl stop gitlab-runner
echo "removing instances..."
DOCKER_INSTANCES=$(docker-machine ls -f "{{.Name}}")
DROPLETS=$(doctl compute droplet list --tag-name auto-generated --format ID | awk '{if(NR>1)print}')
[ -z "${DOCKER_INSTANCES}" ] || docker-machine rm -f ${DOCKER_INSTANCES}
[ -z "${DROPLETS}" ] || doctl compute droplet delete -f ${DROPLETS}
echo "restarting gitlab-runner service..."
systemctl start gitlab-runner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment