2014-11-15 04:39:34 +00:00
#!/bin/sh
2016-11-05 01:18:43 +00:00
pre_checks() {
mmc=$(sysctl vm.max_map_count|sed 's/.*= //')
if [[ $mmc -lt 262144 ]]; then
echo "
ERROR: As of 5.0.0 Elasticsearch requires increasing mmap counts.
Refer to https://www.elastic.co/guide/en/elasticsearch/reference/current/vm-max-map-count.html
"
exit 1
fi
}
2014-11-15 04:39:34 +00:00
2016-09-04 21:10:08 +00:00
discoverIpFromLink() {
dev=$1
mode=$2
ip=`ipaddr show dev $dev scope global|awk '$1 == "inet" { if (!match($2,"/32")) { gsub("/.*","",$2) ; print $2 } }'`
echo "Discovered $mode address $ip for $dev"
2016-11-05 01:18:43 +00:00
OPTS="$OPTS -E $mode.host=$ip"
2016-09-04 21:10:08 +00:00
}
2017-01-23 16:25:50 +00:00
discoverAllGlobalIps() {
ips=`ipaddr show scope global|awk '$1 == "inet" { if (!match($2,"/32")) { gsub("/.*","",$2) ; addrs[length(addrs)] = $2 } } END { for (i in addrs) { if (i>0) printf "," ; printf addrs[i] } }'`
OPTS="$OPTS -E network.host=$ips"
}
2016-11-05 01:18:43 +00:00
setup_clustering() {
2016-09-04 20:25:04 +00:00
2016-11-05 01:18:43 +00:00
if [ -n "$CLUSTER" ]; then
OPTS="$OPTS -E cluster.name=$CLUSTER"
if [ -n "$CLUSTER_FROM" ]; then
if [ -d /data/$CLUSTER_FROM -a ! -d /data/$CLUSTER ]; then
echo "Performing cluster data migration from $CLUSTER_FROM to $CLUSTER"
mv /data/$CLUSTER_FROM /data/$CLUSTER
fi
2015-07-24 16:49:57 +00:00
fi
fi
2016-11-05 15:46:32 +00:00
2016-11-05 01:18:43 +00:00
if [ -n "$NODE_NAME" ]; then
OPTS="$OPTS -E node.name=$NODE_NAME"
fi
2016-11-05 15:46:32 +00:00
2016-11-05 01:18:43 +00:00
if [ -n "$MULTICAST" ]; then
OPTS="$OPTS -E discovery.zen.ping.multicast.enabled=$MULTICAST"
fi
2016-11-05 15:46:32 +00:00
2016-11-05 01:18:43 +00:00
if [ -n "$UNICAST_HOSTS" ]; then
OPTS="$OPTS -E discovery.zen.ping.unicast.hosts=$UNICAST_HOSTS"
fi
2016-11-05 15:46:32 +00:00
2016-11-05 01:18:43 +00:00
if [ -n "$PUBLISH_AS" ]; then
OPTS="$OPTS -E transport.publish_host=$(echo $PUBLISH_AS | awk -F: '{print $1}')"
OPTS="$OPTS -E transport.publish_port=$(echo $PUBLISH_AS | awk -F: '{if ($2) print $2; else print 9300}')"
fi
2014-11-15 20:10:06 +00:00
2016-11-05 01:18:43 +00:00
if [ -n "$MIN_MASTERS" ]; then
2016-11-05 15:46:32 +00:00
OPTS="$OPTS -E discovery.zen.minimum_master_nodes=$MIN_MASTERS"
2016-11-05 01:18:43 +00:00
fi
2014-11-15 20:10:06 +00:00
2016-11-05 01:18:43 +00:00
}
2015-11-28 17:35:59 +00:00
2016-11-05 01:18:43 +00:00
install_plugins() {
2014-11-15 20:10:06 +00:00
2016-11-05 01:18:43 +00:00
if [ -n "$PLUGINS" ]; then
for p in $(echo $PLUGINS | awk -v RS=, '{print}')
do
echo "Installing the plugin $p"
$ES_HOME/bin/elasticsearch-plugin install $p
done
else
mkdir -p $ES_HOME/plugins
fi
}
2014-11-15 04:39:34 +00:00
2016-11-05 01:18:43 +00:00
setup_personality() {
if [ -n "$TYPE" ]; then
case $TYPE in
MASTER)
2016-11-05 15:46:32 +00:00
OPTS="$OPTS -E node.master=true -E node.data=false"
2016-11-05 01:18:43 +00:00
;;
2016-11-05 15:46:32 +00:00
2016-11-05 01:18:43 +00:00
GATEWAY)
2016-11-05 15:46:32 +00:00
OPTS="$OPTS -E node.master=false -E node.data=false"
2016-11-05 01:18:43 +00:00
;;
2016-11-05 15:46:32 +00:00
2016-11-05 01:18:43 +00:00
DATA|NON_MASTER)
2016-11-05 15:46:32 +00:00
OPTS="$OPTS -E node.master=false -E node.data=true"
2016-11-05 01:18:43 +00:00
;;
2016-11-05 15:46:32 +00:00
2016-11-05 01:18:43 +00:00
*)
echo "Unknown node type. Please use MASTER|GATEWAY|DATA|NON_MASTER"
exit 1
esac
fi
2016-07-10 21:32:55 +00:00
2016-11-05 01:18:43 +00:00
}
2016-07-10 21:32:55 +00:00
2016-11-05 01:18:43 +00:00
pre_checks
2016-07-10 21:32:55 +00:00
2016-11-05 01:18:43 +00:00
if [ -f /conf/env ]; then
. /conf/env
2016-07-10 21:32:55 +00:00
fi
2016-11-05 01:18:43 +00:00
if [ ! -e /conf/elasticsearch.* ]; then
cp $ES_HOME/config/elasticsearch.yml /conf
2016-07-10 21:32:55 +00:00
fi
2016-11-05 01:18:43 +00:00
if [ ! -e /conf/log4j2.properties ]; then
cp $ES_HOME/config/log4j2.properties /conf
2014-11-15 20:10:06 +00:00
fi
2016-11-05 01:18:43 +00:00
OPTS="$OPTS \
-E path.conf=/conf \
-E path.data=/data \
-E path.logs=/data \
-E transport.tcp.port=9300 \
-E http.port=9200"
2017-01-23 16:25:50 +00:00
discoverAllGlobalIps
if [ "${DISCOVER_TRANSPORT_IP}" != "" ]; then
discoverIpFromLink $DISCOVER_TRANSPORT_IP transport
fi
if [ "${DISCOVER_HTTP_IP}" != "" ]; then
discoverIpFromLink $DISCOVER_HTTP_IP http
fi
2016-11-05 01:18:43 +00:00
setup_personality
setup_clustering
install_plugins
2016-07-09 17:52:02 +00:00
mkdir -p /conf/scripts
2014-11-15 21:12:49 +00:00
echo "Starting Elasticsearch with the options $OPTS"
2016-07-09 17:52:02 +00:00
CMD="$ES_HOME/bin/elasticsearch $OPTS"
if [ `id -u` = 0 ]; then
echo "Running as non-root..."
2016-11-29 03:37:44 +00:00
chown -R $DEFAULT_ES_USER /data /conf
2016-07-10 14:00:10 +00:00
su -c "$CMD" $DEFAULT_ES_USER
2016-07-09 17:52:02 +00:00
else
$CMD
fi