2016-05-18 11:03:00 -04:00
|
|
|
#!/bin/bash
|
2015-04-14 10:22:37 -04:00
|
|
|
|
2017-09-14 09:08:20 -04:00
|
|
|
# This file contains some utilities to test the .deb/.rpm
|
2017-05-17 17:42:25 -04:00
|
|
|
# packages and the SysV/Systemd scripts.
|
2015-04-14 10:22:37 -04:00
|
|
|
|
|
|
|
# WARNING: This testing file must be executed as root and can
|
2017-04-26 10:40:35 -04:00
|
|
|
# dramatically change your system. It should only be executed
|
|
|
|
# in a throw-away VM like those made by the Vagrantfile at
|
|
|
|
# the root of the Elasticsearch source code. This should
|
|
|
|
# cause the script to fail if it is executed any other way:
|
|
|
|
[ -f /etc/is_vagrant_vm ] || {
|
|
|
|
>&2 echo "must be run on a vagrant VM"
|
|
|
|
exit 1
|
|
|
|
}
|
2015-04-14 10:22:37 -04:00
|
|
|
|
|
|
|
# Licensed to Elasticsearch under one or more contributor
|
|
|
|
# license agreements. See the NOTICE file distributed with
|
|
|
|
# this work for additional information regarding copyright
|
|
|
|
# ownership. Elasticsearch licenses this file to you under
|
|
|
|
# the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing,
|
|
|
|
# software distributed under the License is distributed on an
|
|
|
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
# KIND, either express or implied. See the License for the
|
|
|
|
# specific language governing permissions and limitations
|
|
|
|
# under the License.
|
|
|
|
|
|
|
|
# Checks if necessary commands are available to run the tests
|
|
|
|
|
|
|
|
if [ ! -x /usr/bin/which ]; then
|
|
|
|
echo "'which' command is mandatory to run the tests"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -x "`which wget 2>/dev/null`" ]; then
|
|
|
|
echo "'wget' command is mandatory to run the tests"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -x "`which curl 2>/dev/null`" ]; then
|
|
|
|
echo "'curl' command is mandatory to run the tests"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -x "`which pgrep 2>/dev/null`" ]; then
|
|
|
|
echo "'pgrep' command is mandatory to run the tests"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -x "`which unzip 2>/dev/null`" ]; then
|
|
|
|
echo "'unzip' command is mandatory to run the tests"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -x "`which tar 2>/dev/null`" ]; then
|
|
|
|
echo "'tar' command is mandatory to run the tests"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -x "`which unzip 2>/dev/null`" ]; then
|
|
|
|
echo "'unzip' command is mandatory to run the tests"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -x "`which java 2>/dev/null`" ]; then
|
2018-06-25 11:54:39 -04:00
|
|
|
# there are some tests that move java temporarily
|
|
|
|
if [ ! -x "`command -v java.bak 2>/dev/null`" ]; then
|
|
|
|
echo "'java' command is mandatory to run the tests"
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-04-14 10:22:37 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Returns 0 if the 'dpkg' command is available
|
|
|
|
is_dpkg() {
|
|
|
|
[ -x "`which dpkg 2>/dev/null`" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
# Returns 0 if the 'rpm' command is available
|
|
|
|
is_rpm() {
|
|
|
|
[ -x "`which rpm 2>/dev/null`" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
# Skip test if the 'dpkg' command is not supported
|
|
|
|
skip_not_dpkg() {
|
2015-08-24 12:26:06 -04:00
|
|
|
is_dpkg || skip "dpkg is not supported"
|
2015-04-14 10:22:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Skip test if the 'rpm' command is not supported
|
|
|
|
skip_not_rpm() {
|
2015-08-24 12:26:06 -04:00
|
|
|
is_rpm || skip "rpm is not supported"
|
|
|
|
}
|
|
|
|
|
|
|
|
skip_not_dpkg_or_rpm() {
|
|
|
|
is_dpkg || is_rpm || skip "only dpkg or rpm systems are supported"
|
2015-04-14 10:22:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Returns 0 if the system supports Systemd
|
|
|
|
is_systemd() {
|
|
|
|
[ -x /bin/systemctl ]
|
|
|
|
}
|
|
|
|
|
|
|
|
# Skip test if Systemd is not supported
|
|
|
|
skip_not_systemd() {
|
|
|
|
if [ ! -x /bin/systemctl ]; then
|
|
|
|
skip "systemd is not supported"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Returns 0 if the system supports SysV
|
|
|
|
is_sysvinit() {
|
|
|
|
[ -x "`which service 2>/dev/null`" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
# Skip test if SysV is not supported
|
|
|
|
skip_not_sysvinit() {
|
|
|
|
if [ -x "`which service 2>/dev/null`" ] && is_systemd; then
|
|
|
|
skip "sysvinit is supported, but systemd too"
|
|
|
|
fi
|
|
|
|
if [ ! -x "`which service 2>/dev/null`" ]; then
|
|
|
|
skip "sysvinit is not supported"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Skip if tar is not supported
|
|
|
|
skip_not_tar_gz() {
|
|
|
|
if [ ! -x "`which tar 2>/dev/null`" ]; then
|
|
|
|
skip "tar is not supported"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Skip if unzip is not supported
|
|
|
|
skip_not_zip() {
|
|
|
|
if [ ! -x "`which unzip 2>/dev/null`" ]; then
|
|
|
|
skip "unzip is not supported"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_file_exist() {
|
2015-08-14 15:48:26 -04:00
|
|
|
local file="$1"
|
2017-12-12 11:07:33 -05:00
|
|
|
local count=$(echo "$file" | wc -l)
|
|
|
|
[[ "$count" == "1" ]] || {
|
|
|
|
echo "assert_file_exist must be run on a single file at a time but was called on [$count] files: $file"
|
|
|
|
false
|
|
|
|
}
|
2016-04-18 17:31:28 -04:00
|
|
|
if [ ! -e "$file" ]; then
|
|
|
|
echo "Should exist: ${file} but does not"
|
|
|
|
fi
|
2015-08-14 15:48:26 -04:00
|
|
|
local file=$(readlink -m "${file}")
|
|
|
|
[ -e "$file" ]
|
2015-04-14 10:22:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
assert_file_not_exist() {
|
2015-08-14 15:48:26 -04:00
|
|
|
local file="$1"
|
2016-04-18 17:31:28 -04:00
|
|
|
if [ -e "$file" ]; then
|
|
|
|
echo "Should not exist: ${file} but does"
|
|
|
|
fi
|
2015-08-14 15:48:26 -04:00
|
|
|
local file=$(readlink -m "${file}")
|
|
|
|
[ ! -e "$file" ]
|
2015-04-14 10:22:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
assert_file() {
|
2015-08-21 16:05:50 -04:00
|
|
|
local file="$1"
|
2015-04-14 10:22:37 -04:00
|
|
|
local type=$2
|
|
|
|
local user=$3
|
2015-10-08 04:43:38 -04:00
|
|
|
local group=$4
|
|
|
|
local privileges=$5
|
2015-04-14 10:22:37 -04:00
|
|
|
|
2015-08-21 16:05:50 -04:00
|
|
|
assert_file_exist "$file"
|
2015-04-14 10:22:37 -04:00
|
|
|
|
|
|
|
if [ "$type" = "d" ]; then
|
2016-04-18 17:31:28 -04:00
|
|
|
if [ ! -d "$file" ]; then
|
|
|
|
echo "[$file] should be a directory but is not"
|
|
|
|
fi
|
2015-04-14 10:22:37 -04:00
|
|
|
[ -d "$file" ]
|
|
|
|
else
|
2016-04-18 17:31:28 -04:00
|
|
|
if [ ! -f "$file" ]; then
|
|
|
|
echo "[$file] should be a regular file but is not"
|
|
|
|
fi
|
2015-04-14 10:22:37 -04:00
|
|
|
[ -f "$file" ]
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "x$user" != "x" ]; then
|
2015-10-09 10:52:05 -04:00
|
|
|
realuser=$(find "$file" -maxdepth 0 -printf "%u")
|
2016-04-18 17:31:28 -04:00
|
|
|
if [ "$realuser" != "$user" ]; then
|
|
|
|
echo "Expected user: $user, found $realuser [$file]"
|
|
|
|
fi
|
2015-04-14 10:22:37 -04:00
|
|
|
[ "$realuser" = "$user" ]
|
|
|
|
fi
|
|
|
|
|
2015-10-08 04:43:38 -04:00
|
|
|
if [ "x$group" != "x" ]; then
|
|
|
|
realgroup=$(find "$file" -maxdepth 0 -printf "%g")
|
2016-04-18 17:31:28 -04:00
|
|
|
if [ "$realgroup" != "$group" ]; then
|
|
|
|
echo "Expected group: $group, found $realgroup [$file]"
|
|
|
|
fi
|
2015-10-08 04:43:38 -04:00
|
|
|
[ "$realgroup" = "$group" ]
|
|
|
|
fi
|
|
|
|
|
2015-04-14 10:22:37 -04:00
|
|
|
if [ "x$privileges" != "x" ]; then
|
|
|
|
realprivileges=$(find "$file" -maxdepth 0 -printf "%m")
|
2016-04-18 17:31:28 -04:00
|
|
|
if [ "$realprivileges" != "$privileges" ]; then
|
|
|
|
echo "Expected privileges: $privileges, found $realprivileges [$file]"
|
|
|
|
fi
|
2015-04-14 10:22:37 -04:00
|
|
|
[ "$realprivileges" = "$privileges" ]
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-03-17 22:11:59 -04:00
|
|
|
assert_module_or_plugin_directory() {
|
|
|
|
local directory=$1
|
|
|
|
shift
|
|
|
|
|
|
|
|
#owner group and permissions vary depending on how es was installed
|
|
|
|
#just make sure that everything is the same as $CONFIG_DIR, which was properly set up during install
|
|
|
|
config_user=$(find "$ESHOME" -maxdepth 0 -printf "%u")
|
|
|
|
config_owner=$(find "$ESHOME" -maxdepth 0 -printf "%g")
|
|
|
|
|
2016-04-18 17:31:28 -04:00
|
|
|
assert_file $directory d $config_user $config_owner 755
|
2016-03-17 22:11:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
assert_module_or_plugin_file() {
|
|
|
|
local file=$1
|
|
|
|
shift
|
|
|
|
|
2016-03-17 22:34:33 -04:00
|
|
|
assert_file_exist "$(readlink -m $file)"
|
2016-04-18 17:31:28 -04:00
|
|
|
assert_file $file f $config_user $config_owner 644
|
2016-03-17 22:11:59 -04:00
|
|
|
}
|
|
|
|
|
2015-04-14 10:22:37 -04:00
|
|
|
assert_output() {
|
|
|
|
echo "$output" | grep -E "$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Deletes everything before running a test file
|
|
|
|
clean_before_test() {
|
|
|
|
|
|
|
|
# List of files to be deleted
|
|
|
|
ELASTICSEARCH_TEST_FILES=("/usr/share/elasticsearch" \
|
|
|
|
"/etc/elasticsearch" \
|
|
|
|
"/var/lib/elasticsearch" \
|
|
|
|
"/var/log/elasticsearch" \
|
|
|
|
"/tmp/elasticsearch" \
|
|
|
|
"/etc/default/elasticsearch" \
|
|
|
|
"/etc/sysconfig/elasticsearch" \
|
|
|
|
"/var/run/elasticsearch" \
|
2015-04-22 08:40:53 -04:00
|
|
|
"/usr/share/doc/elasticsearch" \
|
2018-04-25 12:52:37 -04:00
|
|
|
"/usr/share/doc/elasticsearch-oss" \
|
2015-04-22 10:02:20 -04:00
|
|
|
"/tmp/elasticsearch" \
|
|
|
|
"/usr/lib/systemd/system/elasticsearch.conf" \
|
|
|
|
"/usr/lib/tmpfiles.d/elasticsearch.conf" \
|
|
|
|
"/usr/lib/sysctl.d/elasticsearch.conf")
|
2015-04-14 10:22:37 -04:00
|
|
|
|
2015-08-14 18:12:52 -04:00
|
|
|
# Kills all processes of user elasticsearch
|
|
|
|
if id elasticsearch > /dev/null 2>&1; then
|
|
|
|
pkill -u elasticsearch 2>/dev/null || true
|
|
|
|
fi
|
2015-04-22 08:40:53 -04:00
|
|
|
|
2015-08-14 18:12:52 -04:00
|
|
|
# Kills all running Elasticsearch processes
|
|
|
|
ps aux | grep -i "org.elasticsearch.bootstrap.Elasticsearch" | awk {'print $2'} | xargs kill -9 > /dev/null 2>&1 || true
|
2015-04-14 10:22:37 -04:00
|
|
|
|
2016-03-18 11:45:28 -04:00
|
|
|
purge_elasticsearch
|
|
|
|
|
|
|
|
# Removes user & group
|
|
|
|
userdel elasticsearch > /dev/null 2>&1 || true
|
|
|
|
groupdel elasticsearch > /dev/null 2>&1 || true
|
|
|
|
|
|
|
|
# Removes all files
|
|
|
|
for d in "${ELASTICSEARCH_TEST_FILES[@]}"; do
|
|
|
|
if [ -e "$d" ]; then
|
|
|
|
rm -rf "$d"
|
|
|
|
fi
|
|
|
|
done
|
2017-07-11 17:38:50 -04:00
|
|
|
|
|
|
|
if is_systemd; then
|
|
|
|
systemctl unmask systemd-sysctl.service
|
|
|
|
fi
|
2016-03-18 11:45:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
purge_elasticsearch() {
|
2015-08-14 18:12:52 -04:00
|
|
|
# Removes RPM package
|
|
|
|
if is_rpm; then
|
2018-02-23 11:03:17 -05:00
|
|
|
rpm --quiet -e $PACKAGE_NAME > /dev/null 2>&1 || true
|
2015-08-14 18:12:52 -04:00
|
|
|
fi
|
2015-04-14 10:22:37 -04:00
|
|
|
|
2015-08-14 18:12:52 -04:00
|
|
|
if [ -x "`which yum 2>/dev/null`" ]; then
|
2018-02-23 11:03:17 -05:00
|
|
|
yum remove -y $PACKAGE_NAME > /dev/null 2>&1 || true
|
2015-08-14 18:12:52 -04:00
|
|
|
fi
|
2015-04-14 10:22:37 -04:00
|
|
|
|
2015-08-14 18:12:52 -04:00
|
|
|
# Removes DEB package
|
|
|
|
if is_dpkg; then
|
2018-02-23 11:03:17 -05:00
|
|
|
dpkg --purge $PACKAGE_NAME > /dev/null 2>&1 || true
|
2015-08-14 18:12:52 -04:00
|
|
|
fi
|
2015-04-14 10:22:37 -04:00
|
|
|
|
2015-08-14 18:12:52 -04:00
|
|
|
if [ -x "`which apt-get 2>/dev/null`" ]; then
|
2018-02-23 11:03:17 -05:00
|
|
|
apt-get --quiet --yes purge $PACKAGE_NAME > /dev/null 2>&1 || true
|
2015-08-14 18:12:52 -04:00
|
|
|
fi
|
2015-04-14 10:22:37 -04:00
|
|
|
}
|
|
|
|
|
2015-09-04 15:34:10 -04:00
|
|
|
# Start elasticsearch and wait for it to come up with a status.
|
|
|
|
# $1 - expected status - defaults to green
|
2015-04-14 10:22:37 -04:00
|
|
|
start_elasticsearch_service() {
|
2015-09-02 15:16:53 -04:00
|
|
|
local desiredStatus=${1:-green}
|
2016-03-23 15:55:10 -04:00
|
|
|
local index=$2
|
2017-04-17 16:36:32 -04:00
|
|
|
local commandLineArgs=$3
|
2015-09-02 15:16:53 -04:00
|
|
|
|
2017-04-17 16:36:32 -04:00
|
|
|
run_elasticsearch_service 0 $commandLineArgs
|
2015-09-24 11:39:00 -04:00
|
|
|
|
2016-03-23 15:55:10 -04:00
|
|
|
wait_for_elasticsearch_status $desiredStatus $index
|
2015-09-24 11:39:00 -04:00
|
|
|
|
|
|
|
if [ -r "/tmp/elasticsearch/elasticsearch.pid" ]; then
|
|
|
|
pid=$(cat /tmp/elasticsearch/elasticsearch.pid)
|
|
|
|
[ "x$pid" != "x" ] && [ "$pid" -gt 0 ]
|
|
|
|
echo "Looking for elasticsearch pid...."
|
|
|
|
ps $pid
|
|
|
|
elif is_systemd; then
|
|
|
|
run systemctl is-active elasticsearch.service
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
run systemctl status elasticsearch.service
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
elif is_sysvinit; then
|
|
|
|
run service elasticsearch status
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Start elasticsearch
|
|
|
|
# $1 expected status code
|
|
|
|
# $2 additional command line args
|
|
|
|
run_elasticsearch_service() {
|
2015-10-06 14:02:09 -04:00
|
|
|
local expectedStatus=$1
|
|
|
|
local commandLineArgs=$2
|
2017-08-14 17:19:06 -04:00
|
|
|
# Set the ES_PATH_CONF setting in case we start as a service
|
|
|
|
if [ ! -z "$ES_PATH_CONF" ] ; then
|
2017-07-20 20:38:49 -04:00
|
|
|
if is_dpkg; then
|
2017-08-14 17:19:06 -04:00
|
|
|
echo "ES_PATH_CONF=$ES_PATH_CONF" >> /etc/default/elasticsearch;
|
2015-09-24 11:39:00 -04:00
|
|
|
elif is_rpm; then
|
2017-08-14 17:19:06 -04:00
|
|
|
echo "ES_PATH_CONF=$ES_PATH_CONF" >> /etc/sysconfig/elasticsearch;
|
2015-09-24 11:39:00 -04:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2015-04-22 08:40:53 -04:00
|
|
|
if [ -f "/tmp/elasticsearch/bin/elasticsearch" ]; then
|
2015-09-24 11:39:00 -04:00
|
|
|
# we must capture the exit code to compare so we don't want to start as background process in case we expect something other than 0
|
2015-10-06 14:02:09 -04:00
|
|
|
local background=""
|
|
|
|
local timeoutCommand=""
|
|
|
|
if [ "$expectedStatus" = 0 ]; then
|
|
|
|
background="-d"
|
|
|
|
else
|
2019-10-28 00:47:06 -04:00
|
|
|
timeoutCommand="timeout 180s "
|
2015-09-24 11:39:00 -04:00
|
|
|
fi
|
2015-08-14 18:16:16 -04:00
|
|
|
# su and the Elasticsearch init script work together to break bats.
|
|
|
|
# sudo isolates bats enough from the init script so everything continues
|
|
|
|
# to tick along
|
2015-09-24 11:39:00 -04:00
|
|
|
run sudo -u elasticsearch bash <<BASH
|
2015-09-27 21:33:05 -04:00
|
|
|
# If jayatana is installed then we try to use it. Elasticsearch should ignore it even when we try.
|
|
|
|
# If it doesn't ignore it then Elasticsearch will fail to start because of security errors.
|
|
|
|
# This line is attempting to emulate the on login behavior of /usr/share/upstart/sessions/jayatana.conf
|
|
|
|
[ -f /usr/share/java/jayatanaag.jar ] && export JAVA_TOOL_OPTIONS="-javaagent:/usr/share/java/jayatanaag.jar"
|
|
|
|
# And now we can start Elasticsearch normally, in the background (-d) and with a pidfile (-p).
|
2017-08-14 17:19:06 -04:00
|
|
|
export ES_PATH_CONF=$ES_PATH_CONF
|
2016-04-11 07:15:19 -04:00
|
|
|
export ES_JAVA_OPTS=$ES_JAVA_OPTS
|
2017-07-20 20:38:49 -04:00
|
|
|
$timeoutCommand/tmp/elasticsearch/bin/elasticsearch $background -p /tmp/elasticsearch/elasticsearch.pid $commandLineArgs
|
2015-09-27 21:33:05 -04:00
|
|
|
BASH
|
2015-10-06 14:02:09 -04:00
|
|
|
[ "$status" -eq "$expectedStatus" ]
|
2015-04-22 08:40:53 -04:00
|
|
|
elif is_systemd; then
|
2015-04-14 10:22:37 -04:00
|
|
|
run systemctl daemon-reload
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
run systemctl enable elasticsearch.service
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
run systemctl is-enabled elasticsearch.service
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
run systemctl start elasticsearch.service
|
2015-10-06 14:02:09 -04:00
|
|
|
[ "$status" -eq "$expectedStatus" ]
|
2015-04-14 10:22:37 -04:00
|
|
|
|
|
|
|
elif is_sysvinit; then
|
|
|
|
run service elasticsearch start
|
2015-10-06 14:02:09 -04:00
|
|
|
[ "$status" -eq "$expectedStatus" ]
|
2015-04-14 10:22:37 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
stop_elasticsearch_service() {
|
2015-04-22 08:40:53 -04:00
|
|
|
if [ -r "/tmp/elasticsearch/elasticsearch.pid" ]; then
|
|
|
|
pid=$(cat /tmp/elasticsearch/elasticsearch.pid)
|
|
|
|
[ "x$pid" != "x" ] && [ "$pid" -gt 0 ]
|
|
|
|
|
2015-08-14 18:16:16 -04:00
|
|
|
kill -SIGTERM $pid
|
2015-04-22 08:40:53 -04:00
|
|
|
elif is_systemd; then
|
2015-04-14 10:22:37 -04:00
|
|
|
run systemctl stop elasticsearch.service
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
run systemctl is-active elasticsearch.service
|
|
|
|
[ "$status" -eq 3 ]
|
2015-04-22 08:40:53 -04:00
|
|
|
|
|
|
|
echo "$output" | grep -E 'inactive|failed'
|
2015-04-14 10:22:37 -04:00
|
|
|
|
|
|
|
elif is_sysvinit; then
|
|
|
|
run service elasticsearch stop
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
run service elasticsearch status
|
|
|
|
[ "$status" -ne 0 ]
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-02-13 13:51:13 -05:00
|
|
|
# the default netcat packages in the distributions we test are not all compatible
|
|
|
|
# so we use /dev/tcp - a feature of bash which makes tcp connections
|
|
|
|
# http://tldp.org/LDP/abs/html/devref1.html#DEVTCP
|
|
|
|
test_port() {
|
|
|
|
local host="$1"
|
|
|
|
local port="$2"
|
|
|
|
cat < /dev/null > "/dev/tcp/$host/$port"
|
|
|
|
}
|
|
|
|
|
|
|
|
describe_port() {
|
|
|
|
local host="$1"
|
|
|
|
local port="$2"
|
|
|
|
if test_port "$host" "$port"; then
|
|
|
|
echo "port $port on host $host is open"
|
|
|
|
else
|
|
|
|
echo "port $port on host $host is not open"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
debug_collect_logs() {
|
Elasticsearch support to JSON logging (#36833)
In order to support JSON log format, a custom pattern layout was used and its configuration is enclosed in ESJsonLayout. Users are free to use their own patterns, but if smooth Beats integration is needed, they should use ESJsonLayout. EvilLoggerTests are left intact to make sure user's custom log patterns work fine.
To populate additional fields node.id and cluster.uuid which are not available at start time,
a cluster state update will have to be received and the values passed to log4j pattern converter.
A ClusterStateObserver.Listener is used to receive only one ClusteStateUpdate. Once update is received the nodeId and clusterUUid are set in a static field in a NodeAndClusterIdConverter.
Following fields are expected in JSON log lines: type, tiemstamp, level, component, cluster.name, node.name, node.id, cluster.uuid, message, stacktrace
see ESJsonLayout.java for more details and field descriptions
Docker log4j2 configuration is now almost the same as the one use for ES binary.
The only difference is that docker is using console appenders, whereas ES is using file appenders.
relates: #32850
2019-01-29 01:20:09 -05:00
|
|
|
local es_logfile="$ESLOG/elasticsearch_server.json"
|
2018-02-13 13:51:13 -05:00
|
|
|
local system_logfile='/var/log/messages'
|
|
|
|
|
|
|
|
if [ -e "$es_logfile" ]; then
|
|
|
|
echo "Here's the elasticsearch log:"
|
|
|
|
cat "$es_logfile"
|
|
|
|
else
|
|
|
|
echo "The elasticsearch log doesn't exist at $es_logfile"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -e "$system_logfile" ]; then
|
|
|
|
echo "Here's the tail of the log at $system_logfile:"
|
|
|
|
tail -n20 "$system_logfile"
|
|
|
|
else
|
|
|
|
echo "The logfile at $system_logfile doesn't exist"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Current java processes:"
|
|
|
|
ps aux | grep java || true
|
|
|
|
|
|
|
|
echo "Testing if ES ports are open:"
|
|
|
|
describe_port 127.0.0.1 9200
|
|
|
|
describe_port 127.0.0.1 9201
|
|
|
|
}
|
|
|
|
|
2018-05-29 14:06:14 -04:00
|
|
|
set_debug_logging() {
|
|
|
|
if [ "$ESCONFIG" ] && [ -d "$ESCONFIG" ] && [ -f /etc/os-release ] && (grep -qi suse /etc/os-release); then
|
2018-06-13 14:15:04 -04:00
|
|
|
echo 'logger.org.elasticsearch.indices: TRACE' >> "$ESCONFIG/elasticsearch.yml"
|
2018-05-29 14:06:14 -04:00
|
|
|
echo 'logger.org.elasticsearch.gateway: TRACE' >> "$ESCONFIG/elasticsearch.yml"
|
2018-06-13 14:15:04 -04:00
|
|
|
echo 'logger.org.elasticsearch.cluster: DEBUG' >> "$ESCONFIG/elasticsearch.yml"
|
2018-05-29 14:06:14 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-09-04 15:34:10 -04:00
|
|
|
# Waits for Elasticsearch to reach some status.
|
|
|
|
# $1 - expected status - defaults to green
|
2015-04-14 10:22:37 -04:00
|
|
|
wait_for_elasticsearch_status() {
|
2015-09-02 15:16:53 -04:00
|
|
|
local desiredStatus=${1:-green}
|
2016-03-23 15:55:10 -04:00
|
|
|
local index=$2
|
2015-04-14 10:22:37 -04:00
|
|
|
|
2015-08-14 18:16:16 -04:00
|
|
|
echo "Making sure elasticsearch is up..."
|
2018-02-13 13:51:13 -05:00
|
|
|
wget -O - --retry-connrefused --waitretry=1 --timeout=120 --tries=120 http://localhost:9200/_cluster/health || {
|
|
|
|
echo "Looks like elasticsearch never started"
|
|
|
|
debug_collect_logs
|
|
|
|
false
|
2015-08-14 18:16:16 -04:00
|
|
|
}
|
|
|
|
|
2016-03-23 15:55:10 -04:00
|
|
|
if [ -z "index" ]; then
|
|
|
|
echo "Tring to connect to elasticsearch and wait for expected status $desiredStatus..."
|
2019-10-28 00:47:06 -04:00
|
|
|
curl -sS "http://localhost:9200/_cluster/health?wait_for_status=$desiredStatus&timeout=180s&pretty"
|
2016-03-23 15:55:10 -04:00
|
|
|
else
|
|
|
|
echo "Trying to connect to elasticsearch and wait for expected status $desiredStatus for index $index"
|
2019-10-28 00:47:06 -04:00
|
|
|
curl -sS "http://localhost:9200/_cluster/health/$index?wait_for_status=$desiredStatus&timeout=180s&pretty"
|
2016-03-23 15:55:10 -04:00
|
|
|
fi
|
2015-08-14 18:16:16 -04:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "Connected"
|
|
|
|
else
|
2017-03-20 10:07:59 -04:00
|
|
|
echo "Unable to connect to Elasticsearch"
|
2015-08-14 18:16:16 -04:00
|
|
|
false
|
|
|
|
fi
|
2015-04-14 10:22:37 -04:00
|
|
|
|
2015-08-14 18:16:16 -04:00
|
|
|
echo "Checking that the cluster health matches the waited for status..."
|
|
|
|
run curl -sS -XGET 'http://localhost:9200/_cat/health?h=status&v=false'
|
|
|
|
if [ "$status" -ne 0 ]; then
|
|
|
|
echo "error when checking cluster health. code=$status output="
|
|
|
|
echo $output
|
|
|
|
false
|
2015-04-14 10:22:37 -04:00
|
|
|
fi
|
2015-09-02 15:16:53 -04:00
|
|
|
echo $output | grep $desiredStatus || {
|
|
|
|
echo "unexpected status: '$output' wanted '$desiredStatus'"
|
2015-08-14 18:16:16 -04:00
|
|
|
false
|
|
|
|
}
|
2015-04-14 10:22:37 -04:00
|
|
|
}
|
|
|
|
|
2016-09-13 11:52:06 -04:00
|
|
|
# Checks the current elasticsearch version using the Info REST endpoint
|
|
|
|
# $1 - expected version
|
|
|
|
check_elasticsearch_version() {
|
|
|
|
local version=$1
|
2018-11-29 01:41:39 -05:00
|
|
|
local versionToCheck
|
|
|
|
local major=$(echo ${version} | cut -d. -f1 )
|
|
|
|
if [ $major -ge 7 ] ; then
|
|
|
|
versionToCheck=$version
|
|
|
|
else
|
|
|
|
versionToCheck=$(echo ${version} | sed -e 's/-SNAPSHOT//')
|
|
|
|
fi
|
2016-09-13 11:52:06 -04:00
|
|
|
|
|
|
|
run curl -s localhost:9200
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
echo $output | grep \"number\"\ :\ \"$versionToCheck\" || {
|
2018-11-29 01:41:39 -05:00
|
|
|
echo "Expected $versionToCheck but installed an unexpected version:"
|
2016-09-13 11:52:06 -04:00
|
|
|
curl -s localhost:9200
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-01 22:12:18 -04:00
|
|
|
# Executes some basic Elasticsearch tests
|
2015-04-14 10:22:37 -04:00
|
|
|
run_elasticsearch_tests() {
|
2015-08-14 18:16:16 -04:00
|
|
|
# TODO this assertion is the same the one made when waiting for
|
|
|
|
# elasticsearch to start
|
2015-04-14 10:22:37 -04:00
|
|
|
run curl -XGET 'http://localhost:9200/_cat/health?h=status&v=false'
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
echo "$output" | grep -w "green"
|
|
|
|
|
2017-02-20 15:56:09 -05:00
|
|
|
curl -s -H "Content-Type: application/json" -XPOST 'http://localhost:9200/library/book/1?refresh=true&pretty' -d '{
|
2016-11-23 05:59:36 -05:00
|
|
|
"title": "Book #1",
|
|
|
|
"pages": 123
|
|
|
|
}'
|
|
|
|
|
2017-02-20 15:56:09 -05:00
|
|
|
curl -s -H "Content-Type: application/json" -XPOST 'http://localhost:9200/library/book/2?refresh=true&pretty' -d '{
|
2016-11-23 05:59:36 -05:00
|
|
|
"title": "Book #2",
|
|
|
|
"pages": 456
|
2015-08-14 18:16:16 -04:00
|
|
|
}'
|
2015-04-14 10:22:37 -04:00
|
|
|
|
2015-09-01 22:12:18 -04:00
|
|
|
curl -s -XGET 'http://localhost:9200/_count?pretty' |
|
2016-11-23 05:59:36 -05:00
|
|
|
grep \"count\"\ :\ 2
|
2015-09-01 22:12:18 -04:00
|
|
|
|
2015-08-14 18:16:16 -04:00
|
|
|
curl -s -XDELETE 'http://localhost:9200/_all'
|
2015-04-14 10:22:37 -04:00
|
|
|
}
|
2015-08-21 16:05:50 -04:00
|
|
|
|
|
|
|
# Move the config directory to another directory and properly chown it.
|
|
|
|
move_config() {
|
|
|
|
local oldConfig="$ESCONFIG"
|
2018-08-07 11:59:56 -04:00
|
|
|
# The custom config directory is not under /tmp or /var/tmp because
|
2018-10-03 13:11:39 -04:00
|
|
|
# systemd's private temp directory functionally means different
|
2018-08-07 11:59:56 -04:00
|
|
|
# processes can have different views of what's in these directories
|
|
|
|
export ESCONFIG="${1:-$(mktemp -p /etc -d -t 'config.XXXX')}"
|
2015-08-21 16:05:50 -04:00
|
|
|
echo "Moving configuration directory from $oldConfig to $ESCONFIG"
|
|
|
|
|
|
|
|
# Move configuration files to the new configuration directory
|
|
|
|
mv "$oldConfig"/* "$ESCONFIG"
|
|
|
|
chown -R elasticsearch:elasticsearch "$ESCONFIG"
|
|
|
|
assert_file_exist "$ESCONFIG/elasticsearch.yml"
|
2017-04-13 12:00:10 -04:00
|
|
|
assert_file_exist "$ESCONFIG/jvm.options"
|
2016-08-31 15:52:28 -04:00
|
|
|
assert_file_exist "$ESCONFIG/log4j2.properties"
|
2015-08-21 16:05:50 -04:00
|
|
|
}
|
2015-09-01 22:12:18 -04:00
|
|
|
|
2016-03-18 08:25:21 -04:00
|
|
|
# permissions from the user umask with the executable bit set
|
|
|
|
executable_privileges_for_user_from_umask() {
|
|
|
|
local user=$1
|
|
|
|
shift
|
|
|
|
|
|
|
|
echo $((0777 & ~$(sudo -E -u $user sh -c umask) | 0111))
|
|
|
|
}
|
|
|
|
|
|
|
|
# permissions from the user umask without the executable bit set
|
|
|
|
file_privileges_for_user_from_umask() {
|
|
|
|
local user=$1
|
|
|
|
shift
|
|
|
|
|
|
|
|
echo $((0777 & ~$(sudo -E -u $user sh -c umask) & ~0111))
|
|
|
|
}
|
2018-06-25 11:54:39 -04:00
|
|
|
|
|
|
|
# move java to simulate it not being in the path
|
|
|
|
move_java() {
|
|
|
|
which_java=`command -v java`
|
|
|
|
assert_file_exist $which_java
|
|
|
|
mv $which_java ${which_java}.bak
|
|
|
|
}
|
|
|
|
|
|
|
|
# move java back to its original location
|
|
|
|
unmove_java() {
|
|
|
|
which_java=`command -v java.bak`
|
|
|
|
assert_file_exist $which_java
|
|
|
|
mv $which_java `dirname $which_java`/java
|
|
|
|
}
|