28

Script per riavviare Apache nel caso in cui smetta di funzionare

ottobre 2008 da Lobotomia

1 Stella2 Stelle3 Stelle4 Stelle5 Stelle6 Stelle7 Stelle8 Stelle9 Stelle10 Stelle (2 voti, media: 10,00 su un massimo di 10)
Loading ... Loading ...

Può capitare che smetta di funzionare, vi proponiamo uno script per riavviare in automatico il servizio nel caso non risponda più.

Lo script utilizza netcat e fa una richiesta di tipo GET per controllare che tutto sia apposto, per cui funzionerà anche nel caso in cui il processo esiste ancora ma non risponde più alle connessioni esterne:

#!/bin/bash

RESTARTS=0
COUNT=0
MAXCOUNT=3
INTERVAL=60
PORT=80

while [ 1 ]
do
echo -e “GET / HTTP/1.0\n\n” | nc localhost $PORT > /dev/null
if [ "$?" != "0" ]
then
COUNT=$(($COUNT+1))
echo -n “ is down! Already seen down $COUNT times”
echo “, Restart after $MAXCOUNT times”
if [ "$COUNT" == "$MAXCOUNT" ]
then
echo “*** RESTARTING ***”
COUNT=0
RESTARTS=$(($RESTARTS+1))
/etc/init.d/apache2 restart
fi
else
COUNT=0
echo -n “ is OK, next poll in $INTERVAL seconds”
echo “, Restarts so far $RESTARTS”
fi
sleep $INTERVAL
done

[via zzimma]

Post correlati

2 Risposte a “Script per riavviare Apache nel caso in cui smetta di funzionare”

  1. Gipo said:

    Wow ottimo… non è che magari hai anche una guida di come installarlo ?

  2. Lobotomia said:

    @Gipo: ti basta metterlo in cron :)

Leave a Reply

XHTML: Puoi usare questi tag: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>