working valheim checkpoint

This commit is contained in:
2026-09-20 23:45:00 -07:00
parent a981013d89
commit 02d485ddbf
3 changed files with 243 additions and 83 deletions
+55 -18
View File
@@ -26,7 +26,8 @@ VOLUME_MOUNT="/mnt/$VOLUME_NAME"
# StackScript that mounts the volume on first boot (see stackscript.md).
# Enter the numeric StackScript ID manually after creating it in the Linode UI.
STACKSCRIPT_ID="2225110"
#STACKSCRIPT_ID="2225110"
STACKSCRIPT_ID="2225140"
if [[ "$SCRIPT_ACTION" == "" || "$SCRIPT_ACTION" == "--help" || "$SCRIPT_ACTION" == "-?" ]]; then
echo "Linode helper script: create-linode.sh <action> <label> [args]"
@@ -38,6 +39,7 @@ if [[ "$SCRIPT_ACTION" == "" || "$SCRIPT_ACTION" == "--help" || "$SCRIPT_ACTION"
echo " create-linode.sh x <label> get <remote source> <local dest>"
echo " create-linode.sh x <label> put <local source> <remote dest>"
echo "Update record: create-linode.sh a <label> <subdomain>"
echo " (updates the existing A record, creates one if missing)"
echo "List: create-linode.sh l"
echo " (lists all Linodes, no label needed)"
fi
@@ -118,6 +120,17 @@ if [[ "$SCRIPT_ACTION" == "d" ]]; then
INSTANCE_ID=$(curl -s -H "Authorization: Bearer $LINODE_API_KEY" https://api.linode.com/v4/linode/instances | jq '.data[] | select(.label == "'$LINODE_LABEL'") | .id' | sed -e "s/\"//g")
echo "Destroying ID:$INSTANCE_ID Hit Ctrl-C in the next 10 seconds to cancel."
sleep 15
# Shut the Linode down cleanly before deleting it, so systemd stops the
# Docker container and the Valheim server gets the chance to save the world
# rather than being cut off mid-write.
echo "Shutting down ID:$INSTANCE_ID..."
curl -s -H "Authorization: Bearer $LINODE_API_KEY" \
-X POST https://api.linode.com/v4/linode/instances/$INSTANCE_ID/shutdown | jq .
# Give the shutdown time to finish before the instance is deleted.
sleep 30
curl -s -H "Authorization: Bearer $LINODE_API_KEY" \
-X DELETE https://api.linode.com/v4/linode/instances/$INSTANCE_ID
echo "$(date -Iminutes) --- Id:$INSTANCE_ID --- IP:$INSTANCE_IP Destroyed $LINODE_LABEL." >>$LOGFILE
@@ -154,30 +167,54 @@ if [[ "$SCRIPT_ACTION" == "a" ]]; then
INSTANCE_IP=$(curl -s -H "Authorization: Bearer $LINODE_API_KEY" https://api.linode.com/v4/linode/instances | jq '.data[] | select(.label == "'$LINODE_LABEL'") | .ipv4[]' | sed -e "s/\"//g")
NI_SUBDOMAIN=$3
DOMAIN_RECORDS=$(curl -s -H "Authorization: Bearer $LINODE_API_KEY" \
https://api.linode.com/v4/domains/$WHICH_DOMAIN/records)
echo "Previous value:"
curl -s -H "Authorization: Bearer $LINODE_API_KEY" \
https://api.linode.com/v4/domains/$WHICH_DOMAIN/records | jq .
echo "$DOMAIN_RECORDS" | jq .
sleep 3
# Update the A record that already exists for this subdomain rather than
# adding another one; a record is only created when there is nothing to
# update. DNS names are case-insensitive, so compare them that way.
RECORD_IDS=$(echo "$DOMAIN_RECORDS" | jq -r --arg name "$NI_SUBDOMAIN" \
'.data[] | select(.type == "A" and ((.name // "") | ascii_downcase) == ($name | ascii_downcase)) | .id')
RECORD_ID=$(echo "$RECORD_IDS" | head -n 1)
DUPLICATE_IDS=$(echo "$RECORD_IDS" | tail -n +2)
echo "Updating records with ip $INSTANCE_IP..."
#ni7ne:
curl -s -H "Content-Type: application/json" \
-H "Authorization: Bearer $LINODE_API_KEY" \
-X POST -d '{
"type": "A",
"name": "'$NI_SUBDOMAIN'",
"target": "'$INSTANCE_IP'",
"priority": 0,
"weight": 0,
"port": 0,
"service": null,
"protocol": null,
"ttl_sec": 14400,
"tag": null
}' \
https://api.linode.com/v4/domains/$WHICH_DOMAIN/records | jq .
if [[ -n "$RECORD_ID" ]]; then
curl -s -H "Content-Type: application/json" \
-H "Authorization: Bearer $LINODE_API_KEY" \
-X PUT -d '{
"type": "A",
"name": "'$NI_SUBDOMAIN'",
"target": "'$INSTANCE_IP'",
"ttl_sec": 14400
}' \
https://api.linode.com/v4/domains/$WHICH_DOMAIN/records/$RECORD_ID | jq .
# Duplicates left behind by earlier runs would keep resolving to an old
# IP, so remove everything except the record that was just updated.
for DUPLICATE_ID in $DUPLICATE_IDS; do
echo "Deleting duplicate A record $DUPLICATE_ID for $NI_SUBDOMAIN..."
curl -s -H "Authorization: Bearer $LINODE_API_KEY" \
-X DELETE https://api.linode.com/v4/domains/$WHICH_DOMAIN/records/$DUPLICATE_ID
done
else
curl -s -H "Content-Type: application/json" \
-H "Authorization: Bearer $LINODE_API_KEY" \
-X POST -d '{
"type": "A",
"name": "'$NI_SUBDOMAIN'",
"target": "'$INSTANCE_IP'",
"ttl_sec": 14400
}' \
https://api.linode.com/v4/domains/$WHICH_DOMAIN/records | jq .
fi
echo "Update complete."