pmpw/watchdog.sh

55 lines
947 B
Bash
Raw Permalink Normal View History

2024-06-18 23:28:39 +02:00
#!/bin/bash
# check if $1 exists
if [[ -z $1 ]]
then
echo "Pass a VMID."
exit 1
fi
#------------------------------------------------
# CONSTS
2025-02-25 16:14:14 +00:00
VMID="$1"
QMSTAT="$(/usr/sbin/qm status $VMID )" > /dev/nul> /dev/null0
2024-06-18 23:28:39 +02:00
#------------------------------------------------
# CODE
# check if container exists
2025-02-25 16:14:14 +00:00
if echo $QMSTAT | grep "not exist"
2024-06-18 23:28:39 +02:00
then
printf "\nNo such VM!\n"
exit 1
fi
2025-02-25 16:14:14 +00:00
VMSTATE=$(echo "$QMSTAT" | awk '{print $2}')
#echo $VMSTATE
2024-06-18 23:28:39 +02:00
case $VMSTATE in
"running")
2025-02-25 16:14:14 +00:00
#printf "VM %s" "$VMID" "allready running."
#echo ""
2024-06-18 23:28:39 +02:00
exit 0
;;
"stopped")
2025-02-25 16:14:14 +00:00
printf "\nStarting VM %s" "$VMID\n"
#echo "" # To lazy to fix output spacing
2025-02-25 17:56:24 +00:00
/usr/sbin/qm start "$VMID"
2025-05-08 00:00:48 +02:00
exit 1
2024-06-18 23:28:39 +02:00
;;
*)
printf "\nUnknown state\n"
exit 1
;;
esac
# If you have gotify or something simmilar you can paste it under "running")
2025-02-25 16:14:14 +00:00
# and under "stopped") for notifications.