From 95531708431448d1f2ae2d7573421c2980a16a17 Mon Sep 17 00:00:00 2001 From: Malfurious Date: Thu, 7 Sep 2023 00:28:38 -0400 Subject: acid: Remove running services no longer present in $CYCHE_SERVICES If a service was previously managed by cychedelic, but an update to the cyche code removes it from the config file, stop the service and delete the git clone. As usual, this should leave any docker volumes intact. Signed-off-by: Malfurious --- acid/cyche-remove | 20 ++++++++++++++++++++ acid/cychedelic | 12 ++++++++++++ 2 files changed, 32 insertions(+) create mode 100755 acid/cyche-remove diff --git a/acid/cyche-remove b/acid/cyche-remove new file mode 100755 index 0000000..1aa5f36 --- /dev/null +++ b/acid/cyche-remove @@ -0,0 +1,20 @@ +#!/bin/bash + +# cyche-remove +# +# Stop the service , which was previously managed by cychedelic, and +# remove associated files. + +cd "/services/$1" + +file=$(cat '.git/previous_file') +slug=$(cat '.git/previous_slug') +[ -n "$slug" ] && slug="--project-name $slug" + +docker compose $slug --file "$file" down \ + --remove-orphans + +echo "Removing files..." +cd ".." +rm -rf "$1" +echo "Done." diff --git a/acid/cychedelic b/acid/cychedelic index 17f2d33..a73554a 100755 --- a/acid/cychedelic +++ b/acid/cychedelic @@ -37,11 +37,23 @@ update() { done } +remove() { + next=$(printf '%s\n' "${CYCHE_SERVICES[@]}" | awk '{print $1}') + prev=$(ls -A '/services') + removed=$(printf '%s\n' "$next" "$next" "$prev" | sort | uniq -u) + + for name in $removed; do + cyche-remove "$name" + sleep "$CYCHE_JOB_TIME" + done +} + # startup: A restart of the ACID daemon usually indicates an elapse of the # $CYCHE_MAINT_TIME period, so rebuild services and perform cleanup now. We # sleep briefly at the beginning to allow the previous cychedelic instance time # to die. sleep "$CYCHE_STARTUP_TIME" +remove update --force docker system prune --force --all starttime=$(now) -- cgit v1.2.3