guardrail to prevent conflicting linodes

This commit is contained in:
finn committed 2026-09-22 19:28:20 -07:00
1 parent 92960f4413
commit f477ea7d6b
1 file changed
+12
+12
View File
@@ -66,6 +66,18 @@ fi
# Linode API and be generally buggy and annoying in all further operations.
if [[ "$SCRIPT_ACTION" == "c" && -n "$LINODE_LABEL" ]]; then
# Safety guard: this script administers a single Linode. Creating another
# while one already exists would leave two servers competing for the same
# volume, so refuse instead. The instances list reports the total number of
# Linodes in "results", which is 0 when nothing is running.
EXISTING_COUNT=$(curl -s -H "Authorization: Bearer $LINODE_API_KEY" \
https://api.linode.com/v4/linode/instances | jq -r '.results // 0')
if [[ "$EXISTING_COUNT" != "0" ]]; then
echo "ERROR: $EXISTING_COUNT Linode(s) already exist; this script manages a single instance." >&2
echo " Destroy the existing one first: create-linode.sh d <label>" >&2
exit 1
fi
# Creating a Linode also refreshes the valheim A record, reusing the update
# block at the bottom of this script.
UPDATE_A_RECORD="true"