Script Shell qui ne démarre pas toutes les commandes

Signaler
Messages postés
157
Date d'inscription
vendredi 24 mai 2013
Statut
Membre
Dernière intervention
8 avril 2020
-
Messages postés
157
Date d'inscription
vendredi 24 mai 2013
Statut
Membre
Dernière intervention
8 avril 2020
-
Bonjour
J'ai un script shell , qui doit vérifier si des services sont démarrés , sinon il les démarre , le problème est que le script ne démarre que les deux premiers services, et ignore les autres suivants , est-ce-que quelqu'un pourrait me dire pourquoi ??

voici le script et le fichier config :
Script a executer:
 
\#!/bin/bash
 
#startService
#arg1 service path
#arg2 service command
#arg3 service args
startService(){
        echo "Starting......"
        echo $1
        echo $2
        echo $3
        cd ${1}
        eval ${2} ${3} &
        #cd -
        #Checking if the service is successfully started
        echo "Started!"
}
 
#Check service method
#arg1 the service configuration string
#arg2 the current node type A or P
checkService(){
        #echo $1
        #echo $2
        #Split the configuration string
        IFS=',' read -ra SERVICECONF <<< "$1"
        #Get Service PID
        PID=$(pgrep -f "${SERVICECONF[4]}")
        #echo ${SERVICECONF[1]}
        #echo $PID
        #Check if the serivce is running
        if [ -z $PID ];
        then
                echo "Service ${SERVICECONF[0]} is NOT running"
                #Check if the service is eligible to be started according to the service type and the node type
                #NODETYPE == A && service type == A-A (eligible)
                #NODETYPE == A && service type == A-P (eligible)
                #NODETYPE == P && service type == A-A (eligible)
                #NODETYPE == P && service type == A-P (NOT eligible)
                #echo +++++++++++++++
                #echo $2
                #echo ${SERVICECONF[4]}
                #echo +++++++++++++++
                if [ $2 = "A" -a ${SERVICECONF[5]} = "A-A" ] || \
                        [ $2 = "A" -a ${SERVICECONF[5]} = "A-P" ] || \
                        [ $2 = "P" -a ${SERVICECONF[5]} = "A-A" ]; then
                        echo "Service ${SERVICECONF[0]} is eligible to be restarted"
                        startService ${SERVICECONF[1]} ${SERVICECONF[2]} ${SERVICECONF[3]}
                else
                        echo "Service ${SERVICECONF[0]} is NOT eligible to be restarted"
                fi
        else
                echo "${SERVICECONF[0]} RUNNING"
		if  [ $2 = "P" -a ${SERVICECONF[5]} = "A-P" ]; then
                        echo "${SERVICECONF[0]} is Active-Passive server and shouldn't be running on a passive node"
                        echo "Killing ${SERVICECONF[0]}"
                        kill $PID
                fi
        fi
}
 
echo "Starting at $(date)"
#check the arguments
if [ "$#" -ne 1 ]; then
   echo "The argumants should have the path to the services configuration file only";
   exit;
fi
configFile=$1
IFS=''
servicesList=()
#Reading the config file lines into array
while read line; do
    configurationList+=($line)
done < $configFile
 
IFS='=' read -ra NODECONF <<< "${configurationList[0]}"
NODETYPE=${NODECONF[1]}
echo $NODETYPE
 
for ((i = 1; i < ${#configurationList[@]}; ++i)); do
        #echo $i
        echo -----------------------
        checkService ${configurationList[i]} ${NODETYPE}
done
echo "Done"


Fichier Config

 
NodeType=A
IOT spark job,/DATA/apps/ProcessDataSparkJob/,/DATA/apps/spark-2.3.1-bin-hadoop2.7/bin/spark-submit --class com.ocp.jfc2.iot.dataprocessor.IoTDataProcessor ProcessDataSparkJob.jar,iot.properties &> /DATA/apps/ProcessDataSparkJob/iot_run.log &,com.ocp.jfc2.iot.dataprocessor.IoTDataProcessor,A-P
Plant spark job,/DATA/apps/ProcessDataSparkJob/,/DATA/apps/spark-2.3.1-bin-hadoop2.7/bin/spark-submit --class com.ocp.jfc2.plant.dataprocessor.PlantDataProcessor ProcessDataSparkJob.jar,ProcessAndFilterDataJobs_plant.properties &> /DATA/apps/ProcessDataSparkJob/plant_run.log &,com.ocp.jfc2.plant.dataprocessor.PlantDataProcessor,A-P
JFC4 spark job,/DATA/apps/ProcessDataSparkJob/,/DATA/apps/spark-2.3.1-bin-hadoop2.7/bin/spark-submit --class com.ocp.jfc2.plant.dataprocessor.PlantDataProcessor ProcessDataSparkJob.jar,/DATA/apps/ProcessDataSparkJob/JFC4/ProcessAndFilterDataJobs_plant.properties &> /DATA/apps/ProcessDataSparkJob/JFC4_run.log &,com.ocp.jfc2.plant.dataprocessor.PlantDataProcessor,A-P
JFC3 spark job,/DATA/apps/ProcessDataSparkJob/,/DATA/apps/spark-2.3.1-bin-hadoop2.7/bin/spark-submit --class com.ocp.jfc2.plant.dataprocessor.PlantDataProcessor ProcessDataSparkJob.jar,/DATA/apps/ProcessDataSparkJob/JFC3/ProcessAndFilterDataJobs_plant.properties &> /DATA/apps/ProcessDataSparkJob/JFC3_run.log &,com.ocp.jfc2.plant.dataprocessor.PlantDataProcessor,A-P
JFC1 spark job,/DATA/apps/ProcessDataSparkJob/,/DATA/apps/spark-2.3.1-bin-hadoop2.7/bin/spark-submit --class com.ocp.jfc2.plant.dataprocessor.PlantDataProcessor ProcessDataSparkJob.jar,/DATA/apps/ProcessDataSparkJob/JFC1/ProcessAndFilterDataJobs_plant.properties &> /DATA/apps/ProcessDataSparkJob/JFC1_run.log &,com.ocp.jfc2.plant.dataprocessor.PlantDataProcessor,A-P
SIEMENS spark job,/DATA/apps/ProcessDataSparkJob/,/DATA/apps/spark-2.3.1-bin-hadoop2.7/bin/spark-submit --class com.ocp.jfc2.plant.dataprocessor.PlantDataProcessor ProcessDataSparkJob.jar,/DATA/apps/ProcessDataSparkJob/SIEMENS/ProcessAndFilterDataJobs_plant.properties &> /DATA/apps/ProcessDataSparkJob/SIEMENS_run.log &,com.ocp.jfc2.plant.dataprocessor.PlantDataProcessor,A-P
GE spark job,/DATA/apps/ProcessDataSparkJob/,/DATA/apps/spark-2.3.1-bin-hadoop2.7/bin/spark-submit --class com.ocp.jfc2.plant.dataprocessor.PlantDataProcessor ProcessDataSparkJob.jar,/DATA/apps/ProcessDataSparkJob/GE/ProcessAndFilterDataJobs_plant.properties &> /DATA/apps/ProcessDataSparkJob/GE_run.log &,com.ocp.jfc2.plant.dataprocessor.PlantDataProcessor,A-P


Merci d'avance

1 réponse

Messages postés
157
Date d'inscription
vendredi 24 mai 2013
Statut
Membre
Dernière intervention
8 avril 2020

une aide s'il vous plaît ?