stable #2

Merged
alientim merged 89 commits from stable into dev 2024-11-15 10:37:11 +01:00
Showing only changes of commit 63a40835b6 - Show all commits

View File

@@ -11,8 +11,9 @@ update_watchdog_config() {
# Extract watchdog IP addresses # Extract watchdog IP addresses
watchdog=$(sudo cat /var/lib/dhcp/* | grep -a "option watchdog" | tail -1 | \ watchdog=$(sudo cat /var/lib/dhcp/* | grep -a "option watchdog" | tail -1 | \
awk '{for (i=3; i<=NF; i++) printf "%s ", $i}' | tr -d '";') awk '{for (i=3; i<=NF; i++) printf "%s ", $i}' | tr -d '";')
IFS=' ' read -r -a ip_array <<< "$watchdog" # Split the watchdog IPs into an array
IFS=',' read -r -a ip_array <<< "$watchdog"
# Backup current configuration # Backup current configuration
if sudo cp "$config_file" "$config_file.bak"; then if sudo cp "$config_file" "$config_file.bak"; then
@@ -28,27 +29,27 @@ update_watchdog_config() {
# Set interval # Set interval
echo "interval = 59" | sudo tee -a "$config_file" > /dev/null echo "interval = 59" | sudo tee -a "$config_file" > /dev/null
if [ ${#ip_array[@]} -eq 0 ]; then # Check if IP addresses are found and add them to the config
echo "No IP addresses found. Watchdog configuration cleared." >> "$log_file" if [ ${#ip_array[@]} -gt 0 ]; then
else
for ip in "${ip_array[@]}"; do for ip in "${ip_array[@]}"; do
echo "ping = $ip" | sudo tee -a "$config_file" > /dev/null echo "ping = $ip" | sudo tee -a "$config_file" > /dev/null
echo "Configured watchdog to ping: $ip" >> "$log_file"
done done
echo "Configured watchdog to ping: ${ip_array[*]}" >> "$log_file"
# Restart watchdog service since IP addresses were found # Restart watchdog service since IP addresses were found
if sudo systemctl restart watchdog; then if sudo systemctl restart watchdog; then
echo "Watchdog service restarted successfully." >> "$log_file" echo "Watchdog service restarted successfully." >> "$log_file"
else else
echo "Failed to restart watchdog service." >> "$log_file" echo "Failed to restart watchdog service." >> "$log_file"
fi fi
return 1 # Indicate that IP addresses were found return 1 # Indicate that IP addresses were found
fi fi
echo "No IP addresses found. Watchdog configuration cleared." >> "$log_file"
return 0 # Indicate that no IP addresses were found return 0 # Indicate that no IP addresses were found
} }
# Main loop # Main loop
start_time=$(date +%s) start_time=$(date +%s)
end_time=$((start_time + 300)) # 5 minutes in seconds end_time=$((start_time + 300)) # 5 minutes in seconds