Voici le code :
#!/bin/bash
#set -x
TOMCAT_PATH='/home/serverMiddle/@ENV@/tomcat1/logs/ccm'
ENVS=`cat /etc/motd`
for ENV in $ENVS
do
if [[ ("$ENV" == *wacd* && ( "$ENV" == *cgss* || "$ENV" == *cnav* || "$ENV" == *cram* )) ]]
then
#echo "chaine acceptee = [$ENV]"
stop_service $ENV";
sleep 5;
start_service $ENV";
sleep 5;
fi
done
Voici un exemple plus complet qui lit les fihcier de log et attend de trouver une chaine particuliere
#!/bin/bash
TOMCAT_PATH='/MIDDLE/cnav/ENV/tomcat1/logs'
ENVS=`cat /etc/motd`
NOM_FIC="`date +"%Y.%m.%d"`_SERVER.log"
DETECTION_ACD_STARTED="FIN APPEL SERVICE accesFileCounterrs"
DETECTION_TOMCAT_STARTED="FIN APPEL SERVICE accesFileCounterrs"
function isTomcatStarted()
{
TOMCAT_LOG_DIR=`echo "$1/stdout.log" | sed -e "s@ENV@$2@g"`
if [ -e "$TOMCAT_LOG_DIR" ]
then
while read line; do
case "$line" in
*"Ajp13Processor"*)
echo "Le server Tomcat [$2] est demarre => [$line]"
return 0;
break
;;
*)
;;
esac
done < $TOMCAT_LOG_DIR
else
echo "fichier [$TOMCAT_LOG_DIR] est introuvable"
fi
# cas erreur
return 1;
}
function isACDStarted()
{
WACD_LOG_DIR=`echo "$1/ccm/$NOM_FIC" | sed -e "s@ENV@$2@g"`
if [ -e "$WACD_LOG_DIR" ]
then
while read line; do
case "$line" in
*"Started"*)
echo "L'ACD [$2] est demarre => [$line]"
return 0;
break
;;
*)
;;
esac
done < $WACD_LOG_DIR
else
echo "fichier [$WACD_LOG_DIR] est introuvable"
fi
# cas erreur
return 1;
}
function AR()
{
echo "stop_service $ENV";
sleep 2
echo "start_service $ENV";
isACDStarted $TOMCAT_PATH $ENV
isACDOK=$?
isTomcatStarted $TOMCAT_PATH $ENV
isTomcatOK=$?
if [[ ("$isACDOK" -eq 1 || "$isTomcatStarted" -eq 1) ]]
then
echo "erreur lors du demarrage"
echo "isACDOK =[$isACDOK]"
echo "isTomcatOK=[$isTomcatOK]"
fi
}
for ENV in $ENVS
do
if [[ ("$ENV" == *wacd* && ( "$ENV" == *cgss* || "$ENV" == *cnav* || "$ENV" == *cram* )) ]]
then
AR $ENV
if [ "$?" -eq 0 ]
then
echo "isStarted OK"
else
echo "isStarted KO"
fi
fi
done
Aucun commentaire:
Enregistrer un commentaire