| 1 | * Org Mode |
| 2 | |
| 3 | [[LINK][DESCRIPTION]] |
| 4 | |
| 5 | https://demo.opengist.io/samask/test123/edit |
| 6 | |
| 7 | |
| 8 | /test/ |
| 9 | |
| 10 | [[test][test]] |
| 11 | |
| 12 | _test_ |
| 13 | |
| 14 | ** Test |
| 15 | |
| 16 | *** Test |
| 17 | |
| 18 | **** Test |
zone.sh
· 3.7 KiB · Bash
Raw
#!/bin/bash
# #############################################
# SmartOS Zombie Zone Cleanup Script
# Usage: ./nuke_zone.sh <UUID>
# 20200112
# Use as ./nuke_zone.sh ecc5d57a-3d90-44ca-a89b-8869a120487d
# #############################################
UUID=$1
# 1. Validation
if [[ -z "$UUID" ]]; then
echo "Error: No UUID provided."
echo "Usage: $0 <zone-uuid>"
exit 1
fi
if [[ "$UUID" == "global" ]]; then
echo "Error: Cannot delete the global zone."
exit 1
fi
# Basic check to see if the UUID string format looks roughly correct (simple check)
if [[ ! "$UUID" =~ ^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$ ]]; then
echo "Warning: Format of '$UUID' does not look like a standard UUID."
read -p "Are you sure you want to proceed? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi
echo "--- Starting cleanup for Zone: $UUID ---"
# 2. Check current status
STATE=$(zoneadm -z "$UUID" list -p 2>/dev/null | cut -d: -f3)
if [[ -z "$STATE" ]]; then
echo "Zone currently not recognized by zoneadm. Checking ZFS leftovers..."
else
echo "Current Zone State: $STATE"
fi
# 3. Analyze and Kill Suspicious Processes
echo "Checking for stuck processes..."
# We look for zoneadmd specifically, as it is the controller.
# We also look for qemu/bhyve instances associated with the UUID.
PIDS=$(pgrep -f "$UUID")
if [[ -n "$PIDS" ]]; then
echo "Found the following processes associated with this UUID:"
pgrep -lf "$UUID"
echo "Attempting to kill these processes to release locks..."
# We use kill -9 (SIGKILL) because if we are here, the process is likely unresponsive to SIGTERM.
echo "$PIDS" | xargs kill -9
sleep 2
# Verify they are gone
REMAINING=$(pgrep -f "$UUID")
if [[ -n "$REMAINING" ]]; then
echo "WARNING: Some processes refused to die: $REMAINING"
echo "This may indicate a kernel-level hung task (zombie)."
else
echo "Processes cleared."
fi
else
echo "No locking processes found."
fi
# 4. Force state to installed/halted if possible
# If the zone is technically 'running' in the kernel, we must halt it before uninstalling.
if [[ "$STATE" == "running" || "$STATE" == "shutting_down" ]]; then
echo "Forcing zone halt..."
zoneadm -z "$UUID" halt
sleep 2
fi
# 5. Force Uninstall
echo "Attempting forced uninstall (zoneadm)..."
zoneadm -z "$UUID" uninstall -F
RET=$?
if [[ $RET -eq 0 ]]; then
echo "zoneadm uninstall reported success."
else
echo "zoneadm uninstall reported an error (exit code $RET)."
echo "Proceeding to ZFS cleanup anyway."
fi
# 6. ZFS Dataset Cleanup
# vmadm requires the dataset 'zones/<UUID>' to be gone to consider the VM deleted.
DATASET="zones/$UUID"
if zfs list "$DATASET" > /dev/null 2>&1; then
echo "ZFS dataset $DATASET still exists. Destroying it..."
# Check if there are dependent snapshots or clones (unlikely for a deletion, but possible)
# -r recursively destroys children/snapshots
zfs destroy -r "$DATASET"
if [[ $? -eq 0 ]]; then
echo "Dataset destroyed."
else
echo "Failed to destroy dataset. Check 'zfs list' manually."
fi
else
echo "ZFS dataset $DATASET is already gone."
fi
# 7. Final Verification
echo "--- Final Status Check ---"
if vmadm list | grep -q "$UUID"; then
echo "FAILURE: $UUID still appears in 'vmadm list'."
vmadm list | grep "$UUID"
else
echo "SUCCESS: $UUID is no longer in 'vmadm list'."
fi
if zoneadm list -cv | grep -q "$UUID"; then
echo "WARNING: $UUID still appears in 'zoneadm list'."
else
echo "SUCCESS: $UUID is no longer in 'zoneadm list'."
fi
# #############################################
| 1 | #!/bin/bash |
| 2 | |
| 3 | # ############################################# |
| 4 | # SmartOS Zombie Zone Cleanup Script |
| 5 | # Usage: ./nuke_zone.sh <UUID> |
| 6 | # 20200112 |
| 7 | # Use as ./nuke_zone.sh ecc5d57a-3d90-44ca-a89b-8869a120487d |
| 8 | # ############################################# |
| 9 | |
| 10 | UUID=$1 |
| 11 | |
| 12 | # 1. Validation |
| 13 | if [[ -z "$UUID" ]]; then |
| 14 | echo "Error: No UUID provided." |
| 15 | echo "Usage: $0 <zone-uuid>" |
| 16 | exit 1 |
| 17 | fi |
| 18 | |
| 19 | if [[ "$UUID" == "global" ]]; then |
| 20 | echo "Error: Cannot delete the global zone." |
| 21 | exit 1 |
| 22 | fi |
| 23 | |
| 24 | # Basic check to see if the UUID string format looks roughly correct (simple check) |
| 25 | if [[ ! "$UUID" =~ ^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$ ]]; then |
| 26 | echo "Warning: Format of '$UUID' does not look like a standard UUID." |
| 27 | read -p "Are you sure you want to proceed? (y/n) " -n 1 -r |
| 28 | echo |
| 29 | if [[ ! $REPLY =~ ^[Yy]$ ]]; then |
| 30 | exit 1 |
| 31 | fi |
| 32 | fi |
| 33 | |
| 34 | echo "--- Starting cleanup for Zone: $UUID ---" |
| 35 | |
| 36 | # 2. Check current status |
| 37 | STATE=$(zoneadm -z "$UUID" list -p 2>/dev/null | cut -d: -f3) |
| 38 | |
| 39 | if [[ -z "$STATE" ]]; then |
| 40 | echo "Zone currently not recognized by zoneadm. Checking ZFS leftovers..." |
| 41 | else |
| 42 | echo "Current Zone State: $STATE" |
| 43 | fi |
| 44 | |
| 45 | # 3. Analyze and Kill Suspicious Processes |
| 46 | echo "Checking for stuck processes..." |
| 47 | # We look for zoneadmd specifically, as it is the controller. |
| 48 | # We also look for qemu/bhyve instances associated with the UUID. |
| 49 | PIDS=$(pgrep -f "$UUID") |
| 50 | |
| 51 | if [[ -n "$PIDS" ]]; then |
| 52 | echo "Found the following processes associated with this UUID:" |
| 53 | pgrep -lf "$UUID" |
| 54 | |
| 55 | echo "Attempting to kill these processes to release locks..." |
| 56 | # We use kill -9 (SIGKILL) because if we are here, the process is likely unresponsive to SIGTERM. |
| 57 | echo "$PIDS" | xargs kill -9 |
| 58 | sleep 2 |
| 59 | |
| 60 | # Verify they are gone |
| 61 | REMAINING=$(pgrep -f "$UUID") |
| 62 | if [[ -n "$REMAINING" ]]; then |
| 63 | echo "WARNING: Some processes refused to die: $REMAINING" |
| 64 | echo "This may indicate a kernel-level hung task (zombie)." |
| 65 | else |
| 66 | echo "Processes cleared." |
| 67 | fi |
| 68 | else |
| 69 | echo "No locking processes found." |
| 70 | fi |
| 71 | |
| 72 | # 4. Force state to installed/halted if possible |
| 73 | # If the zone is technically 'running' in the kernel, we must halt it before uninstalling. |
| 74 | if [[ "$STATE" == "running" || "$STATE" == "shutting_down" ]]; then |
| 75 | echo "Forcing zone halt..." |
| 76 | zoneadm -z "$UUID" halt |
| 77 | sleep 2 |
| 78 | fi |
| 79 | |
| 80 | # 5. Force Uninstall |
| 81 | echo "Attempting forced uninstall (zoneadm)..." |
| 82 | zoneadm -z "$UUID" uninstall -F |
| 83 | RET=$? |
| 84 | |
| 85 | if [[ $RET -eq 0 ]]; then |
| 86 | echo "zoneadm uninstall reported success." |
| 87 | else |
| 88 | echo "zoneadm uninstall reported an error (exit code $RET)." |
| 89 | echo "Proceeding to ZFS cleanup anyway." |
| 90 | fi |
| 91 | |
| 92 | # 6. ZFS Dataset Cleanup |
| 93 | # vmadm requires the dataset 'zones/<UUID>' to be gone to consider the VM deleted. |
| 94 | DATASET="zones/$UUID" |
| 95 | if zfs list "$DATASET" > /dev/null 2>&1; then |
| 96 | echo "ZFS dataset $DATASET still exists. Destroying it..." |
| 97 | |
| 98 | # Check if there are dependent snapshots or clones (unlikely for a deletion, but possible) |
| 99 | # -r recursively destroys children/snapshots |
| 100 | zfs destroy -r "$DATASET" |
| 101 | |
| 102 | if [[ $? -eq 0 ]]; then |
| 103 | echo "Dataset destroyed." |
| 104 | else |
| 105 | echo "Failed to destroy dataset. Check 'zfs list' manually." |
| 106 | fi |
| 107 | else |
| 108 | echo "ZFS dataset $DATASET is already gone." |
| 109 | fi |
| 110 | |
| 111 | # 7. Final Verification |
| 112 | echo "--- Final Status Check ---" |
| 113 | if vmadm list | grep -q "$UUID"; then |
| 114 | echo "FAILURE: $UUID still appears in 'vmadm list'." |
| 115 | vmadm list | grep "$UUID" |
| 116 | else |
| 117 | echo "SUCCESS: $UUID is no longer in 'vmadm list'." |
| 118 | fi |
| 119 | |
| 120 | if zoneadm list -cv | grep -q "$UUID"; then |
| 121 | echo "WARNING: $UUID still appears in 'zoneadm list'." |
| 122 | else |
| 123 | echo "SUCCESS: $UUID is no longer in 'zoneadm list'." |
| 124 | fi |
| 125 | |
| 126 | # ############################################# |