From 7724546b6f3fac39f3231a9c8a029e3b75cd4747 Mon Sep 17 00:00:00 2001 From: tteckster Date: Sat, 14 Oct 2023 12:31:06 -0400 Subject: [PATCH] Update monitor-all.sh code refactoring --- misc/monitor-all.sh | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/misc/monitor-all.sh b/misc/monitor-all.sh index 0067ca90..b5567b8e 100644 --- a/misc/monitor-all.sh +++ b/misc/monitor-all.sh @@ -88,43 +88,54 @@ while true; do # Wait for 5 minutes. (Edit to your needs) echo "$(date): Pausing for 5 minutes..." sleep 300 -done >> /var/log/ping-instances.log 2>&1' >/usr/local/bin/ping-instances.sh - +done >/var/log/ping-instances.log 2>&1' >/usr/local/bin/ping-instances.sh +touch /var/log/ping-instances.log # Change file permissions to executable chmod +x /usr/local/bin/ping-instances.sh +cat </etc/systemd/system/ping-instances.timer +[Unit] +Description=Delay ping-instances.service by 5 minutes + +[Timer] +OnBootSec=300 +OnUnitActiveSec=300 + +[Install] +WantedBy=timers.target +EOF # Create ping-instances.service -echo '[Unit] +cat </etc/systemd/system/ping-instances.service +[Unit] Description=Ping instances every 5 minutes and restarts if necessary - +After=ping-instances.timer +Requires=ping-instances.timer [Service] Type=simple # To specify which CT/VM should be excluded, add the CT/VM ID at the end of the line where ExecStart=/usr/local/bin/ping-instances.sh is specified. # For example: ExecStart=/usr/local/bin/ping-instances.sh 100 102 # Virtual machines without the QEMU guest agent installed must be excluded. -# Sleep for 300 seconds (5 minutes) -# ExecStartPre=/usr/bin/sleep 300 + ExecStart=/usr/local/bin/ping-instances.sh -Restart=always StandardOutput=file:/var/log/ping-instances.log StandardError=file:/var/log/ping-instances.log [Install] -WantedBy=multi-user.target' >/etc/systemd/system/ping-instances.service +WantedBy=multi-user.target +EOF # Reload daemon, enable and start ping-instances.service systemctl daemon-reload +systemctl enable -q --now ping-instances.timer systemctl enable -q --now ping-instances.service clear echo -e "\n To view Monitor All logs: cat /var/log/ping-instances.log" } remove() { - systemctl stop ping-instances.service - systemctl disable ping-instances.service &>/dev/null - rm /etc/systemd/system/ping-instances.service - rm /usr/local/bin/ping-instances.sh - rm /var/log/ping-instances.log + systemctl disable -q --now ping-instances.timer + systemctl disable -q --now ping-instances.service + rm /etc/systemd/system/ping-instances.service /etc/systemd/system/ping-instances.timer /usr/local/bin/ping-instances.sh /var/log/ping-instances.log echo "Removed Monitor All from Proxmox VE" }