From 43d6e0ef553760e947429a8438ea08c3d2f66a7f Mon Sep 17 00:00:00 2001 From: Christoph Date: Wed, 6 Jul 2022 22:17:59 +0200 Subject: [PATCH] check_local_mattermost_service.sh: repair code. --- check_local_mattermost_service.sh | 105 +++++++++++++++++------------- 1 file changed, 58 insertions(+), 47 deletions(-) diff --git a/check_local_mattermost_service.sh b/check_local_mattermost_service.sh index f73b484..af71002 100755 --- a/check_local_mattermost_service.sh +++ b/check_local_mattermost_service.sh @@ -420,8 +420,6 @@ if [[ ${#LOG_FILES_TO_MONITOR} -gt 0 ]] ; then else msg_user_defined="${msg_user_defined}\n---\nLast entries (${_number_lines} lines) of \"${_log_file}\":\n---\n-- FILE IS EMPTY --\n" fi - done - fi done msg_user_defined="${msg_user_defined}\n\n" else @@ -549,6 +547,64 @@ if $NGINX_SERVICE_DOWN ; then declare -i counter=0 PID="$(ps aux | grep -E "[[:digit:]]\s+nginx:" | grep -v grep | tail -n 1 | awk '{print$2}' 2> /dev/null)" + sleep 1 + while [[ "X${PID}" = "X" ]]; do + sleep 1 + PID="$(ps aux | grep -E "[[:digit:]]\s+nginx:" | grep -v grep | tail -n 1 | awk '{print$2}' 2> /dev/null)" + if [[ $counter -gt 10 ]]; then + break + else + ((counter++)) + fi + done + + if [[ "X${PID}" = "X" ]] ; then + error "Restarting NGINX Service failed!" + + err_msg="${err_msg}\n[ Error ]: Restarting NGINX Service failed!" + + else + ok "NGINX Service is up and running" + + err_msg="${err_msg}\n[ OK ]: NGINX Service is up and running" + fi + +fi + +if $MM_SERVICE_DOWN; then + error "Mattermost Service seems to be down. Going to restart Service.." + + if [[ -n "$err_msg" ]]; then + err_msg="${err_msg}\n\n\n[ Error ]: Mattermost Service seems to be down. + + Going to restart Mattermost Service Service\n" + else + err_msg="\n[ Error ]: Mattermost Service seems to be down. + + Going to restart Mattermost Service Service\n" + fi + + echononl "Stop mattwermost Service.." + $systemctl stop mattermost > /dev/null 2> ${LOCK_DIR}/error.log + if [[ $? -ne 0 ]]; then + echo_failed + error "$(cat ${LOCK_DIR}/error.log)" + else + echo_done + fi + + declare -i counter=0 + PID="$(ps aux | grep -E "[[:digit:]]\s+/opt/mattermost/bin/mattermost" | grep -v grep | tail -n 1 | awk '{print$2}' 2> /dev/null)" + + while [[ -n "$PID" ]] ; do + + if [[ $counter -gt 3 ]] ; then + break + fatal "Killing remaining mattermost Process(es) failed!" + fi + + warn "There are still mattermost processes running" + ((counter++)) echononl "${counter}: Kill remaining mattermost Process(es).." @@ -598,51 +654,6 @@ if $NGINX_SERVICE_DOWN ; then fi - - -if [[ ! -f "$RESTART_CHECK_FILE" ]]; then - - touch "$RESTART_CHECK_FILE" - - error "The local Mattermost Service seems to be down." - err_msg="\n[ Warning ]: The local Mattermost Service seems to be down.\n" - err_msg="${err_msg}\nFor now nothing is to. because its the first time..\n" - - datum="$(date +"%d.%m.%Y %H:%M")" - - for _email in ${alert_email_arr[@]} ; do - - echo -e "To:${_email}\n${content_type}\nSubject:[Warning] Local Mattermost Service is not available.\n${err_msg}\n\nFilesystem usage:\n=================\n$(df -h)\n\n${msg_process_list}\n\n${msg_user_defined}\n${msg}" \ - | sendmail -F "Error `hostname -f`" -f $sender_address $_email - done - -else - - error "The local Mattermost Service seems to be down." - err_msg="\n[ Warning ]: The local Mattermost Service seems to be down.\n" - - if $LOGGING ; then - echo -e "\n\033[1mGoing to restart the system NOW..\033[m" - else - echo "" - echo "Going to restart the system NOW.." - fi - - err_msg="${err_msg}\nGoing to restart the system..\n" - - datum="$(date +"%d.%m.%Y %H:%M")" - - for _email in ${alert_email_arr[@]} ; do - - echo -e "To:${_email}\n${content_type}\nSubject:[Error] Local Mattermost Service is not available.\n$err_msg\n\nFilesystem usage:\n=================\n$(df -h)\n\n${msg_process_list}\n\n${msg_user_defined}\n${msg}" \ - | sendmail -F "Error `hostname -f`" -f $sender_address $_email - done - - rm -f "$RESTART_CHECK_FILE" - reboot_system - -fi - if $LOGGING ; then echo ""