We are running a jenkins job which runs a script to check the status of the kafka service. The kakfa instances are kept in for loop. when the kafka service is running it checks in all kafka instances and gives job as success, when any one of the kafka service fails, jenkins job gets exits, so we could not know the service status of other running instances. So can we get a solution to check the status of other kafka service also if any one of the service is not running.
pipeline {
agent { label 'host1' }
options {
skipDefaultCheckout()
}
stages {
stage('Checkout code') {
steps {
checkout scm
}
}
stage('Build') {
steps {
script{
dir("$env.WORKSPACE"){
sh '''
check_status() {
serviceCheck=$(/etc/init.d/kafka status | awk '{print $3}') >/dev/null
if [[ "$serviceCheck" = "Running" ]]; then
echo "Kafka Service is running "
else
echo "Kafka Service is NOT running"
fi
}
cd ../
kafka_error_state=0
hostIPList=("xxx.compute-1.amazonaws.com" "yyy.compute-1.amazonaws.com" "zzz.compute-1.amazonaws.com")
for hostIP in "${hostIPList[@]}"; do
echo " **** checking kafka service status in $hostIP ****"
sudo ssh -i "kafka.pem" ubuntu@$hostIP "$(typeset -f check_status); check_status"
if [ $? -eq 10 ]; then
kafka_error_state=1
fi
done
if [ "$kafka_error_state" -eq 1 ]; then
echo "Please check logs, kafka is not running in one or more of the instances.."
exit 1
fi
'''
}
}
}
}
}