#! /bin/bash # Author: Ricardas Stoma, gm # Company: Kolmisoft # Year: 2016 # About: script restart service if it is stopped for some reasons . /usr/src/m2/framework/bash_functions.sh if [ ! -e /usr/share/elasticsearch ]; then exit 0; fi _centos_version if (( centos_version != 6 )); then # centos 7 if ! systemctl status elasticsearch.service | grep -q running; then systemctl start elasticsearch.service else # ES status is running but ES is dead if ! /bin/netstat -atnpl | grep -q 9200; then systemctl stop elasticsearch.service sleep 2 killall -9 java sleep 2 systemctl start elasticsearch.service fi fi else # centos 6 if ! /etc/init.d/elasticsearch status | grep -q running; then /etc/init.d/elasticsearch start else # ES status is running but ES is dead if ! /bin/netstat -atnpl | grep -q 9200; then /etc/init.d/elasticsearch stop sleep 2 killall -9 java sleep 2 /etc/init.d/elasticsearch start fi fi fi