Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # WatchDog script for Proxmox VMs
- # v1.1
- #
- # Install using `crontab -e` like this: * * * * * /root/watchdog.sh
- #
- # Based on https://forum.proxmox.com/threads/simple-reset-script-ping.49901/
- #
- # Config
- adGuardVmName="AdGuardVM"
- adGuardVmId="100"
- adGuardVmIp="192.168.31.10"
- mainVmName="MainVM"
- mainVmId="101"
- mainVmIp="192.168.31.100"
- # Log func
- log () {
- output="[WatchDog] $1"
- echo $output && logger $output
- }
- # Check VM func
- checkVM () {
- if /usr/bin/ping -c 1 $3 &> /dev/null; then
- vmUptime=$(/usr/sbin/qm status $2 -verbose | grep uptime | cut -f2 -d' ')
- log "$1 seems alive, no action taken. Current uptime: $vmUptime"
- else
- log "$1 Crashed - Restarting now..."
- /usr/sbin/qm stop $2 && /usr/sbin/qm start $2
- fi
- }
- # Logic
- checkVM $adGuardVmName $adGuardVmId $adGuardVmIp
- checkVM $mainVmName $mainVmId $mainVmIp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement