Restart service only if it's managed
This commit is contained in:
parent
18e60cc89e
commit
4c8645288c
|
@ -45,17 +45,19 @@ debug_stdout="${temp_dir}/debug.stdout"
|
||||||
service_list="${temp_dir}/services.error.list"
|
service_list="${temp_dir}/services.error.list"
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
# Temp dir for this alert
|
# Temp dir for this alert {{{
|
||||||
if [ ! -d "${temp_dir}" ] ; then
|
if [ ! -d "${temp_dir}" ] ; then
|
||||||
mkdir -p -- "${temp_dir}"
|
mkdir -p -- "${temp_dir}"
|
||||||
fi
|
fi
|
||||||
|
# }}}
|
||||||
|
|
||||||
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : ${BBHOSTNAME} — ${BBSVCNAME} error" > "${debug_stdout}"
|
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : ${BBHOSTNAME} — ${BBSVCNAME} error" > "${debug_stdout}"
|
||||||
|
|
||||||
# Check if host need to reboot
|
# Check if host need to reboot {{{
|
||||||
if echo "${BBALPHAMSG}" | grep -qE "\\&yellow Machine should be reboot.*" ; then
|
if echo "${BBALPHAMSG}" | grep -qE "\\&yellow Machine should be reboot.*" ; then
|
||||||
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Test kernel — The host need to be rebooted." >> "${debug_stdout}"
|
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Test kernel — The host need to be rebooted." >> "${debug_stdout}"
|
||||||
fi
|
fi
|
||||||
|
# }}}
|
||||||
|
|
||||||
# Check if a service need to restart
|
# Check if a service need to restart
|
||||||
if echo "${BBALPHAMSG}" | grep -qE "\\&yellow The following processes.*" ; then
|
if echo "${BBALPHAMSG}" | grep -qE "\\&yellow The following processes.*" ; then
|
||||||
|
@ -69,46 +71,53 @@ if echo "${BBALPHAMSG}" | grep -qE "\\&yellow The following processes.*" ; then
|
||||||
case "${bin_path}" in
|
case "${bin_path}" in
|
||||||
# Arpwatch
|
# Arpwatch
|
||||||
'/usr/sbin/arpwatch' )
|
'/usr/sbin/arpwatch' )
|
||||||
process="arpwatch"
|
service_name="arpwatch"
|
||||||
;;
|
;;
|
||||||
# Dbus
|
# Dbus
|
||||||
'/usr/bin/dbus-daemon' )
|
'/usr/bin/dbus-daemon' )
|
||||||
process="dbus"
|
service_name="dbus"
|
||||||
;;
|
;;
|
||||||
# Postfix
|
# Postfix
|
||||||
'/usr/lib/postfix/sbin/pickup' | '/usr/lib/postfix/qmgr' | '/usr/lib/postfix/sbin/tlsmgr' )
|
'/usr/lib/postfix/sbin/pickup' | '/usr/lib/postfix/qmgr' | '/usr/lib/postfix/sbin/tlsmgr' )
|
||||||
process="postfix"
|
service_name="postfix"
|
||||||
;;
|
;;
|
||||||
# Nginx
|
# Nginx
|
||||||
'/usr/sbin/nginx' )
|
'/usr/sbin/nginx' )
|
||||||
process="nginx"
|
service_name="nginx"
|
||||||
;;
|
;;
|
||||||
# Ntp
|
# Ntp
|
||||||
'/usr/sbin/ntpd' )
|
'/usr/sbin/ntpd' )
|
||||||
process="ntp"
|
service_name="ntp"
|
||||||
;;
|
;;
|
||||||
# Systemd-journald
|
# Systemd-journald
|
||||||
'/lib/systemd/systemd-journald' )
|
'/lib/systemd/systemd-journald' )
|
||||||
process="systemd-journald"
|
service_name="systemd-journald"
|
||||||
;;
|
;;
|
||||||
# Systemd-logind
|
# Systemd-logind
|
||||||
'/lib/systemd/systemd-logind' )
|
'/lib/systemd/systemd-logind' )
|
||||||
process="systemd-logind"
|
service_name="systemd-logind"
|
||||||
;;
|
;;
|
||||||
# default
|
# default
|
||||||
* )
|
* )
|
||||||
process="NOT.MANAGED"
|
service_name="NOT.MANAGED"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : while bin_path loop — ${process} need to be restarted." >> "${debug_stdout}"
|
# Restart service if managed {{{
|
||||||
[ "${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 ${process}.service" >> "${debug_stdout}"
|
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} 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 ${REMOTE_SSH_USER}@${BBHOSTNAME} sudo systemctl restart ${service_name}.service" >> "${debug_stdout}"
|
||||||
|
fi
|
||||||
|
# }}}
|
||||||
done < "${service_list}"
|
done < "${service_list}"
|
||||||
|
|
||||||
# Also restart xymon-client service
|
# Also restart xymon-client service {{{
|
||||||
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Test service — xymon-client also need to be restarted." >> "${debug_stdout}"
|
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Test service — xymon-client also need to be restarted." >> "${debug_stdout}"
|
||||||
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Test service — ssh -o StrictHostKeyChecking=no ${REMOTE_SSH_USER}@${BBHOSTNAME} sudo systemctl restart xymon-client.service" >> "${debug_stdout}"
|
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Test service — ssh -o StrictHostKeyChecking=no ${REMOTE_SSH_USER}@${BBHOSTNAME} sudo systemctl restart xymon-client.service" >> "${debug_stdout}"
|
||||||
|
# }}}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ "${DEBUG}" -eq "0" ] || rm -rf -- "${temp_dir}"
|
[ "${DEBUG}" -eq "0" ] || rm -rf -- "${temp_dir}"
|
||||||
|
|
Loading…
Reference in New Issue