Advertisement
rursache

Proxmox WatchDog for VMs

Jul 17th, 2022 (edited)
493
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.87 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # WatchDog script for Proxmox VMs
  4. # v1.1
  5. #
  6. # Install using `crontab -e` like this: * * * * * /root/watchdog.sh
  7. #
  8. # Based on https://forum.proxmox.com/threads/simple-reset-script-ping.49901/
  9. #
  10.  
  11. # Config
  12. adGuardVmName="AdGuardVM"
  13. adGuardVmId="100"
  14. adGuardVmIp="192.168.31.10"
  15.  
  16. mainVmName="MainVM"
  17. mainVmId="101"
  18. mainVmIp="192.168.31.100"
  19.  
  20. # Log func
  21. log () {
  22.     output="[WatchDog] $1"
  23.     echo $output && logger $output
  24. }
  25.  
  26. # Check VM func
  27. checkVM () {
  28. if /usr/bin/ping -c 1 $3 &> /dev/null; then
  29.     vmUptime=$(/usr/sbin/qm status $2 -verbose | grep uptime | cut -f2 -d' ')
  30.     log "$1 seems alive, no action taken. Current uptime: $vmUptime"
  31. else
  32.     log "$1 Crashed - Restarting now..."
  33.     /usr/sbin/qm stop $2 && /usr/sbin/qm start $2
  34. fi
  35. }
  36.  
  37. # Logic
  38. checkVM $adGuardVmName $adGuardVmId $adGuardVmIp
  39. checkVM $mainVmName $mainVmId $mainVmIp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement