How I Made My Unraid VM Self-Heal with Discord Alerts
π‘ "My Home Assistant VM paused itself randomly. One day my lights didn't turn on and I knew it had to be fixed... permanently."
Running Home Assistant in a VM on Unraid is a solid approach β until the VM unexpectedly pauses and takes your smart home with it. This happened to me daily at one point.
So I built a simple, self-healing watchdog script:
- Detects when a VM is paused
- Sends me an instant Discord alert
- Automatically resumes the VM
- Confirms whether the resume was successful
No plugins, no docker containers, no fancy packages β just a clean Bash script and a Discord webhook.
π¦ What You'll Need:
- Unraid (6.12+ or 7.x)
virsh(comes with Unraid)- Discord (with webhook)
- User Scripts plugin (available via Community Apps)
π οΈ Step-by-Step Setup
1. Create a Discord Webhook
- Go to your server > channel > βοΈ β Integrations β Webhooks
- Create one, name it (e.g. "Unraid Alerts")
- Copy the webhook URL
2. Install User Scripts Plugin
- Go to Apps > Install
User Scripts - Open it via Settings > User Scripts
3. Add the Script
#!/bin/bash
VM_NAME="Hass"
STATE_FILE="/tmp/vm_${VM_NAME}_last_state"
WEBHOOK_URL="https://discord.com/api/webhooks/your-webhook-url"
CURRENT_STATE=$(virsh domstate "$VM_NAME" 2>/dev/null)
LAST_STATE=$(cat "$STATE_FILE" 2>/dev/null || echo "unknown")
echo "$CURRENT_STATE" > "$STATE_FILE"
if [[ "$CURRENT_STATE" == "paused" && "$LAST_STATE" != "paused" ]]; then
curl -H "Content-Type: application/json" -X POST \
-d '{"content": "π¨ VM '"$VM_NAME"' paused. Trying to resume..."}' "$WEBHOOK_URL"
virsh resume "$VM_NAME"
sleep 5
NEW_STATE=$(virsh domstate "$VM_NAME" 2>/dev/null)
if [[ "$NEW_STATE" == "running" ]]; then
curl -H "Content-Type: application/json" -X POST \
-d '{"content": "β
VM resumed successfully."}' "$WEBHOOK_URL"
else
curl -H "Content-Type: application/json" -X POST \
-d '{"content": "β VM could not be resumed."}' "$WEBHOOK_URL"
fi
fi
4. Schedule It
- Set the script to run every
5 minutesusing cron:*/5 * * * *
π§ͺ Result:
- I pause my VM β get notified on Discord β it resumes automatically.
- I get a second message confirming it worked β or didnβt.
π Bonus Ideas:
- Extend it to multiple VMs
- Add Telegram or Pushover alerts
- Write logs to flash for auditing:
echo "$(date): VM $VM_NAME paused/resumed" >> /boot/logs/vm_watchdog.log
π¬ Final Thoughts
This lightweight solution gives me peace of mind. My VM can still fail β but now it won't go unnoticed or unresolved. And if Home Assistant is critical in your setup like mine, itβs 100% worth the few minutes to set up.