Skip to content

Instantly share code, notes, and snippets.

@soldni
Last active April 6, 2016 01:52
Show Gist options
  • Select an option

  • Save soldni/76272770d094c0da744d866ee1158e34 to your computer and use it in GitHub Desktop.

Select an option

Save soldni/76272770d094c0da744d866ee1158e34 to your computer and use it in GitHub Desktop.
Starts/stop deamons for elasticsearch
#!/bin/bash
# SETTINGS
USAGE="USAGE: ./es-manager.sh [start|stop] {instances to start}"
ERROR_INT="ERROR: second paramter must be an integer or none."
ERROR_ESHOME="ERROR: Environmental variable ES_HOME is not set."
PID_DIR="pid"
# print error is ES_HOME is not set
if [ -z ${ES_HOME+x} ]
then
echo $ERROR_ESHOME > /dev/stderr;
exit 1
fi
# parse input
MODE=$1
START_COUNT=$2
# make directory for pids
mkdir $PID_DIR 2> /dev/null
if [ "$1" == "start" ]
then
# set count of instances to 1 if none is provided
if [ -z $START_COUNT ]
then
START_COUNT="1"
fi
# check if count is a nubmer
if ! [ "$START_COUNT" -eq "$START_COUNT" ] 2>/dev/null
then
echo $ERROR_INT
echo $USAGE
exit 1
fi
# start elasticsearch
for i in `seq 1 $START_COUNT`
do
sh $ES_HOME/bin/elasticsearch -d -p "pid/$i"
echo "instance #$i started"
sleep 1
done
exit 0
fi
if [ "$MODE" == "stop" ]
then
# stop elasticsearch
for pid in "$PID_DIR"/*
do
kill `cat "$pid"`
done
exit 0
fi
# print usage if no operation was executed
echo $USAGE
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment