2016-05-18 11:03:00 -04:00
|
|
|
#!/bin/bash
|
2015-09-01 22:12:18 -04:00
|
|
|
|
|
|
|
# This file contains some utilities to test the elasticsearch scripts with
|
|
|
|
# the .deb/.rpm packages.
|
|
|
|
|
|
|
|
# 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-09-01 22:12:18 -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.
|
|
|
|
|
|
|
|
|
|
|
|
# Export some useful paths.
|
|
|
|
export_elasticsearch_paths() {
|
|
|
|
export ESHOME="/usr/share/elasticsearch"
|
|
|
|
export ESPLUGINS="$ESHOME/plugins"
|
2016-03-16 19:29:16 -04:00
|
|
|
export ESMODULES="$ESHOME/modules"
|
2015-09-01 22:12:18 -04:00
|
|
|
export ESCONFIG="/etc/elasticsearch"
|
|
|
|
export ESDATA="/var/lib/elasticsearch"
|
|
|
|
export ESLOG="/var/log/elasticsearch"
|
|
|
|
export ESPIDDIR="/var/run/elasticsearch"
|
2016-11-10 05:11:47 -05:00
|
|
|
if is_dpkg; then
|
|
|
|
export ESENVFILE="/etc/default/elasticsearch"
|
|
|
|
fi
|
|
|
|
if is_rpm; then
|
|
|
|
export ESENVFILE="/etc/sysconfig/elasticsearch"
|
|
|
|
fi
|
2018-02-23 11:03:17 -05:00
|
|
|
export PACKAGE_NAME=${PACKAGE_NAME:-"elasticsearch-oss"}
|
2015-09-01 22:12:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Install the rpm or deb package.
|
|
|
|
# -u upgrade rather than install. This only matters for rpm.
|
|
|
|
# -v the version to upgrade to. Defaults to the version under test.
|
|
|
|
install_package() {
|
|
|
|
local version=$(cat version)
|
|
|
|
local rpmCommand='-i'
|
2016-09-13 11:52:06 -04:00
|
|
|
while getopts ":fuv:" opt; do
|
2015-09-01 22:12:18 -04:00
|
|
|
case $opt in
|
|
|
|
u)
|
|
|
|
rpmCommand='-U'
|
2016-03-24 09:21:33 -04:00
|
|
|
dpkgCommand='--force-confnew'
|
2015-09-01 22:12:18 -04:00
|
|
|
;;
|
2016-09-13 11:52:06 -04:00
|
|
|
f)
|
|
|
|
rpmCommand='-U --force'
|
|
|
|
dpkgCommand='--force-conflicts'
|
|
|
|
;;
|
2015-09-01 22:12:18 -04:00
|
|
|
v)
|
|
|
|
version=$OPTARG
|
|
|
|
;;
|
|
|
|
\?)
|
|
|
|
echo "Invalid option: -$OPTARG" >&2
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
if is_rpm; then
|
2018-02-23 11:03:17 -05:00
|
|
|
rpm $rpmCommand $PACKAGE_NAME-$version.rpm
|
2015-09-01 22:12:18 -04:00
|
|
|
elif is_dpkg; then
|
2018-11-27 09:06:10 -05:00
|
|
|
run dpkg $dpkgCommand -i $PACKAGE_NAME-$version.deb
|
|
|
|
[[ "$status" -eq 0 ]] || {
|
|
|
|
echo "dpkg failed:"
|
|
|
|
echo "$output"
|
|
|
|
run lsof /var/lib/dpkg/lock
|
|
|
|
echo "lsof /var/lib/dpkg/lock:"
|
|
|
|
echo "$output"
|
|
|
|
false
|
|
|
|
}
|
2015-09-01 22:12:18 -04:00
|
|
|
else
|
|
|
|
skip "Only rpm or deb supported"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Checks that all directories & files are correctly installed after a deb or
|
|
|
|
# rpm install.
|
|
|
|
verify_package_installation() {
|
|
|
|
id elasticsearch
|
|
|
|
|
|
|
|
getent group elasticsearch
|
2018-05-02 17:33:34 -04:00
|
|
|
# homedir is set in /etc/passwd but to a non existent directory
|
|
|
|
assert_file_not_exist $(getent passwd elasticsearch | cut -d: -f6)
|
2015-09-01 22:12:18 -04:00
|
|
|
|
2015-10-08 04:43:38 -04:00
|
|
|
assert_file "$ESHOME" d root root 755
|
|
|
|
assert_file "$ESHOME/bin" d root root 755
|
2016-10-24 03:42:03 -04:00
|
|
|
assert_file "$ESHOME/bin/elasticsearch" f root root 755
|
|
|
|
assert_file "$ESHOME/bin/elasticsearch-plugin" f root root 755
|
2018-09-19 04:28:22 -04:00
|
|
|
assert_file "$ESHOME/bin/elasticsearch-shard" f root root 755
|
2015-10-08 04:43:38 -04:00
|
|
|
assert_file "$ESHOME/lib" d root root 755
|
2017-08-28 20:47:42 -04:00
|
|
|
assert_file "$ESCONFIG" d root elasticsearch 2750
|
2018-03-12 12:48:00 -04:00
|
|
|
assert_file "$ESCONFIG/elasticsearch.keystore" f root elasticsearch 660
|
|
|
|
|
|
|
|
sudo -u elasticsearch "$ESHOME/bin/elasticsearch-keystore" list | grep "keystore.seed"
|
|
|
|
|
|
|
|
assert_file "$ESCONFIG/.elasticsearch.keystore.initial_md5sum" f root elasticsearch 644
|
2016-10-24 03:42:03 -04:00
|
|
|
assert_file "$ESCONFIG/elasticsearch.yml" f root elasticsearch 660
|
|
|
|
assert_file "$ESCONFIG/jvm.options" f root elasticsearch 660
|
|
|
|
assert_file "$ESCONFIG/log4j2.properties" f root elasticsearch 660
|
|
|
|
assert_file "$ESDATA" d elasticsearch elasticsearch 750
|
|
|
|
assert_file "$ESLOG" d elasticsearch elasticsearch 750
|
2016-03-17 15:35:21 -04:00
|
|
|
assert_file "$ESPLUGINS" d root root 755
|
2016-03-16 19:29:16 -04:00
|
|
|
assert_file "$ESMODULES" d root root 755
|
2015-10-08 04:43:38 -04:00
|
|
|
assert_file "$ESPIDDIR" d elasticsearch elasticsearch 755
|
|
|
|
assert_file "$ESHOME/NOTICE.txt" f root root 644
|
|
|
|
assert_file "$ESHOME/README.textile" f root root 644
|
2015-09-01 22:12:18 -04:00
|
|
|
|
|
|
|
if is_dpkg; then
|
|
|
|
# Env file
|
2017-07-20 20:38:49 -04:00
|
|
|
assert_file "/etc/default/elasticsearch" f root elasticsearch 660
|
2015-09-01 22:12:18 -04:00
|
|
|
|
2018-04-25 12:52:37 -04:00
|
|
|
# Machine-readable debian/copyright file
|
|
|
|
local copyrightDir=$(readlink -f /usr/share/doc/$PACKAGE_NAME)
|
|
|
|
assert_file $copyrightDir d root root 755
|
|
|
|
assert_file "$copyrightDir/copyright" f root root 644
|
2015-09-01 22:12:18 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
if is_rpm; then
|
|
|
|
# Env file
|
2017-07-20 20:38:49 -04:00
|
|
|
assert_file "/etc/sysconfig/elasticsearch" f root elasticsearch 660
|
2015-09-01 22:12:18 -04:00
|
|
|
# License file
|
2015-10-08 04:43:38 -04:00
|
|
|
assert_file "/usr/share/elasticsearch/LICENSE.txt" f root root 644
|
2015-09-01 22:12:18 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
if is_systemd; then
|
2015-10-08 04:43:38 -04:00
|
|
|
assert_file "/usr/lib/systemd/system/elasticsearch.service" f root root 644
|
|
|
|
assert_file "/usr/lib/tmpfiles.d/elasticsearch.conf" f root root 644
|
|
|
|
assert_file "/usr/lib/sysctl.d/elasticsearch.conf" f root root 644
|
2016-11-12 07:03:45 -05:00
|
|
|
if is_rpm; then
|
|
|
|
[[ $(/usr/sbin/sysctl vm.max_map_count) =~ "vm.max_map_count = 262144" ]]
|
|
|
|
else
|
|
|
|
[[ $(/sbin/sysctl vm.max_map_count) =~ "vm.max_map_count = 262144" ]]
|
|
|
|
fi
|
2015-09-01 22:12:18 -04:00
|
|
|
fi
|
2016-10-24 03:42:03 -04:00
|
|
|
|
|
|
|
if is_sysvinit; then
|
|
|
|
assert_file "/etc/init.d/elasticsearch" f root root 750
|
|
|
|
fi
|
|
|
|
|
|
|
|
run sudo -E -u vagrant LANG="en_US.UTF-8" cat "$ESCONFIG/elasticsearch.yml"
|
|
|
|
[ $status = 1 ]
|
|
|
|
[[ "$output" == *"Permission denied"* ]] || {
|
|
|
|
echo "Expected permission denied but found $output:"
|
|
|
|
false
|
|
|
|
}
|
2015-09-01 22:12:18 -04:00
|
|
|
}
|