Nouvelle version de check avec support de lanceur dans un tableau associatif
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@425 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
51
check
51
check
@@ -56,15 +56,30 @@ function checklog()
|
||||
fi
|
||||
}
|
||||
|
||||
function chercheLanceur()
|
||||
{
|
||||
# Cette fonction renvoie le lanceur du programme passé en paramètre
|
||||
# On peut définir un tableau supplémentaire dans le fichier de configuration
|
||||
# Si le lanceur n'est pas défini dans le tableau, on renvoie le nom du
|
||||
# processus
|
||||
processus=$1
|
||||
if [ -z ${lanceur["$processus"]} ]; then
|
||||
echo "$processus"
|
||||
else
|
||||
echo ${lanceur["$processus"]}
|
||||
fi
|
||||
}
|
||||
|
||||
function testps()
|
||||
{
|
||||
if [ ! -e "/etc/init.d/$1" ]; then
|
||||
echo "ERREUR : /etc/init.d/$1 introuvable (testps)"
|
||||
lanceur=`chercheLanceur "$1"`
|
||||
if [ ! -e "/etc/init.d/$lanceur" ]; then
|
||||
echo "ERREUR : /etc/init.d/$lanceur introuvable (testps)"
|
||||
else
|
||||
if [ `ps -edf | grep -v grep | grep "$*" | wc -l` -eq 0 ]; then
|
||||
checklog "Relance de '$*'"
|
||||
/etc/init.d/$1 stop
|
||||
/etc/init.d/$1 start
|
||||
checklog "Relance de '$*' par /etc/init.d/$lanceur"
|
||||
/etc/init.d/$lanceur stop
|
||||
/etc/init.d/$lanceur start
|
||||
fi
|
||||
fi
|
||||
}
|
||||
@@ -72,13 +87,14 @@ function testps()
|
||||
function testpsStrict()
|
||||
{
|
||||
# On rend le test plus strict en mettant un slash devant le nom du demon
|
||||
if [ ! -e "/etc/init.d/$1" ]; then
|
||||
echo "ERREUR : /etc/init.d/$1 introuvable (testpsStrict) "
|
||||
lanceur=`chercheLanceur "$1"`
|
||||
if [ ! -e "/etc/init.d/$lanceur" ]; then
|
||||
echo "ERREUR : /etc/init.d/$lanceur introuvable (testpsStrict) "
|
||||
else
|
||||
if [ `ps -edf | grep -v grep | grep "/$*" | wc -l` -eq 0 ]; then
|
||||
checklog "Relance de '$*'"
|
||||
/etc/init.d/$1 stop
|
||||
/etc/init.d/$1 start
|
||||
checklog "Relance de '$*' par /etc/init.d/$lanceur"
|
||||
/etc/init.d/$lanceur stop
|
||||
/etc/init.d/$lanceur start
|
||||
fi
|
||||
fi
|
||||
}
|
||||
@@ -179,8 +195,8 @@ function testDDClient()
|
||||
# une ligne 'ddclient - sleeping for'. Si ce n'est pas le cas (test en cours)
|
||||
# on attend 15 s et on refait le test. Si le test est toujours negatif on
|
||||
# relance.
|
||||
if [ ! -e "/etc/init.d/$3" ]; then
|
||||
echo "ERREUR : /etc/init.d/$3 introuvable (testDDClient)"
|
||||
if [ ! -e "/etc/init.d/ddclient" ]; then
|
||||
echo "ERREUR : /etc/init.d/ddclient introuvable (testDDClient)"
|
||||
else
|
||||
LIGNE1=`ps -edf | grep -v grep | egrep "ddclient "`
|
||||
LIGNE2=`echo $LIGNE1 | egrep 'ddclient - sleeping for|ddclient - (connecting to|reading from) checkip.dyndns.com port 80'`
|
||||
@@ -247,6 +263,17 @@ if [ ! -f "/etc/check.conf" ]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
# Lanceur est le tableau associatif des lanceurs 'processus'=>'lanceur' dans
|
||||
# /etc/init.d
|
||||
# On peut définir des lanceurs dans la fonction chercheLanceur, ou dans le
|
||||
# fichier de configuration /etc/check.conf. Si on redéfinit un lanceur dans
|
||||
# /etc/check.conf, c'est lui qui est prioritaire par rapport à ceux codés en dur
|
||||
declare -A lanceur
|
||||
lanceur[ntpd]="ntp"
|
||||
lanceur[bind]="bind9"
|
||||
lanceur[rsyslogd]="rsyslog"
|
||||
lanceur[sshd]="ssh"
|
||||
|
||||
. /etc/check.conf
|
||||
|
||||
if [ "$alerteNotify" == "TRUE" ] && [ ! -f "/usr/bin/notify-send" ]; then
|
||||
|
||||
Reference in New Issue
Block a user