From ad0fe278445584ccf9956ecb0ca60af04001df3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Tue, 21 Aug 2018 09:36:00 +0200 Subject: [PATCH] Avoid to restart more than once the same service --- xymon/xymon.libs.alert.sh | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/xymon/xymon.libs.alert.sh b/xymon/xymon.libs.alert.sh index 73a765f..656fbb7 100755 --- a/xymon/xymon.libs.alert.sh +++ b/xymon/xymon.libs.alert.sh @@ -99,13 +99,18 @@ if echo "${BBALPHAMSG}" | grep -qE "\\&yellow The following processes.*" ; then esac # }}} - # Restart service if managed {{{ - if [ "${service_name}" = "NOT.MANAGED" ]; then - [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : while bin_path loop — service for ${bin_path} is not managed." >> "${debug_stdout}" - else + # Restart service if needed {{{ + if [ "${service_name}" != "NOT.MANAGED" ] && [ "${service_name}" != "${previous_service_name}" ]; then [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : while bin_path loop — ${service_name} need to be restarted." >> "${debug_stdout}" - [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : while bin_path loop — ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${REMOTE_SSH_USER}@${BBHOSTNAME} sudo systemctl restart ${service_name}.service" >> "${debug_stdout}" - ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${REMOTE_SSH_USER}@${BBHOSTNAME} sudo systemctl restart ${service_name}.service >> "${debug_stdout}" 2>> "${debug_stderr}" + [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : while bin_path loop — ssh -o StrictHostKeyChecking=no ${REMOTE_SSH_USER}@${BBHOSTNAME} sudo systemctl restart ${service_name}.service" >> "${debug_stdout}" + ssh -o StrictHostKeyChecking=no ${REMOTE_SSH_USER}@${BBHOSTNAME} sudo systemctl restart ${service_name}.service >> "${debug_stdout}" 2>> "${debug_stderr}" + previous_service_name="${service_name}" + else + if [ "${service_name}" = "NOT.MANAGED" ]; then + [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : while bin_path loop — service for ${bin_path} is not managed." >> "${debug_stdout}" + else + [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : while bin_path loop — ${service_name} was already restarted." >> "${debug_stdout}" + fi fi # }}} done < "${service_list}"