Score:0

Improving script to check site response and restart the server

hu flag

Any suggestions how I can improve this script. We are receiving 200 response but server is doesn't always restart

#!/bin/bash

if [[ $EUID -ne 0 ]]; then
        echo "This script must be run as root"
        exit 1
fi

if [[ -f /etc/maintenance ]]; then
        echo "In Maintenance Mode : Skip operation"
        exit 0
fi

if [[ $(curl -m 2 -s -o /dev/null -w "%{http_code}" http://127.0.0.1:8080/statusCheck.page) -ne '200' ]]; then
        echo "[$(date)](server20) : Server Down!" >> /etc/check.log
        THISTIME=`date +%s`
        if [[ ! -f /etc/LAST_DOWN20.chk ]]; then
                echo $(date) > /etc/LAST_DOWN20.chk
        fi

        TIMESTRING=`cat /etc/LAST_DOWN20.chk`
        LASTTIME=`date +%s -d "${TIMESTRING}"`

        if [[ -f /etc//LAST_RESTART20.chk ]]; then
                TIMESTRING=`cat /etc/LAST_RESTART20.chk`
                LASTRESTART=`date +%s -d "${TIMESTRING}"`
        else
                LASTRESTART=$THISTIME
        fi

        ELAPSED=`expr "${THISTIME}" - "${LASTTIME}"`

        if [ "$ELAPSED" -gt 120 ]; then
                if [[ -f /etc/LAST_RESTART20.chk ]]; then
                        TIMESTRING=`cat /etc/LAST_RESTART20.chk`
                        LASTRESTART=`date +%s -d "${TIMESTRING}"`
                else
                        LASTRESTART="0"
                fi

                ELAPSED=`expr "${THISTIME}" - "${LASTRESTART}"`

                if [ "$ELAPSED" -gt 300 ]; then
                        echo $(date) > /etc/LAST_RESTART20.chk
                        touch /etc//maintenance
                        /etc//dump_server20.sh
                        /etc//force_kill_server20.sh
                        rm /etc//maintenance
                        echo "[$(date)](server20) : Server Restart!" >> /etc/check.log
                fi
        fi
else
        if [[ -f /etc/LAST_DOWN20.chk ]]; then
                rm /etc/LAST_DOWN20.chk
        fi
        echo "[$(date)](server20) : Server OK!" >> /etc//check.log
fi
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.