From 77de05e8564dc155fcddac4e7fee0f26415bf388 Mon Sep 17 00:00:00 2001 From: William Petit Date: Thu, 20 Oct 2022 21:22:17 +0200 Subject: [PATCH] feat: add cleanup-worker script --- misc/clean-worker.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 misc/clean-worker.sh diff --git a/misc/clean-worker.sh b/misc/clean-worker.sh new file mode 100644 index 0000000..72fffa4 --- /dev/null +++ b/misc/clean-worker.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +cleanup_docker() { + RUNNING_CONTAINERS=$(docker ps -q) + if [ ! -z "$RUNNING_CONTAINERS" ]; then + docker stop $RUNNING_CONTAINERS + fi + + docker system prune -f -a --volumes + docker network prune -f + + service docker restart +} + +cleanup_old_workspaces() { + # Suppression des workspaces dont la dernière date + # de modification est supérieure à 7 jours. + find /workspace -maxdepth 1 -type d -mtime +7 -exec rm -rf {} \; +} + +main() { + cleanup_docker + cleanup_old_workspaces +} + +main \ No newline at end of file