summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMalfurious <m@lfurio.us>2023-09-07 00:28:38 -0400
committerMalfurious <m@lfurio.us>2023-09-08 19:07:29 -0400
commit95531708431448d1f2ae2d7573421c2980a16a17 (patch)
tree6ca5414f83524ae703aa1ea6a391ca63c3923705
parent7a7ff89ff16542d30ff7c1f70689236b8fd9c607 (diff)
downloadcychedelic-95531708431448d1f2ae2d7573421c2980a16a17.tar.gz
cychedelic-95531708431448d1f2ae2d7573421c2980a16a17.zip
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 <m@lfurio.us>
-rwxr-xr-xacid/cyche-remove20
-rwxr-xr-xacid/cychedelic12
2 files changed, 32 insertions, 0 deletions
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 <name>
+#
+# Stop the service <name>, 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)