|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +################################################################################## |
| 4 | +# Name : deploy__elk_beats.sh # |
| 5 | +# Author : Ibrahim Musayev # |
| 6 | +# Purpose : Downloading of beats rpm files from artifactory and installing # |
| 7 | +# them on servers by using sudo privileges in install_root.sh # |
| 8 | +# script. # |
| 9 | +# History : 18.02.22 Ibrahim Musayev, creation # |
| 10 | +################################################################################## |
| 11 | + |
| 12 | +DATE=`date +'%Y%m%d'` |
| 13 | +TIMESTAMP=`date +'%Y%m%d_%H%M%S'` |
| 14 | +BEATS_SETUP=/opt/setup/beats |
| 15 | +OLD_VERSION_FILEBEAT=`/usr/share/filebeat/bin/filebeat version| awk '{print $3 }' 2>/dev/null` |
| 16 | +OLD_VERSION_METRICBEAT=`/usr/share/metricbeat/bin/metricbeat version| awk '{print $3 }' 2>/dev/null` |
| 17 | +LOGFILE=/opt/operations/logs/deploy_beats.log |
| 18 | +INSTALL_ROOT=/opt/source/custom/scripts/install_root.sh |
| 19 | +MASK=$1 |
| 20 | + |
| 21 | +if [ ! -d ${BEATS_SETUP} ]; then |
| 22 | + mkdir -p ${BEATS_SETUP} |
| 23 | +elif [ -d ${BEATS_SETUP} ] && [ $(ls "$BEATS_SETUP" | wc -l) -ne 0 ]; then |
| 24 | + rm -r ${BEATS_SETUP}/* |
| 25 | +fi |
| 26 | + |
| 27 | +if [[ ! -d $(dirname ${LOGFILE}) ]]; then |
| 28 | + mkdir -p $(dirname ${LOGFILE}) |
| 29 | +fi |
| 30 | + |
| 31 | +cd $BEATS_SETUP |
| 32 | +echo "${TIMESTAMP} WARN Stop filebeat and metricbeat on all nodes with operate_services.sh." | tee -a ${LOGFILE} |
| 33 | +read -p 'Enter the APITOKEN: ' APITOKEN |
| 34 | +read -p 'Enter desired filebeat & metricbeat version: ' VERSION_BEATS |
| 35 | + |
| 36 | +curl -H X-JFrog-Art-Api:${APITOKEN} -O -s "https://artifactory.$MASK/elastic/${VERSION_BEATS}/filebeat-${VERSION_BEATS}-x86_64.rpm" # masking the domain regarding security. |
| 37 | +curl -H X-JFrog-Art-Api:${APITOKEN} -O -s "https://artifactory.$MASK/elastic/${VERSION_BEATS}/metricbeat-${VERSION_BEATS}-x86_64.rpm" # masking the domain regarding security. |
| 38 | + |
| 39 | +if [ $(ls "$BEATS_SETUP" | wc -l) -ne 0 ]; then |
| 40 | + echo "${TIMESTAMP} INFO filebeat-${VERSION_BEATS} and metricbeat-${VERSION_BEATS} downloads completed." | tee -a ${LOGFILE} |
| 41 | +else |
| 42 | + echo "${TIMESTAMP} ERROR Something went wrong. Please retry to download update again!" | tee -a ${LOGFILE} |
| 43 | + exit 1 |
| 44 | +fi |
| 45 | + |
| 46 | +if [[ "${VERSION_BEATS}" == "${OLD_VERSION_FILEBEAT}" ]]; then |
| 47 | + echo "${TIMESTAMP} INFO filebeat-${VERSION_BEATS} is already installed. Nothing to do. Complete!" | tee -a ${LOGFILE} |
| 48 | + exit 0 |
| 49 | +else |
| 50 | + sudo ${INSTALL_ROOT} install_filebeat |
| 51 | +fi |
| 52 | + |
| 53 | +if [[ "${VERSION_BEATS}" == "${OLD_VERSION_METRICBEAT}" ]]; then |
| 54 | + echo "${TIMESTAMP} INFO metricbeat-${VERSION_BEATS} is already installed. Nothing to do. Complete!" | tee -a ${LOGFILE} |
| 55 | + exit 0 |
| 56 | +else |
| 57 | + sudo ${INSTALL_ROOT} install_metricbeat |
| 58 | +fi |
| 59 | + |
| 60 | +CHECK_FILEBEAT_VERSION=`/usr/share/filebeat/bin/filebeat version| awk '{print $3 }' 2>/dev/null` |
| 61 | +CHECK_METRICBEAT_VERSION=`/usr/share/metricbeat/bin/metricbeat version| awk '{print $3 }' 2>/dev/null` |
| 62 | +TIMESTAMP=`date +'%Y%m%d_%H%M%S'` |
| 63 | + |
| 64 | +if [[ "${CHECK_FILEBEAT_VERSION}" == "${VERSION_BEATS}" ]]; then |
| 65 | + echo "${TIMESTAMP} INFO filebeat-${VERSION_BEATS} is successfully installed." |
| 66 | +else |
| 67 | + echo "${TIMESTAMP} ERROR Fatal error during filebeat-${VERSION_BEATS} installation. Exiting..." | tee -a ${LOGFILE} |
| 68 | + exit 1 |
| 69 | +fi |
| 70 | + |
| 71 | +if [[ "${CHECK_METRICBEAT_VERSION}" == "${VERSION_BEATS}" ]]; then |
| 72 | + echo "${TIMESTAMP} INFO metricbeat-${VERSION_BEATS} is successfully installed." |
| 73 | +else |
| 74 | + echo "${TIMESTAMP} ERROR Fatal error during metricbeat-${VERSION_BEATS} installation. Exiting..." | tee -a ${LOGFILE} |
| 75 | + exit 1 |
| 76 | +fi |
| 77 | + |
| 78 | +EXITCODE=$? |
| 79 | +TIMESTAMP=`date +'%Y%m%d_%H%M%S'` |
| 80 | +if [[ ${EXITCODE} -ne 0 ]]; then |
| 81 | + echo "${TIMESTAMP} ERROR Got exit code ${EXITCODE} on installation. Exiting ..." | tee -a ${LOGFILE} |
| 82 | + exit 1 |
| 83 | +else |
| 84 | + echo "${TIMESTAMP} INFO Starting to copy parameters in installation folders" | tee -a ${LOGFILE} |
| 85 | + sudo ${INSTALL_ROOT} sync_source ${ENV} ${VERSION_BEATS} |
| 86 | +fi |
| 87 | + |
| 88 | +exit 0 |
0 commit comments