usr/bin/custom/watchdog-monitor aktualisiert
This commit is contained in:
@@ -26,7 +26,7 @@ update_watchdog_config() {
|
|||||||
|
|
||||||
if [ ${#ip_array[@]} -eq 0 ]; then
|
if [ ${#ip_array[@]} -eq 0 ]; then
|
||||||
echo "No IP addresses found. Watchdog configuration cleared." >> "$log_file"
|
echo "No IP addresses found. Watchdog configuration cleared." >> "$log_file"
|
||||||
return 0 # No IP addresses to configure
|
return 1 # No IP addresses to configure, return 1 to continue loop
|
||||||
else
|
else
|
||||||
# Insert IPs into config
|
# Insert IPs into config
|
||||||
for ip in "${ip_array[@]}"; do
|
for ip in "${ip_array[@]}"; do
|
||||||
@@ -35,26 +35,37 @@ update_watchdog_config() {
|
|||||||
echo "Configured watchdog to ping: ${ip_array[*]}" >> "$log_file"
|
echo "Configured watchdog to ping: ${ip_array[*]}" >> "$log_file"
|
||||||
|
|
||||||
# Restart watchdog service
|
# Restart watchdog service
|
||||||
sudo systemctl restart watchdog
|
if sudo systemctl restart watchdog; then
|
||||||
return 1 # IP addresses were configured
|
echo "Watchdog service restarted successfully." >> "$log_file"
|
||||||
|
return 0 # Successful restart, exit function with 0 to break main loop
|
||||||
|
else
|
||||||
|
echo "Failed to restart watchdog service." >> "$log_file"
|
||||||
|
return 1 # Failed restart, continue main loop
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Loop parameters
|
||||||
|
interval=30 # Interval to wait between checks
|
||||||
|
start_time=$(date +%s)
|
||||||
|
end_time=$((start_time + 300)) # 5 minutes in seconds
|
||||||
|
|
||||||
|
# Main loop
|
||||||
while true; do
|
while true; do
|
||||||
if update_watchdog_config; then
|
if ! update_watchdog_config; then
|
||||||
echo "IP addresses found and watchdog restarted. Exiting loop." >> "$log_file"
|
echo "IP addresses found and watchdog restarted. Exiting loop." >> "$log_file"
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
echo "No IP addresses found. Waiting for $interval seconds before checking again..." >> "$log_file"
|
echo "No IP addresses found or restart failed. Waiting for $interval seconds before checking again..." >> "$log_file"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check time limit
|
# Check if 5 minutes have passed
|
||||||
if [ "$(date +%s)" -ge "$end_time" ]; then
|
if [ "$(date +%s)" -ge "$end_time" ]; then
|
||||||
echo "5 minutes have passed. Stopping the watchdog service." >> "$log_file"
|
echo "5 minutes have passed. Stopping the watchdog service." >> "$log_file"
|
||||||
sudo systemctl stop watchdog
|
sudo systemctl stop watchdog
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Waiting for $interval seconds before checking for IP addresses again..." >> "$log_file"
|
echo "Waiting for $interval seconds before checking for IP addresses again..." >> "$log_file"
|
||||||
sleep $interval
|
sleep $interval
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user