Skip to content

Commit

Permalink
Merge pull request #917 from hmcts/fix-elasticsearch-job
Browse files Browse the repository at this point in the history
Fix elasticsearch workflow
  • Loading branch information
ieuanb74 authored Dec 12, 2024
2 parents 40a93e6 + 5a3d97a commit 9e962ef
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 30 deletions.
33 changes: 12 additions & 21 deletions azure-pipeline-start-elasticsearch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,12 @@ schedules:
include:
- master

trigger:
branches:
include:
- master

variables:
timeoutInMinutes: 60
agentPool: 'hmcts-cftptl-agent-pool'
service_connection: 'GA'

stages:
stage: StartElasticsearchService
jobs:
job: StartElasticsearchService
displayName: Start Elasticsearch Service
pool:
name: $(agentPool)
pool:
name: 'hmcts-cftptl-agent-pool'

jobs:
- job: StartElasticsearchService
displayName: Start Elasticsearch Service
steps:
- checkout: self
clean: true
Expand All @@ -34,14 +22,17 @@ stages:
inputs:
secureFile: 'elk_private_key'

- script: ./$(System.DefaultWorkingDirectory)/scripts/vm/restart-es-service.sh staging $(elkprivatekey.secureFilePath)
- script: chmod 600 $(elkprivatekey.secureFilePath)
displayName: 'Set permissions on private key'

- script: ./scripts/vm/restart-es-service.sh staging $(elkprivatekey.secureFilePath)
displayName: 'Start Elasticsearch Staging'

- script: ./$(System.DefaultWorkingDirectory)/scripts/vm/restart-es-service.sh demo $(elkprivatekey.secureFilePath)
- script: ./scripts/vm/restart-es-service.sh demo $(elkprivatekey.secureFilePath)
displayName: 'Start Elasticsearch Demo'

- script: ./$(System.DefaultWorkingDirectory)/scripts/vm/restart-es-service.sh perftest $(elkprivatekey.secureFilePath)
- script: ./scripts/vm/restart-es-service.sh perftest $(elkprivatekey.secureFilePath)
displayName: 'Start Elasticsearch Perftest'

- script: ./$(System.DefaultWorkingDirectory)/scripts/vm/restart-es-service.sh ithc $(elkprivatekey.secureFilePath)
- script: ./scripts/vm/restart-es-service.sh ithc $(elkprivatekey.secureFilePath)
displayName: 'Start Elasticsearch ITHC'
22 changes: 13 additions & 9 deletions scripts/vm/restart-es-service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ PERFTEST_HOSTS=("10.112.153.7" "10.112.153.6" "10.112.153.9" "10.112.153.5") # c
CHECK_COMMAND="sudo systemctl is-failed elasticsearch.service"
RESTART_COMMAND="sudo systemctl restart elasticsearch.service"

if [ "$#" -ne 1 ]; then
echo "Usage: $0 <environment>"
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <environment> <private_key>"
exit 1
fi

Expand All @@ -40,11 +40,15 @@ case "${ENVIRONMENT}" in
esac

for REMOTE_HOST in "${REMOTE_HOSTS[@]}"; do
STATUS=$(ssh -o StrictHostKeyChecking=no -i "${PRIVATE_KEY}" ${REMOTE_USER}@${REMOTE_HOST} "${CHECK_COMMAND}")
if [ "${STATUS}" != "active" ]; then
echo "Restarting Elasticsearch service on ${REMOTE_HOST}"
ssh -o StrictHostKeyChecking=no -i "${PRIVATE_KEY}" ${REMOTE_USER}@${REMOTE_HOST} "${RESTART_COMMAND}"
else
echo "Elasticsearch service on ${REMOTE_HOST} is active."
fi
STATUS=$(ssh -o ConnectTimeout=20 -o StrictHostKeyChecking=no -i "${PRIVATE_KEY}" ${REMOTE_USER}@${REMOTE_HOST} "${CHECK_COMMAND}")
if [[ -z "${STATUS}" ]]; then
echo "Problem connecting to host ${REMOTE_HOST}."
else
if [[ "${STATUS}" == "active" ]]; then
echo "Elasticsearch service on ${REMOTE_HOST} is active."
else
echo "Restarting Elasticsearch service on ${REMOTE_HOST}"
ssh -o ConnectTimeout=20 -o StrictHostKeyChecking=no -i "${PRIVATE_KEY}" ${REMOTE_USER}@${REMOTE_HOST} "${RESTART_COMMAND}"
fi
fi
done

0 comments on commit 9e962ef

Please sign in to comment.