Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
first pass at decommission_host script
Browse files Browse the repository at this point in the history
  • Loading branch information
solarce committed Jan 16, 2014
1 parent 8e13e50 commit c96d311
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions scripts/decommission_host
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
##decomm.sh
#
#!/bin/bash

SERVER=$1
BUG="https://bugzilla.mozilla.org/show_bug.cgi?id=960155"
PTR=$(dig +short $SERVER)
PK=$(invtool SYS detail --hostname $SERVER | grep pk: | awk '{print $2}')


if [ $# -lt 1 ]; then
echo "Usage: $0 <hostname>"
exit 1
fi

echo "setting comments with bug and IP, setting status to decommissioned"
invtool --silent SYS update --pk $PK --notes "$BUG $PTR"
invtool --silent SYS update --pk $PK --system-status-pk 6

KV=$(invtool --json SYS_kv list --obj-pk $PK)

PK_KVs=$(echo $KV | python -m json.tool | grep kv_pk | cut -d':' -f 2 | cut -d',' -f 1)

echo "deleting KV items"
for item in $PK_KVs
do
echo "deleting $item"
invtool --silent SYS_kv delete --kv-pk $item
done

A_PK=$(invtool search --query "/^$SERVER (type=:A OR type=:CNAME)" | cut -d ' ' -f 1)
if [ -n "$A_PK" ]
then
echo "deleting host's A record"
invtool A delete --pk $A_PK
else
echo "no A records exist"
fi

PTR_PK=$(invtool search --query "/^$PTR (type=:PTR)" | cut -d ' ' -f 1)
if [ -n "$PTR_PK" ]
then
echo "deleting host PTR record"
invtool --silent PTR delete --pk $PTR_PK
else
echo "no PTR records exist"
fi

0 comments on commit c96d311

Please sign in to comment.