diff --git a/usr/bin/custom/watchdog-monitor b/usr/bin/custom/watchdog-monitor index a7e9d63..3797fe1 100644 --- a/usr/bin/custom/watchdog-monitor +++ b/usr/bin/custom/watchdog-monitor @@ -43,22 +43,30 @@ update_watchdog_config() { done log "Configured watchdog to ping: ${ip_array[*]}" - # Restart watchdog service - if sudo systemctl restart watchdog; then - log "Watchdog service restarted successfully." + # Attempt to restart watchdog service + if ! sudo systemctl restart watchdog; then + log "Failed to restart watchdog service. Attempting to stop and start." - # Stop watchdog-monitor service - if sudo systemctl stop watchdog-monitor; then - log "watchdog-monitor service stopped successfully." + # Fallback: stop then start the service + sudo systemctl stop watchdog + if sudo systemctl start watchdog; then + log "Watchdog service started successfully after stop." else - log "Failed to stop watchdog-monitor service." + log "Failed to start watchdog service after stop." + return 1 fi - - return 0 # Successful restart else - log "Failed to restart watchdog service." - return 1 # Failed restart + log "Watchdog service restarted successfully." fi + + # Stop watchdog-monitor service if restart/start was successful + if sudo systemctl stop watchdog-monitor; then + log "watchdog-monitor service stopped successfully." + else + log "Failed to stop watchdog-monitor service." + fi + + return 0 # Successful restart/start fi }