Files
ProxmoxVE/tools/pve/monitor-all.sh

180 lines
5.4 KiB
Bash
Raw Normal View History

2023-04-29 00:04:09 -04:00
#!/usr/bin/env bash
# Copyright (c) 2021-2025 tteck
2023-04-29 00:04:09 -04:00
# Author: tteck (tteckster)
# License: MIT
# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
2023-04-29 00:04:09 -04:00
clear
cat <<"EOF"
__ ___ _ __ ___ ____
/ |/ /___ ____ (_) /_____ _____ / | / / /
/ /|_/ / __ \/ __ \/ / __/ __ \/ ___/ / /| | / / /
/ / / / /_/ / / / / / /_/ /_/ / / / ___ |/ / /
/_/ /_/\____/_/ /_/_/\__/\____/_/ /_/ |_/_/_/
EOF
add() {
Update monitor-all.sh (#4437) ✅ Summary of Changes from the Initial Version 🧩 1. Tag-Based Filtering (Core Feature) New feature: Only restart instances (VMs or containers) that have the mon-restart tag. This makes monitoring and auto-restart controllable directly from the Proxmox Web UI, without editing scripts or services. Set via GUI: VM → Options → Tags → mon-restart Set via CLI: qm set <vmid> -tags mon-restart or pct set <ctid> -tags mon-restart This is the primary new control mechanism, making the script safer, more flexible, and user-friendly. 🧰 2. Backward-Compatible Exclusion Mechanism The original feature that lets you exclude instances via CLI arguments is preserved: bash Copy Edit ./ping-instances.sh 101 300 These IDs will always be skipped regardless of tag. 🧠 3. Intelligent Responsiveness Checks For VMs: Uses qm guest cmd <id> ping to check responsiveness via the QEMU guest agent. No longer relies on network-level ping, which can be misleading or blocked. For containers (CTs): Uses traditional ping to IP addresses obtained from pct exec, since CTs don’t support QEMU agent. ⛔ 4. Instance Skipping Improvements Instances are now skipped if: They are explicitly excluded via CLI. They are templates. They are configured with onboot: 0 or missing. They lack the mon-restart tag, regardless of other status. 🪵 5. Same Logging Behavior All output continues to go to /var/log/ping-instances.log for persistent tracking. Verbose messages were added for traceability (e.g., why a VM or CT was skipped). 🎯 Why This Matters With tag-based control, admins can now manage restart behavior dynamically from the Proxmox Web UI, making the script: More secure (no accidental restarts). More maintainable (no script edits needed). More user-friendly (integrated with the UI workflow).
2025-05-14 12:00:57 +03:00
echo -e "\n IMPORTANT: Tag-Based Monitoring Enabled"
echo "Only VMs and containers with the tag 'mon-restart' will be automatically restarted by this service."
echo
echo "🔧 How to add the tag:"
echo " → Proxmox Web UI: Go to VM/CT → Options → Tags → Add 'mon-restart'"
echo " → CLI: qm set <vmid> -tags mon-restart"
echo " pct set <ctid> -tags mon-restart"
echo
while true; do
Update monitor-all.sh (#4437) ✅ Summary of Changes from the Initial Version 🧩 1. Tag-Based Filtering (Core Feature) New feature: Only restart instances (VMs or containers) that have the mon-restart tag. This makes monitoring and auto-restart controllable directly from the Proxmox Web UI, without editing scripts or services. Set via GUI: VM → Options → Tags → mon-restart Set via CLI: qm set <vmid> -tags mon-restart or pct set <ctid> -tags mon-restart This is the primary new control mechanism, making the script safer, more flexible, and user-friendly. 🧰 2. Backward-Compatible Exclusion Mechanism The original feature that lets you exclude instances via CLI arguments is preserved: bash Copy Edit ./ping-instances.sh 101 300 These IDs will always be skipped regardless of tag. 🧠 3. Intelligent Responsiveness Checks For VMs: Uses qm guest cmd <id> ping to check responsiveness via the QEMU guest agent. No longer relies on network-level ping, which can be misleading or blocked. For containers (CTs): Uses traditional ping to IP addresses obtained from pct exec, since CTs don’t support QEMU agent. ⛔ 4. Instance Skipping Improvements Instances are now skipped if: They are explicitly excluded via CLI. They are templates. They are configured with onboot: 0 or missing. They lack the mon-restart tag, regardless of other status. 🪵 5. Same Logging Behavior All output continues to go to /var/log/ping-instances.log for persistent tracking. Verbose messages were added for traceability (e.g., why a VM or CT was skipped). 🎯 Why This Matters With tag-based control, admins can now manage restart behavior dynamically from the Proxmox Web UI, making the script: More secure (no accidental restarts). More maintainable (no script edits needed). More user-friendly (integrated with the UI workflow).
2025-05-14 12:00:57 +03:00
read -p "This script will add Monitor All to Proxmox VE. Proceed (y/n)? " yn
case $yn in
Update monitor-all.sh (#4437) ✅ Summary of Changes from the Initial Version 🧩 1. Tag-Based Filtering (Core Feature) New feature: Only restart instances (VMs or containers) that have the mon-restart tag. This makes monitoring and auto-restart controllable directly from the Proxmox Web UI, without editing scripts or services. Set via GUI: VM → Options → Tags → mon-restart Set via CLI: qm set <vmid> -tags mon-restart or pct set <ctid> -tags mon-restart This is the primary new control mechanism, making the script safer, more flexible, and user-friendly. 🧰 2. Backward-Compatible Exclusion Mechanism The original feature that lets you exclude instances via CLI arguments is preserved: bash Copy Edit ./ping-instances.sh 101 300 These IDs will always be skipped regardless of tag. 🧠 3. Intelligent Responsiveness Checks For VMs: Uses qm guest cmd <id> ping to check responsiveness via the QEMU guest agent. No longer relies on network-level ping, which can be misleading or blocked. For containers (CTs): Uses traditional ping to IP addresses obtained from pct exec, since CTs don’t support QEMU agent. ⛔ 4. Instance Skipping Improvements Instances are now skipped if: They are explicitly excluded via CLI. They are templates. They are configured with onboot: 0 or missing. They lack the mon-restart tag, regardless of other status. 🪵 5. Same Logging Behavior All output continues to go to /var/log/ping-instances.log for persistent tracking. Verbose messages were added for traceability (e.g., why a VM or CT was skipped). 🎯 Why This Matters With tag-based control, admins can now manage restart behavior dynamically from the Proxmox Web UI, making the script: More secure (no accidental restarts). More maintainable (no script edits needed). More user-friendly (integrated with the UI workflow).
2025-05-14 12:00:57 +03:00
[Yy]*) break ;;
[Nn]*) exit ;;
*) echo "Please answer yes or no." ;;
esac
done
Update monitor-all.sh (#4437) ✅ Summary of Changes from the Initial Version 🧩 1. Tag-Based Filtering (Core Feature) New feature: Only restart instances (VMs or containers) that have the mon-restart tag. This makes monitoring and auto-restart controllable directly from the Proxmox Web UI, without editing scripts or services. Set via GUI: VM → Options → Tags → mon-restart Set via CLI: qm set <vmid> -tags mon-restart or pct set <ctid> -tags mon-restart This is the primary new control mechanism, making the script safer, more flexible, and user-friendly. 🧰 2. Backward-Compatible Exclusion Mechanism The original feature that lets you exclude instances via CLI arguments is preserved: bash Copy Edit ./ping-instances.sh 101 300 These IDs will always be skipped regardless of tag. 🧠 3. Intelligent Responsiveness Checks For VMs: Uses qm guest cmd <id> ping to check responsiveness via the QEMU guest agent. No longer relies on network-level ping, which can be misleading or blocked. For containers (CTs): Uses traditional ping to IP addresses obtained from pct exec, since CTs don’t support QEMU agent. ⛔ 4. Instance Skipping Improvements Instances are now skipped if: They are explicitly excluded via CLI. They are templates. They are configured with onboot: 0 or missing. They lack the mon-restart tag, regardless of other status. 🪵 5. Same Logging Behavior All output continues to go to /var/log/ping-instances.log for persistent tracking. Verbose messages were added for traceability (e.g., why a VM or CT was skipped). 🎯 Why This Matters With tag-based control, admins can now manage restart behavior dynamically from the Proxmox Web UI, making the script: More secure (no accidental restarts). More maintainable (no script edits needed). More user-friendly (integrated with the UI workflow).
2025-05-14 12:00:57 +03:00
cat <<'EOF' >/usr/local/bin/ping-instances.sh
#!/usr/bin/env bash
2023-04-29 00:04:09 -04:00
# Read excluded instances from command line arguments
excluded_instances=("$@")
echo "Excluded instances: ${excluded_instances[@]}"
2023-04-30 04:48:05 -04:00
while true; do
2023-04-29 00:04:09 -04:00
Update monitor-all.sh (#4437) ✅ Summary of Changes from the Initial Version 🧩 1. Tag-Based Filtering (Core Feature) New feature: Only restart instances (VMs or containers) that have the mon-restart tag. This makes monitoring and auto-restart controllable directly from the Proxmox Web UI, without editing scripts or services. Set via GUI: VM → Options → Tags → mon-restart Set via CLI: qm set <vmid> -tags mon-restart or pct set <ctid> -tags mon-restart This is the primary new control mechanism, making the script safer, more flexible, and user-friendly. 🧰 2. Backward-Compatible Exclusion Mechanism The original feature that lets you exclude instances via CLI arguments is preserved: bash Copy Edit ./ping-instances.sh 101 300 These IDs will always be skipped regardless of tag. 🧠 3. Intelligent Responsiveness Checks For VMs: Uses qm guest cmd <id> ping to check responsiveness via the QEMU guest agent. No longer relies on network-level ping, which can be misleading or blocked. For containers (CTs): Uses traditional ping to IP addresses obtained from pct exec, since CTs don’t support QEMU agent. ⛔ 4. Instance Skipping Improvements Instances are now skipped if: They are explicitly excluded via CLI. They are templates. They are configured with onboot: 0 or missing. They lack the mon-restart tag, regardless of other status. 🪵 5. Same Logging Behavior All output continues to go to /var/log/ping-instances.log for persistent tracking. Verbose messages were added for traceability (e.g., why a VM or CT was skipped). 🎯 Why This Matters With tag-based control, admins can now manage restart behavior dynamically from the Proxmox Web UI, making the script: More secure (no accidental restarts). More maintainable (no script edits needed). More user-friendly (integrated with the UI workflow).
2025-05-14 12:00:57 +03:00
for instance in $(pct list | awk 'NR>1 {print $1}'; qm list | awk 'NR>1 {print $1}'); do
2023-04-29 00:04:09 -04:00
# Skip excluded instances
if [[ " ${excluded_instances[@]} " =~ " ${instance} " ]]; then
2023-09-21 19:00:13 -04:00
echo "Skipping $instance because it is excluded"
2023-04-29 00:04:09 -04:00
continue
fi
Update monitor-all.sh (#4437) ✅ Summary of Changes from the Initial Version 🧩 1. Tag-Based Filtering (Core Feature) New feature: Only restart instances (VMs or containers) that have the mon-restart tag. This makes monitoring and auto-restart controllable directly from the Proxmox Web UI, without editing scripts or services. Set via GUI: VM → Options → Tags → mon-restart Set via CLI: qm set <vmid> -tags mon-restart or pct set <ctid> -tags mon-restart This is the primary new control mechanism, making the script safer, more flexible, and user-friendly. 🧰 2. Backward-Compatible Exclusion Mechanism The original feature that lets you exclude instances via CLI arguments is preserved: bash Copy Edit ./ping-instances.sh 101 300 These IDs will always be skipped regardless of tag. 🧠 3. Intelligent Responsiveness Checks For VMs: Uses qm guest cmd <id> ping to check responsiveness via the QEMU guest agent. No longer relies on network-level ping, which can be misleading or blocked. For containers (CTs): Uses traditional ping to IP addresses obtained from pct exec, since CTs don’t support QEMU agent. ⛔ 4. Instance Skipping Improvements Instances are now skipped if: They are explicitly excluded via CLI. They are templates. They are configured with onboot: 0 or missing. They lack the mon-restart tag, regardless of other status. 🪵 5. Same Logging Behavior All output continues to go to /var/log/ping-instances.log for persistent tracking. Verbose messages were added for traceability (e.g., why a VM or CT was skipped). 🎯 Why This Matters With tag-based control, admins can now manage restart behavior dynamically from the Proxmox Web UI, making the script: More secure (no accidental restarts). More maintainable (no script edits needed). More user-friendly (integrated with the UI workflow).
2025-05-14 12:00:57 +03:00
# Determine type and set config command
2023-04-29 00:04:09 -04:00
if pct status $instance >/dev/null 2>&1; then
Update monitor-all.sh (#4437) ✅ Summary of Changes from the Initial Version 🧩 1. Tag-Based Filtering (Core Feature) New feature: Only restart instances (VMs or containers) that have the mon-restart tag. This makes monitoring and auto-restart controllable directly from the Proxmox Web UI, without editing scripts or services. Set via GUI: VM → Options → Tags → mon-restart Set via CLI: qm set <vmid> -tags mon-restart or pct set <ctid> -tags mon-restart This is the primary new control mechanism, making the script safer, more flexible, and user-friendly. 🧰 2. Backward-Compatible Exclusion Mechanism The original feature that lets you exclude instances via CLI arguments is preserved: bash Copy Edit ./ping-instances.sh 101 300 These IDs will always be skipped regardless of tag. 🧠 3. Intelligent Responsiveness Checks For VMs: Uses qm guest cmd <id> ping to check responsiveness via the QEMU guest agent. No longer relies on network-level ping, which can be misleading or blocked. For containers (CTs): Uses traditional ping to IP addresses obtained from pct exec, since CTs don’t support QEMU agent. ⛔ 4. Instance Skipping Improvements Instances are now skipped if: They are explicitly excluded via CLI. They are templates. They are configured with onboot: 0 or missing. They lack the mon-restart tag, regardless of other status. 🪵 5. Same Logging Behavior All output continues to go to /var/log/ping-instances.log for persistent tracking. Verbose messages were added for traceability (e.g., why a VM or CT was skipped). 🎯 Why This Matters With tag-based control, admins can now manage restart behavior dynamically from the Proxmox Web UI, making the script: More secure (no accidental restarts). More maintainable (no script edits needed). More user-friendly (integrated with the UI workflow).
2025-05-14 12:00:57 +03:00
type="ct"
2023-04-29 00:04:09 -04:00
config_cmd="pct config"
else
Update monitor-all.sh (#4437) ✅ Summary of Changes from the Initial Version 🧩 1. Tag-Based Filtering (Core Feature) New feature: Only restart instances (VMs or containers) that have the mon-restart tag. This makes monitoring and auto-restart controllable directly from the Proxmox Web UI, without editing scripts or services. Set via GUI: VM → Options → Tags → mon-restart Set via CLI: qm set <vmid> -tags mon-restart or pct set <ctid> -tags mon-restart This is the primary new control mechanism, making the script safer, more flexible, and user-friendly. 🧰 2. Backward-Compatible Exclusion Mechanism The original feature that lets you exclude instances via CLI arguments is preserved: bash Copy Edit ./ping-instances.sh 101 300 These IDs will always be skipped regardless of tag. 🧠 3. Intelligent Responsiveness Checks For VMs: Uses qm guest cmd <id> ping to check responsiveness via the QEMU guest agent. No longer relies on network-level ping, which can be misleading or blocked. For containers (CTs): Uses traditional ping to IP addresses obtained from pct exec, since CTs don’t support QEMU agent. ⛔ 4. Instance Skipping Improvements Instances are now skipped if: They are explicitly excluded via CLI. They are templates. They are configured with onboot: 0 or missing. They lack the mon-restart tag, regardless of other status. 🪵 5. Same Logging Behavior All output continues to go to /var/log/ping-instances.log for persistent tracking. Verbose messages were added for traceability (e.g., why a VM or CT was skipped). 🎯 Why This Matters With tag-based control, admins can now manage restart behavior dynamically from the Proxmox Web UI, making the script: More secure (no accidental restarts). More maintainable (no script edits needed). More user-friendly (integrated with the UI workflow).
2025-05-14 12:00:57 +03:00
type="vm"
2023-04-29 00:04:09 -04:00
config_cmd="qm config"
fi
Update monitor-all.sh (#4437) ✅ Summary of Changes from the Initial Version 🧩 1. Tag-Based Filtering (Core Feature) New feature: Only restart instances (VMs or containers) that have the mon-restart tag. This makes monitoring and auto-restart controllable directly from the Proxmox Web UI, without editing scripts or services. Set via GUI: VM → Options → Tags → mon-restart Set via CLI: qm set <vmid> -tags mon-restart or pct set <ctid> -tags mon-restart This is the primary new control mechanism, making the script safer, more flexible, and user-friendly. 🧰 2. Backward-Compatible Exclusion Mechanism The original feature that lets you exclude instances via CLI arguments is preserved: bash Copy Edit ./ping-instances.sh 101 300 These IDs will always be skipped regardless of tag. 🧠 3. Intelligent Responsiveness Checks For VMs: Uses qm guest cmd <id> ping to check responsiveness via the QEMU guest agent. No longer relies on network-level ping, which can be misleading or blocked. For containers (CTs): Uses traditional ping to IP addresses obtained from pct exec, since CTs don’t support QEMU agent. ⛔ 4. Instance Skipping Improvements Instances are now skipped if: They are explicitly excluded via CLI. They are templates. They are configured with onboot: 0 or missing. They lack the mon-restart tag, regardless of other status. 🪵 5. Same Logging Behavior All output continues to go to /var/log/ping-instances.log for persistent tracking. Verbose messages were added for traceability (e.g., why a VM or CT was skipped). 🎯 Why This Matters With tag-based control, admins can now manage restart behavior dynamically from the Proxmox Web UI, making the script: More secure (no accidental restarts). More maintainable (no script edits needed). More user-friendly (integrated with the UI workflow).
2025-05-14 12:00:57 +03:00
# Skip templates and onboot-disabled
2023-11-20 17:46:05 -05:00
onboot=$($config_cmd $instance | grep -q "onboot: 0" || ( ! $config_cmd $instance | grep -q "onboot" ) && echo "true" || echo "false")
Update monitor-all.sh (#4437) ✅ Summary of Changes from the Initial Version 🧩 1. Tag-Based Filtering (Core Feature) New feature: Only restart instances (VMs or containers) that have the mon-restart tag. This makes monitoring and auto-restart controllable directly from the Proxmox Web UI, without editing scripts or services. Set via GUI: VM → Options → Tags → mon-restart Set via CLI: qm set <vmid> -tags mon-restart or pct set <ctid> -tags mon-restart This is the primary new control mechanism, making the script safer, more flexible, and user-friendly. 🧰 2. Backward-Compatible Exclusion Mechanism The original feature that lets you exclude instances via CLI arguments is preserved: bash Copy Edit ./ping-instances.sh 101 300 These IDs will always be skipped regardless of tag. 🧠 3. Intelligent Responsiveness Checks For VMs: Uses qm guest cmd <id> ping to check responsiveness via the QEMU guest agent. No longer relies on network-level ping, which can be misleading or blocked. For containers (CTs): Uses traditional ping to IP addresses obtained from pct exec, since CTs don’t support QEMU agent. ⛔ 4. Instance Skipping Improvements Instances are now skipped if: They are explicitly excluded via CLI. They are templates. They are configured with onboot: 0 or missing. They lack the mon-restart tag, regardless of other status. 🪵 5. Same Logging Behavior All output continues to go to /var/log/ping-instances.log for persistent tracking. Verbose messages were added for traceability (e.g., why a VM or CT was skipped). 🎯 Why This Matters With tag-based control, admins can now manage restart behavior dynamically from the Proxmox Web UI, making the script: More secure (no accidental restarts). More maintainable (no script edits needed). More user-friendly (integrated with the UI workflow).
2025-05-14 12:00:57 +03:00
template=$($config_cmd $instance | grep -q "^template:" && echo "true" || echo "false")
if [ "$onboot" == "true" ]; then
echo "Skipping $instance because it is set not to boot"
continue
elif [ "$template" == "true" ]; then
2023-04-29 00:04:09 -04:00
echo "Skipping $instance because it is a template"
continue
fi
Update monitor-all.sh (#4437) ✅ Summary of Changes from the Initial Version 🧩 1. Tag-Based Filtering (Core Feature) New feature: Only restart instances (VMs or containers) that have the mon-restart tag. This makes monitoring and auto-restart controllable directly from the Proxmox Web UI, without editing scripts or services. Set via GUI: VM → Options → Tags → mon-restart Set via CLI: qm set <vmid> -tags mon-restart or pct set <ctid> -tags mon-restart This is the primary new control mechanism, making the script safer, more flexible, and user-friendly. 🧰 2. Backward-Compatible Exclusion Mechanism The original feature that lets you exclude instances via CLI arguments is preserved: bash Copy Edit ./ping-instances.sh 101 300 These IDs will always be skipped regardless of tag. 🧠 3. Intelligent Responsiveness Checks For VMs: Uses qm guest cmd <id> ping to check responsiveness via the QEMU guest agent. No longer relies on network-level ping, which can be misleading or blocked. For containers (CTs): Uses traditional ping to IP addresses obtained from pct exec, since CTs don’t support QEMU agent. ⛔ 4. Instance Skipping Improvements Instances are now skipped if: They are explicitly excluded via CLI. They are templates. They are configured with onboot: 0 or missing. They lack the mon-restart tag, regardless of other status. 🪵 5. Same Logging Behavior All output continues to go to /var/log/ping-instances.log for persistent tracking. Verbose messages were added for traceability (e.g., why a VM or CT was skipped). 🎯 Why This Matters With tag-based control, admins can now manage restart behavior dynamically from the Proxmox Web UI, making the script: More secure (no accidental restarts). More maintainable (no script edits needed). More user-friendly (integrated with the UI workflow).
2025-05-14 12:00:57 +03:00
# Check for mon-restart tag
has_tag=$($config_cmd $instance | grep -q "tags:.*mon-restart" && echo "true" || echo "false")
if [ "$has_tag" != "true" ]; then
echo "Skipping $instance because it does not have 'mon-restart' tag"
continue
fi
# Responsiveness check and restart if needed
if [ "$type" == "vm" ]; then
# Check if guest agent responds
if qm guest cmd $instance ping >/dev/null 2>&1; then
echo "VM $instance is responsive via guest agent"
2023-04-29 00:04:09 -04:00
else
Update monitor-all.sh (#4437) ✅ Summary of Changes from the Initial Version 🧩 1. Tag-Based Filtering (Core Feature) New feature: Only restart instances (VMs or containers) that have the mon-restart tag. This makes monitoring and auto-restart controllable directly from the Proxmox Web UI, without editing scripts or services. Set via GUI: VM → Options → Tags → mon-restart Set via CLI: qm set <vmid> -tags mon-restart or pct set <ctid> -tags mon-restart This is the primary new control mechanism, making the script safer, more flexible, and user-friendly. 🧰 2. Backward-Compatible Exclusion Mechanism The original feature that lets you exclude instances via CLI arguments is preserved: bash Copy Edit ./ping-instances.sh 101 300 These IDs will always be skipped regardless of tag. 🧠 3. Intelligent Responsiveness Checks For VMs: Uses qm guest cmd <id> ping to check responsiveness via the QEMU guest agent. No longer relies on network-level ping, which can be misleading or blocked. For containers (CTs): Uses traditional ping to IP addresses obtained from pct exec, since CTs don’t support QEMU agent. ⛔ 4. Instance Skipping Improvements Instances are now skipped if: They are explicitly excluded via CLI. They are templates. They are configured with onboot: 0 or missing. They lack the mon-restart tag, regardless of other status. 🪵 5. Same Logging Behavior All output continues to go to /var/log/ping-instances.log for persistent tracking. Verbose messages were added for traceability (e.g., why a VM or CT was skipped). 🎯 Why This Matters With tag-based control, admins can now manage restart behavior dynamically from the Proxmox Web UI, making the script: More secure (no accidental restarts). More maintainable (no script edits needed). More user-friendly (integrated with the UI workflow).
2025-05-14 12:00:57 +03:00
echo "$(date): VM $instance is not responding to agent ping, restarting..."
2023-04-29 00:04:09 -04:00
if qm status $instance | grep -q "status: running"; then
qm stop $instance >/dev/null 2>&1
sleep 5
2023-04-29 00:04:09 -04:00
fi
qm start $instance >/dev/null 2>&1
2023-04-29 00:04:09 -04:00
fi
Update monitor-all.sh (#4437) ✅ Summary of Changes from the Initial Version 🧩 1. Tag-Based Filtering (Core Feature) New feature: Only restart instances (VMs or containers) that have the mon-restart tag. This makes monitoring and auto-restart controllable directly from the Proxmox Web UI, without editing scripts or services. Set via GUI: VM → Options → Tags → mon-restart Set via CLI: qm set <vmid> -tags mon-restart or pct set <ctid> -tags mon-restart This is the primary new control mechanism, making the script safer, more flexible, and user-friendly. 🧰 2. Backward-Compatible Exclusion Mechanism The original feature that lets you exclude instances via CLI arguments is preserved: bash Copy Edit ./ping-instances.sh 101 300 These IDs will always be skipped regardless of tag. 🧠 3. Intelligent Responsiveness Checks For VMs: Uses qm guest cmd <id> ping to check responsiveness via the QEMU guest agent. No longer relies on network-level ping, which can be misleading or blocked. For containers (CTs): Uses traditional ping to IP addresses obtained from pct exec, since CTs don’t support QEMU agent. ⛔ 4. Instance Skipping Improvements Instances are now skipped if: They are explicitly excluded via CLI. They are templates. They are configured with onboot: 0 or missing. They lack the mon-restart tag, regardless of other status. 🪵 5. Same Logging Behavior All output continues to go to /var/log/ping-instances.log for persistent tracking. Verbose messages were added for traceability (e.g., why a VM or CT was skipped). 🎯 Why This Matters With tag-based control, admins can now manage restart behavior dynamically from the Proxmox Web UI, making the script: More secure (no accidental restarts). More maintainable (no script edits needed). More user-friendly (integrated with the UI workflow).
2025-05-14 12:00:57 +03:00
else
# Container: get IP and ping
IP=$(pct exec $instance ip a s dev eth0 | awk '/inet / {print $2}' | cut -d/ -f1 | head -n1)
Update monitor-all.sh (#4437) ✅ Summary of Changes from the Initial Version 🧩 1. Tag-Based Filtering (Core Feature) New feature: Only restart instances (VMs or containers) that have the mon-restart tag. This makes monitoring and auto-restart controllable directly from the Proxmox Web UI, without editing scripts or services. Set via GUI: VM → Options → Tags → mon-restart Set via CLI: qm set <vmid> -tags mon-restart or pct set <ctid> -tags mon-restart This is the primary new control mechanism, making the script safer, more flexible, and user-friendly. 🧰 2. Backward-Compatible Exclusion Mechanism The original feature that lets you exclude instances via CLI arguments is preserved: bash Copy Edit ./ping-instances.sh 101 300 These IDs will always be skipped regardless of tag. 🧠 3. Intelligent Responsiveness Checks For VMs: Uses qm guest cmd <id> ping to check responsiveness via the QEMU guest agent. No longer relies on network-level ping, which can be misleading or blocked. For containers (CTs): Uses traditional ping to IP addresses obtained from pct exec, since CTs don’t support QEMU agent. ⛔ 4. Instance Skipping Improvements Instances are now skipped if: They are explicitly excluded via CLI. They are templates. They are configured with onboot: 0 or missing. They lack the mon-restart tag, regardless of other status. 🪵 5. Same Logging Behavior All output continues to go to /var/log/ping-instances.log for persistent tracking. Verbose messages were added for traceability (e.g., why a VM or CT was skipped). 🎯 Why This Matters With tag-based control, admins can now manage restart behavior dynamically from the Proxmox Web UI, making the script: More secure (no accidental restarts). More maintainable (no script edits needed). More user-friendly (integrated with the UI workflow).
2025-05-14 12:00:57 +03:00
if ! ping -c 1 $IP >/dev/null 2>&1; then
echo "$(date): CT $instance is not responding, restarting..."
pct stop $instance >/dev/null 2>&1
sleep 5
pct start $instance >/dev/null 2>&1
else
echo "CT $instance is responsive"
fi
2023-04-29 00:04:09 -04:00
fi
done
echo "$(date): Pausing for 5 minutes..."
sleep 300
Update monitor-all.sh (#4437) ✅ Summary of Changes from the Initial Version 🧩 1. Tag-Based Filtering (Core Feature) New feature: Only restart instances (VMs or containers) that have the mon-restart tag. This makes monitoring and auto-restart controllable directly from the Proxmox Web UI, without editing scripts or services. Set via GUI: VM → Options → Tags → mon-restart Set via CLI: qm set <vmid> -tags mon-restart or pct set <ctid> -tags mon-restart This is the primary new control mechanism, making the script safer, more flexible, and user-friendly. 🧰 2. Backward-Compatible Exclusion Mechanism The original feature that lets you exclude instances via CLI arguments is preserved: bash Copy Edit ./ping-instances.sh 101 300 These IDs will always be skipped regardless of tag. 🧠 3. Intelligent Responsiveness Checks For VMs: Uses qm guest cmd <id> ping to check responsiveness via the QEMU guest agent. No longer relies on network-level ping, which can be misleading or blocked. For containers (CTs): Uses traditional ping to IP addresses obtained from pct exec, since CTs don’t support QEMU agent. ⛔ 4. Instance Skipping Improvements Instances are now skipped if: They are explicitly excluded via CLI. They are templates. They are configured with onboot: 0 or missing. They lack the mon-restart tag, regardless of other status. 🪵 5. Same Logging Behavior All output continues to go to /var/log/ping-instances.log for persistent tracking. Verbose messages were added for traceability (e.g., why a VM or CT was skipped). 🎯 Why This Matters With tag-based control, admins can now manage restart behavior dynamically from the Proxmox Web UI, making the script: More secure (no accidental restarts). More maintainable (no script edits needed). More user-friendly (integrated with the UI workflow).
2025-05-14 12:00:57 +03:00
done >/var/log/ping-instances.log 2>&1
EOF
touch /var/log/ping-instances.log
chmod +x /usr/local/bin/ping-instances.sh
Update monitor-all.sh (#4437) ✅ Summary of Changes from the Initial Version 🧩 1. Tag-Based Filtering (Core Feature) New feature: Only restart instances (VMs or containers) that have the mon-restart tag. This makes monitoring and auto-restart controllable directly from the Proxmox Web UI, without editing scripts or services. Set via GUI: VM → Options → Tags → mon-restart Set via CLI: qm set <vmid> -tags mon-restart or pct set <ctid> -tags mon-restart This is the primary new control mechanism, making the script safer, more flexible, and user-friendly. 🧰 2. Backward-Compatible Exclusion Mechanism The original feature that lets you exclude instances via CLI arguments is preserved: bash Copy Edit ./ping-instances.sh 101 300 These IDs will always be skipped regardless of tag. 🧠 3. Intelligent Responsiveness Checks For VMs: Uses qm guest cmd <id> ping to check responsiveness via the QEMU guest agent. No longer relies on network-level ping, which can be misleading or blocked. For containers (CTs): Uses traditional ping to IP addresses obtained from pct exec, since CTs don’t support QEMU agent. ⛔ 4. Instance Skipping Improvements Instances are now skipped if: They are explicitly excluded via CLI. They are templates. They are configured with onboot: 0 or missing. They lack the mon-restart tag, regardless of other status. 🪵 5. Same Logging Behavior All output continues to go to /var/log/ping-instances.log for persistent tracking. Verbose messages were added for traceability (e.g., why a VM or CT was skipped). 🎯 Why This Matters With tag-based control, admins can now manage restart behavior dynamically from the Proxmox Web UI, making the script: More secure (no accidental restarts). More maintainable (no script edits needed). More user-friendly (integrated with the UI workflow).
2025-05-14 12:00:57 +03:00
cat <<EOF >/etc/systemd/system/ping-instances.timer
2023-10-14 12:31:06 -04:00
[Unit]
Description=Delay ping-instances.service by 5 minutes
[Timer]
OnBootSec=300
OnUnitActiveSec=300
[Install]
WantedBy=timers.target
EOF
2023-04-29 00:04:09 -04:00
cat <<EOF >/etc/systemd/system/ping-instances.service
2023-10-14 12:31:06 -04:00
[Unit]
Update monitor-all.sh (#4437) ✅ Summary of Changes from the Initial Version 🧩 1. Tag-Based Filtering (Core Feature) New feature: Only restart instances (VMs or containers) that have the mon-restart tag. This makes monitoring and auto-restart controllable directly from the Proxmox Web UI, without editing scripts or services. Set via GUI: VM → Options → Tags → mon-restart Set via CLI: qm set <vmid> -tags mon-restart or pct set <ctid> -tags mon-restart This is the primary new control mechanism, making the script safer, more flexible, and user-friendly. 🧰 2. Backward-Compatible Exclusion Mechanism The original feature that lets you exclude instances via CLI arguments is preserved: bash Copy Edit ./ping-instances.sh 101 300 These IDs will always be skipped regardless of tag. 🧠 3. Intelligent Responsiveness Checks For VMs: Uses qm guest cmd <id> ping to check responsiveness via the QEMU guest agent. No longer relies on network-level ping, which can be misleading or blocked. For containers (CTs): Uses traditional ping to IP addresses obtained from pct exec, since CTs don’t support QEMU agent. ⛔ 4. Instance Skipping Improvements Instances are now skipped if: They are explicitly excluded via CLI. They are templates. They are configured with onboot: 0 or missing. They lack the mon-restart tag, regardless of other status. 🪵 5. Same Logging Behavior All output continues to go to /var/log/ping-instances.log for persistent tracking. Verbose messages were added for traceability (e.g., why a VM or CT was skipped). 🎯 Why This Matters With tag-based control, admins can now manage restart behavior dynamically from the Proxmox Web UI, making the script: More secure (no accidental restarts). More maintainable (no script edits needed). More user-friendly (integrated with the UI workflow).
2025-05-14 12:00:57 +03:00
Description=Ping instances every 5 minutes and restart if necessary
2023-10-14 12:31:06 -04:00
After=ping-instances.timer
Requires=ping-instances.timer
Update monitor-all.sh (#4437) ✅ Summary of Changes from the Initial Version 🧩 1. Tag-Based Filtering (Core Feature) New feature: Only restart instances (VMs or containers) that have the mon-restart tag. This makes monitoring and auto-restart controllable directly from the Proxmox Web UI, without editing scripts or services. Set via GUI: VM → Options → Tags → mon-restart Set via CLI: qm set <vmid> -tags mon-restart or pct set <ctid> -tags mon-restart This is the primary new control mechanism, making the script safer, more flexible, and user-friendly. 🧰 2. Backward-Compatible Exclusion Mechanism The original feature that lets you exclude instances via CLI arguments is preserved: bash Copy Edit ./ping-instances.sh 101 300 These IDs will always be skipped regardless of tag. 🧠 3. Intelligent Responsiveness Checks For VMs: Uses qm guest cmd <id> ping to check responsiveness via the QEMU guest agent. No longer relies on network-level ping, which can be misleading or blocked. For containers (CTs): Uses traditional ping to IP addresses obtained from pct exec, since CTs don’t support QEMU agent. ⛔ 4. Instance Skipping Improvements Instances are now skipped if: They are explicitly excluded via CLI. They are templates. They are configured with onboot: 0 or missing. They lack the mon-restart tag, regardless of other status. 🪵 5. Same Logging Behavior All output continues to go to /var/log/ping-instances.log for persistent tracking. Verbose messages were added for traceability (e.g., why a VM or CT was skipped). 🎯 Why This Matters With tag-based control, admins can now manage restart behavior dynamically from the Proxmox Web UI, making the script: More secure (no accidental restarts). More maintainable (no script edits needed). More user-friendly (integrated with the UI workflow).
2025-05-14 12:00:57 +03:00
2023-04-29 00:04:09 -04:00
[Service]
Type=simple
Update monitor-all.sh (#4437) ✅ Summary of Changes from the Initial Version 🧩 1. Tag-Based Filtering (Core Feature) New feature: Only restart instances (VMs or containers) that have the mon-restart tag. This makes monitoring and auto-restart controllable directly from the Proxmox Web UI, without editing scripts or services. Set via GUI: VM → Options → Tags → mon-restart Set via CLI: qm set <vmid> -tags mon-restart or pct set <ctid> -tags mon-restart This is the primary new control mechanism, making the script safer, more flexible, and user-friendly. 🧰 2. Backward-Compatible Exclusion Mechanism The original feature that lets you exclude instances via CLI arguments is preserved: bash Copy Edit ./ping-instances.sh 101 300 These IDs will always be skipped regardless of tag. 🧠 3. Intelligent Responsiveness Checks For VMs: Uses qm guest cmd <id> ping to check responsiveness via the QEMU guest agent. No longer relies on network-level ping, which can be misleading or blocked. For containers (CTs): Uses traditional ping to IP addresses obtained from pct exec, since CTs don’t support QEMU agent. ⛔ 4. Instance Skipping Improvements Instances are now skipped if: They are explicitly excluded via CLI. They are templates. They are configured with onboot: 0 or missing. They lack the mon-restart tag, regardless of other status. 🪵 5. Same Logging Behavior All output continues to go to /var/log/ping-instances.log for persistent tracking. Verbose messages were added for traceability (e.g., why a VM or CT was skipped). 🎯 Why This Matters With tag-based control, admins can now manage restart behavior dynamically from the Proxmox Web UI, making the script: More secure (no accidental restarts). More maintainable (no script edits needed). More user-friendly (integrated with the UI workflow).
2025-05-14 12:00:57 +03:00
# To exclude specific instances, pass IDs to ExecStart, e.g.:
# ExecStart=/usr/local/bin/ping-instances.sh 100 200
# Instances must also have the 'mon-restart' tag to be monitored
2023-10-14 12:31:06 -04:00
2023-04-29 00:04:09 -04:00
ExecStart=/usr/local/bin/ping-instances.sh
2023-10-14 12:45:48 -04:00
Restart=always
2023-04-29 00:04:09 -04:00
StandardOutput=file:/var/log/ping-instances.log
StandardError=file:/var/log/ping-instances.log
[Install]
2023-10-14 12:31:06 -04:00
WantedBy=multi-user.target
EOF
2023-04-29 00:04:09 -04:00
systemctl daemon-reload
systemctl enable -q --now ping-instances.timer
systemctl enable -q --now ping-instances.service
clear
Update monitor-all.sh (#4437) ✅ Summary of Changes from the Initial Version 🧩 1. Tag-Based Filtering (Core Feature) New feature: Only restart instances (VMs or containers) that have the mon-restart tag. This makes monitoring and auto-restart controllable directly from the Proxmox Web UI, without editing scripts or services. Set via GUI: VM → Options → Tags → mon-restart Set via CLI: qm set <vmid> -tags mon-restart or pct set <ctid> -tags mon-restart This is the primary new control mechanism, making the script safer, more flexible, and user-friendly. 🧰 2. Backward-Compatible Exclusion Mechanism The original feature that lets you exclude instances via CLI arguments is preserved: bash Copy Edit ./ping-instances.sh 101 300 These IDs will always be skipped regardless of tag. 🧠 3. Intelligent Responsiveness Checks For VMs: Uses qm guest cmd <id> ping to check responsiveness via the QEMU guest agent. No longer relies on network-level ping, which can be misleading or blocked. For containers (CTs): Uses traditional ping to IP addresses obtained from pct exec, since CTs don’t support QEMU agent. ⛔ 4. Instance Skipping Improvements Instances are now skipped if: They are explicitly excluded via CLI. They are templates. They are configured with onboot: 0 or missing. They lack the mon-restart tag, regardless of other status. 🪵 5. Same Logging Behavior All output continues to go to /var/log/ping-instances.log for persistent tracking. Verbose messages were added for traceability (e.g., why a VM or CT was skipped). 🎯 Why This Matters With tag-based control, admins can now manage restart behavior dynamically from the Proxmox Web UI, making the script: More secure (no accidental restarts). More maintainable (no script edits needed). More user-friendly (integrated with the UI workflow).
2025-05-14 12:00:57 +03:00
echo -e "\n Monitor All installed."
echo "📄 To view logs: cat /var/log/ping-instances.log"
echo "⚙️ Make sure your VMs or containers have the 'mon-restart' tag to be monitored."
2023-04-29 00:04:09 -04:00
}
remove() {
2023-10-14 12:31:06 -04:00
systemctl disable -q --now ping-instances.timer
systemctl disable -q --now ping-instances.service
Update monitor-all.sh (#4437) ✅ Summary of Changes from the Initial Version 🧩 1. Tag-Based Filtering (Core Feature) New feature: Only restart instances (VMs or containers) that have the mon-restart tag. This makes monitoring and auto-restart controllable directly from the Proxmox Web UI, without editing scripts or services. Set via GUI: VM → Options → Tags → mon-restart Set via CLI: qm set <vmid> -tags mon-restart or pct set <ctid> -tags mon-restart This is the primary new control mechanism, making the script safer, more flexible, and user-friendly. 🧰 2. Backward-Compatible Exclusion Mechanism The original feature that lets you exclude instances via CLI arguments is preserved: bash Copy Edit ./ping-instances.sh 101 300 These IDs will always be skipped regardless of tag. 🧠 3. Intelligent Responsiveness Checks For VMs: Uses qm guest cmd <id> ping to check responsiveness via the QEMU guest agent. No longer relies on network-level ping, which can be misleading or blocked. For containers (CTs): Uses traditional ping to IP addresses obtained from pct exec, since CTs don’t support QEMU agent. ⛔ 4. Instance Skipping Improvements Instances are now skipped if: They are explicitly excluded via CLI. They are templates. They are configured with onboot: 0 or missing. They lack the mon-restart tag, regardless of other status. 🪵 5. Same Logging Behavior All output continues to go to /var/log/ping-instances.log for persistent tracking. Verbose messages were added for traceability (e.g., why a VM or CT was skipped). 🎯 Why This Matters With tag-based control, admins can now manage restart behavior dynamically from the Proxmox Web UI, making the script: More secure (no accidental restarts). More maintainable (no script edits needed). More user-friendly (integrated with the UI workflow).
2025-05-14 12:00:57 +03:00
rm -f /etc/systemd/system/ping-instances.service
rm -f /etc/systemd/system/ping-instances.timer
rm -f /usr/local/bin/ping-instances.sh
rm -f /var/log/ping-instances.log
echo "Monitor All removed from Proxmox VE"
2023-04-29 00:04:09 -04:00
}
OPTIONS=(Add "Add Monitor-All to Proxmox VE"
Remove "Remove Monitor-All from Proxmox VE")
2023-05-06 07:30:41 -04:00
2023-09-09 05:13:17 -04:00
CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "Monitor-All for Proxmox VE" --menu "Select an option:" 10 58 2 \
"${OPTIONS[@]}" 3>&1 1>&2 2>&3)
2023-05-06 07:30:41 -04:00
case $CHOICE in
Update monitor-all.sh (#4437) ✅ Summary of Changes from the Initial Version 🧩 1. Tag-Based Filtering (Core Feature) New feature: Only restart instances (VMs or containers) that have the mon-restart tag. This makes monitoring and auto-restart controllable directly from the Proxmox Web UI, without editing scripts or services. Set via GUI: VM → Options → Tags → mon-restart Set via CLI: qm set <vmid> -tags mon-restart or pct set <ctid> -tags mon-restart This is the primary new control mechanism, making the script safer, more flexible, and user-friendly. 🧰 2. Backward-Compatible Exclusion Mechanism The original feature that lets you exclude instances via CLI arguments is preserved: bash Copy Edit ./ping-instances.sh 101 300 These IDs will always be skipped regardless of tag. 🧠 3. Intelligent Responsiveness Checks For VMs: Uses qm guest cmd <id> ping to check responsiveness via the QEMU guest agent. No longer relies on network-level ping, which can be misleading or blocked. For containers (CTs): Uses traditional ping to IP addresses obtained from pct exec, since CTs don’t support QEMU agent. ⛔ 4. Instance Skipping Improvements Instances are now skipped if: They are explicitly excluded via CLI. They are templates. They are configured with onboot: 0 or missing. They lack the mon-restart tag, regardless of other status. 🪵 5. Same Logging Behavior All output continues to go to /var/log/ping-instances.log for persistent tracking. Verbose messages were added for traceability (e.g., why a VM or CT was skipped). 🎯 Why This Matters With tag-based control, admins can now manage restart behavior dynamically from the Proxmox Web UI, making the script: More secure (no accidental restarts). More maintainable (no script edits needed). More user-friendly (integrated with the UI workflow).
2025-05-14 12:00:57 +03:00
"Add") add ;;
"Remove") remove ;;
*) echo "Exiting..."; exit 0 ;;
2023-05-06 07:30:41 -04:00
esac