Remove default path settings

This commit removes the default path settings for data and logs. With
this change, we now ship the packages with these settings set in the
elasticsearch.yml configuration file rather than going through the
default.path.data and default.path.logs dance that we went through in
the past.

Relates #25408
This commit is contained in:
Jason Tedor 2017-06-26 21:43:20 -04:00 committed by GitHub
parent cca18a2c35
commit dfd241e0a6
19 changed files with 38 additions and 468 deletions

View File

@ -280,26 +280,6 @@ final class Security {
throw new IllegalStateException("unable to access [" + path + "]", e);
}
}
/*
* If path.data and default.path.data are set, we need read access to the paths in default.path.data to check for the existence of
* index directories there that could have arisen from a bug in the handling of simultaneous configuration of path.data and
* default.path.data that was introduced in Elasticsearch 5.3.0.
*
* If path.data is not set then default.path.data would take precedence in setting the data paths for the environment and
* permissions would have been granted above.
*
* If path.data is not set and default.path.data is not set, then we would fallback to the default data directory under
* Elasticsearch home and again permissions would have been granted above.
*
* If path.data is set and default.path.data is not set, there is nothing to do here.
*/
if (Environment.PATH_DATA_SETTING.exists(environment.settings())
&& Environment.DEFAULT_PATH_DATA_SETTING.exists(environment.settings())) {
for (final String path : Environment.DEFAULT_PATH_DATA_SETTING.get(environment.settings())) {
// write permissions are not needed here, we are not going to be writing to any paths here
addPath(policy, Environment.DEFAULT_PATH_DATA_SETTING.getKey(), getPath(path), "read,readlink");
}
}
for (Path path : environment.repoFiles()) {
addPath(policy, Environment.PATH_REPO_SETTING.getKey(), path, "read,readlink,write,delete");
}
@ -309,11 +289,6 @@ final class Security {
}
}
@SuppressForbidden(reason = "read path that is not configured in environment")
private static Path getPath(final String path) {
return PathUtils.get(path);
}
/**
* Add dynamic {@link SocketPermission}s based on HTTP and transport settings.
*
@ -427,27 +402,6 @@ final class Security {
policy.add(new FilePermission(path.toString() + path.getFileSystem().getSeparator() + "-", permissions));
}
/**
* Add access to a directory iff it exists already
* @param policy current policy to add permissions to
* @param configurationName the configuration name associated with the path (for error messages only)
* @param path the path itself
* @param permissions set of file permissions to grant to the path
*/
static void addPathIfExists(Permissions policy, String configurationName, Path path, String permissions) {
if (Files.isDirectory(path)) {
// add each path twice: once for itself, again for files underneath it
policy.add(new FilePermission(path.toString(), permissions));
policy.add(new FilePermission(path.toString() + path.getFileSystem().getSeparator() + "-", permissions));
try {
path.getFileSystem().provider().checkAccess(path.toRealPath(), AccessMode.READ);
} catch (IOException e) {
throw new IllegalStateException("Unable to access '" + configurationName + "' (" + path + ")", e);
}
}
}
/**
* Ensures configured directory {@code path} exists.
* @throws IOException if {@code path} exists, but is not a directory, not accessible, or broken symbolic link.

View File

@ -314,10 +314,8 @@ public final class ClusterSettings extends AbstractScopedSettings {
HunspellService.HUNSPELL_IGNORE_CASE,
HunspellService.HUNSPELL_DICTIONARY_OPTIONS,
IndicesStore.INDICES_STORE_DELETE_SHARD_TIMEOUT,
Environment.DEFAULT_PATH_DATA_SETTING,
Environment.PATH_DATA_SETTING,
Environment.PATH_HOME_SETTING,
Environment.DEFAULT_PATH_LOGS_SETTING,
Environment.PATH_LOGS_SETTING,
Environment.PATH_REPO_SETTING,
Environment.PATH_SHARED_DATA_SETTING,

View File

@ -46,13 +46,10 @@ import java.util.function.Function;
// public+forbidden api!
public class Environment {
public static final Setting<String> PATH_HOME_SETTING = Setting.simpleString("path.home", Property.NodeScope);
public static final Setting<List<String>> DEFAULT_PATH_DATA_SETTING =
Setting.listSetting("default.path.data", Collections.emptyList(), Function.identity(), Property.NodeScope);
public static final Setting<List<String>> PATH_DATA_SETTING =
Setting.listSetting("path.data", DEFAULT_PATH_DATA_SETTING, Function.identity(), Property.NodeScope);
public static final Setting<String> DEFAULT_PATH_LOGS_SETTING = Setting.simpleString("default.path.logs", Property.NodeScope);
Setting.listSetting("path.data", Collections.emptyList(), Function.identity(), Property.NodeScope);
public static final Setting<String> PATH_LOGS_SETTING =
new Setting<>("path.logs", DEFAULT_PATH_LOGS_SETTING, Function.identity(), Property.NodeScope);
new Setting<>("path.logs", "", Function.identity(), Property.NodeScope);
public static final Setting<List<String>> PATH_REPO_SETTING =
Setting.listSetting("path.repo", Collections.emptyList(), Function.identity(), Property.NodeScope);
public static final Setting<String> PATH_SHARED_DATA_SETTING = Setting.simpleString("path.shared_data", Property.NodeScope);
@ -137,7 +134,7 @@ public class Environment {
}
// this is trappy, Setting#get(Settings) will get a fallback setting yet return false for Settings#exists(Settings)
if (PATH_LOGS_SETTING.exists(settings) || DEFAULT_PATH_LOGS_SETTING.exists(settings)) {
if (PATH_LOGS_SETTING.exists(settings)) {
logsFile = PathUtils.get(PATH_LOGS_SETTING.get(settings)).normalize();
} else {
logsFile = homeFile.resolve("logs");

View File

@ -269,9 +269,6 @@ public class Node implements Closeable {
Logger logger = Loggers.getLogger(Node.class, tmpSettings);
final String nodeId = nodeEnvironment.nodeId();
tmpSettings = addNodeNameIfNeeded(tmpSettings, nodeId);
if (DiscoveryNode.nodeRequiresLocalStorage(tmpSettings)) {
checkForIndexDataInDefaultPathData(tmpSettings, nodeEnvironment, logger);
}
// this must be captured after the node name is possibly added to the settings
final String nodeName = NODE_NAME_SETTING.get(tmpSettings);
if (hadPredefinedNodeName == false) {
@ -525,73 +522,6 @@ public class Node implements Closeable {
}
}
/**
* Checks for path.data and default.path.data being configured, and there being index data in any of the paths in default.path.data.
*
* @param settings the settings to check for path.data and default.path.data
* @param nodeEnv the current node environment
* @param logger a logger where messages regarding the detection will be logged
* @throws IOException if an I/O exception occurs reading the directory structure
*/
static void checkForIndexDataInDefaultPathData(
final Settings settings, final NodeEnvironment nodeEnv, final Logger logger) throws IOException {
if (!Environment.PATH_DATA_SETTING.exists(settings) || !Environment.DEFAULT_PATH_DATA_SETTING.exists(settings)) {
return;
}
boolean clean = true;
for (final String defaultPathData : Environment.DEFAULT_PATH_DATA_SETTING.get(settings)) {
final Path defaultNodeDirectory = NodeEnvironment.resolveNodePath(getPath(defaultPathData), nodeEnv.getNodeLockId());
if (Files.exists(defaultNodeDirectory) == false) {
continue;
}
if (isDefaultPathDataInPathData(nodeEnv, defaultNodeDirectory)) {
continue;
}
final NodeEnvironment.NodePath nodePath = new NodeEnvironment.NodePath(defaultNodeDirectory);
final Set<String> availableIndexFolders = nodeEnv.availableIndexFoldersForPath(nodePath);
if (availableIndexFolders.isEmpty()) {
continue;
}
clean = false;
logger.error("detected index data in default.path.data [{}] where there should not be any", nodePath.indicesPath);
for (final String availableIndexFolder : availableIndexFolders) {
logger.info(
"index folder [{}] in default.path.data [{}] must be moved to any of {}",
availableIndexFolder,
nodePath.indicesPath,
Arrays.stream(nodeEnv.nodePaths()).map(np -> np.indicesPath).collect(Collectors.toList()));
}
}
if (clean) {
return;
}
final String message = String.format(
Locale.ROOT,
"detected index data in default.path.data %s where there should not be any; check the logs for details",
Environment.DEFAULT_PATH_DATA_SETTING.get(settings));
throw new IllegalStateException(message);
}
private static boolean isDefaultPathDataInPathData(final NodeEnvironment nodeEnv, final Path defaultNodeDirectory) throws IOException {
for (final NodeEnvironment.NodePath dataPath : nodeEnv.nodePaths()) {
if (Files.isSameFile(dataPath.path, defaultNodeDirectory)) {
return true;
}
}
return false;
}
@SuppressForbidden(reason = "read path that is not configured in environment")
private static Path getPath(final String path) {
return PathUtils.get(path);
}
// visible for testing
static void warnIfPreRelease(final Version version, final boolean isSnapshot, final Logger logger) {
if (!version.isRelease() || isSnapshot) {

View File

@ -73,28 +73,6 @@ public class EnvironmentTests extends ESTestCase {
assertThat(environment.resolveRepoURL(new URL("jar:http://localhost/test/../repo1?blah!/repo/")), nullValue());
}
public void testDefaultPathData() {
final Path defaultPathData = createTempDir().toAbsolutePath();
final Settings settings = Settings.builder()
.put("path.home", createTempDir().toAbsolutePath())
.put("default.path.data", defaultPathData)
.build();
final Environment environment = new Environment(settings);
assertThat(environment.dataFiles(), equalTo(new Path[] { defaultPathData }));
}
public void testPathDataOverrideDefaultPathData() {
final Path pathData = createTempDir().toAbsolutePath();
final Path defaultPathData = createTempDir().toAbsolutePath();
final Settings settings = Settings.builder()
.put("path.home", createTempDir().toAbsolutePath())
.put("path.data", pathData)
.put("default.path.data", defaultPathData)
.build();
final Environment environment = new Environment(settings);
assertThat(environment.dataFiles(), equalTo(new Path[] { pathData }));
}
public void testPathDataWhenNotSet() {
final Path pathHome = createTempDir().toAbsolutePath();
final Settings settings = Settings.builder().put("path.home", pathHome).build();
@ -103,38 +81,10 @@ public class EnvironmentTests extends ESTestCase {
}
public void testPathDataNotSetInEnvironmentIfNotSet() {
final Path defaultPathData = createTempDir().toAbsolutePath();
final Settings settings = Settings.builder()
.put("path.home", createTempDir().toAbsolutePath())
.put("default.path.data", defaultPathData)
.build();
final Settings settings = Settings.builder().put("path.home", createTempDir().toAbsolutePath()).build();
assertFalse(Environment.PATH_DATA_SETTING.exists(settings));
assertTrue(Environment.DEFAULT_PATH_DATA_SETTING.exists(settings));
final Environment environment = new Environment(settings);
assertFalse(Environment.PATH_DATA_SETTING.exists(environment.settings()));
assertTrue(Environment.DEFAULT_PATH_DATA_SETTING.exists(environment.settings()));
}
public void testDefaultPathLogs() {
final Path defaultPathLogs = createTempDir().toAbsolutePath();
final Settings settings = Settings.builder()
.put("path.home", createTempDir().toAbsolutePath())
.put("default.path.logs", defaultPathLogs)
.build();
final Environment environment = new Environment(settings);
assertThat(environment.logsFile(), equalTo(defaultPathLogs));
}
public void testPathLogsOverrideDefaultPathLogs() {
final Path pathLogs = createTempDir().toAbsolutePath();
final Path defaultPathLogs = createTempDir().toAbsolutePath();
final Settings settings = Settings.builder()
.put("path.home", createTempDir().toAbsolutePath())
.put("path.logs", pathLogs)
.put("default.path.logs", defaultPathLogs)
.build();
final Environment environment = new Environment(settings);
assertThat(environment.logsFile(), equalTo(pathLogs));
}
public void testPathLogsWhenNotSet() {

View File

@ -163,72 +163,6 @@ public class NodeTests extends ESTestCase {
}
}
public void testDefaultPathDataSet() throws IOException {
final Path zero = createTempDir().toAbsolutePath();
final Path one = createTempDir().toAbsolutePath();
final Path defaultPathData = createTempDir().toAbsolutePath();
final Settings settings = Settings.builder()
.put("path.home", "/home")
.put("path.data.0", zero)
.put("path.data.1", one)
.put("default.path.data", defaultPathData)
.build();
try (NodeEnvironment nodeEnv = new NodeEnvironment(settings, new Environment(settings))) {
final Path defaultPathDataWithNodesAndId = defaultPathData.resolve("nodes/0");
Files.createDirectories(defaultPathDataWithNodesAndId);
final NodeEnvironment.NodePath defaultNodePath = new NodeEnvironment.NodePath(defaultPathDataWithNodesAndId);
final boolean indexExists = randomBoolean();
final List<String> indices;
if (indexExists) {
indices = IntStream.range(0, randomIntBetween(1, 3)).mapToObj(i -> UUIDs.randomBase64UUID()).collect(Collectors.toList());
for (final String index : indices) {
Files.createDirectories(defaultNodePath.indicesPath.resolve(index));
}
} else {
indices = Collections.emptyList();
}
final Logger mock = mock(Logger.class);
if (indexExists) {
final IllegalStateException e = expectThrows(
IllegalStateException.class,
() -> Node.checkForIndexDataInDefaultPathData(settings, nodeEnv, mock));
final String message = String.format(
Locale.ROOT,
"detected index data in default.path.data [%s] where there should not be any; check the logs for details",
defaultPathData);
assertThat(e, hasToString(containsString(message)));
verify(mock)
.error("detected index data in default.path.data [{}] where there should not be any", defaultNodePath.indicesPath);
for (final String index : indices) {
verify(mock).info(
"index folder [{}] in default.path.data [{}] must be moved to any of {}",
index,
defaultNodePath.indicesPath,
Arrays.stream(nodeEnv.nodePaths()).map(np -> np.indicesPath).collect(Collectors.toList()));
}
verifyNoMoreInteractions(mock);
} else {
Node.checkForIndexDataInDefaultPathData(settings, nodeEnv, mock);
verifyNoMoreInteractions(mock);
}
}
}
public void testDefaultPathDataNotSet() throws IOException {
final Path zero = createTempDir().toAbsolutePath();
final Path one = createTempDir().toAbsolutePath();
final Settings settings = Settings.builder()
.put("path.home", "/home")
.put("path.data.0", zero)
.put("path.data.1", one)
.build();
try (NodeEnvironment nodeEnv = new NodeEnvironment(settings, new Environment(settings))) {
final Logger mock = mock(Logger.class);
Node.checkForIndexDataInDefaultPathData(settings, nodeEnv, mock);
verifyNoMoreInteractions(mock);
}
}
private static Settings.Builder baseSettings() {
final Path tempDir = createTempDir();
return Settings.builder()

View File

@ -496,6 +496,8 @@ task run(type: RunTask) {
*/
Map<String, String> expansionsForDistribution(distributionType) {
final String defaultHeapSize = "2g"
final String packagingPathData = "path.data: /var/lib/elasticsearch"
final String packagingPathLogs = "path.logs: /var/log/elasticsearch"
String footer = "# Built for ${project.name}-${project.version} " +
"(${distributionType})"
@ -509,6 +511,11 @@ Map<String, String> expansionsForDistribution(distributionType) {
'integ-test-zip': '$ES_HOME/config',
'def': '/etc/elasticsearch',
],
'path.data': [
'deb': packagingPathData,
'rpm': packagingPathData,
'def': '#path.data: /path/to/data'
],
'path.env': [
'deb': '/etc/default/elasticsearch',
'rpm': '/etc/sysconfig/elasticsearch',
@ -516,6 +523,11 @@ Map<String, String> expansionsForDistribution(distributionType) {
make an empty string here so the script can properly skip it. */
'def': '',
],
'path.logs': [
'deb': packagingPathLogs,
'rpm': packagingPathLogs,
'def': '#path.logs: /path/to/logs'
],
'heap.min': defaultHeapSize,
'heap.max': defaultHeapSize,

View File

@ -44,12 +44,6 @@ MAX_OPEN_FILES=65536
# Maximum amount of locked memory
#MAX_LOCKED_MEMORY=
# Elasticsearch log directory
LOG_DIR=/var/log/$NAME
# Elasticsearch data directory
DATA_DIR=/var/lib/$NAME
# Elasticsearch configuration directory
CONF_DIR=/etc/$NAME
@ -81,7 +75,7 @@ fi
# Define other required variables
PID_FILE="$PID_DIR/$NAME.pid"
DAEMON=$ES_HOME/bin/elasticsearch
DAEMON_OPTS="-d -p $PID_FILE -Edefault.path.logs=$LOG_DIR -Edefault.path.data=$DATA_DIR --path.conf $CONF_DIR"
DAEMON_OPTS="-d -p $PID_FILE --path.conf $CONF_DIR"
export ES_JAVA_OPTS
export JAVA_HOME

View File

@ -35,8 +35,6 @@ fi
ES_HOME="/usr/share/elasticsearch"
MAX_OPEN_FILES=65536
MAX_MAP_COUNT=262144
LOG_DIR="/var/log/elasticsearch"
DATA_DIR="/var/lib/elasticsearch"
CONF_DIR="${path.conf}"
PID_DIR="/var/run/elasticsearch"
@ -114,7 +112,7 @@ start() {
cd $ES_HOME
echo -n $"Starting $prog: "
# if not running, start it up here, usually something like "daemon $exec"
daemon --user elasticsearch --pidfile $pidfile $exec -p $pidfile -d -Edefault.path.logs=$LOG_DIR -Edefault.path.data=$DATA_DIR --path.conf $CONF_DIR
daemon --user elasticsearch --pidfile $pidfile $exec -p $pidfile -d --path.conf $CONF_DIR
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile

View File

@ -11,12 +11,6 @@
# Elasticsearch configuration directory
#CONF_DIR=${path.conf}
# Elasticsearch data directory
#DATA_DIR=/var/lib/elasticsearch
# Elasticsearch logs directory
#LOG_DIR=/var/log/elasticsearch
# Elasticsearch PID directory
#PID_DIR=/var/run/elasticsearch

View File

@ -7,8 +7,6 @@ After=network-online.target
[Service]
Environment=ES_HOME=/usr/share/elasticsearch
Environment=CONF_DIR=${path.conf}
Environment=DATA_DIR=/var/lib/elasticsearch
Environment=LOG_DIR=/var/log/elasticsearch
Environment=PID_DIR=/var/run/elasticsearch
EnvironmentFile=-${path.env}
@ -22,8 +20,6 @@ ExecStartPre=/usr/share/elasticsearch/bin/elasticsearch-systemd-pre-exec
ExecStart=/usr/share/elasticsearch/bin/elasticsearch \
-p ${PID_DIR}/elasticsearch.pid \
--quiet \
-Edefault.path.logs=${LOG_DIR} \
-Edefault.path.data=${DATA_DIR} \
--path.conf ${CONF_DIR}
# StandardOutput is configured to redirect to journalctl since

View File

@ -54,7 +54,7 @@ echo elasticsearch-service-(x86|x64).exe was not found...
:okExe
set ES_VERSION=${project.version}
if "%LOG_DIR%" == "" set LOG_DIR=%ES_HOME%\logs
if "%SERVICE_LOG_DIR%" == "" set SERVICE_LOG_DIR=%ES_HOME%\logs
if "x%1x" == "xx" goto displayUsage
set SERVICE_CMD=%1
@ -64,7 +64,7 @@ set SERVICE_ID=%1
:checkServiceCmd
if "%LOG_OPTS%" == "" set LOG_OPTS=--LogPath "%LOG_DIR%" --LogPrefix "%SERVICE_ID%" --StdError auto --StdOutput auto
if "%LOG_OPTS%" == "" set LOG_OPTS=--LogPath "%SERVICE_LOG_DIR%" --LogPrefix "%SERVICE_ID%" --StdError auto --StdOutput auto
if /i %SERVICE_CMD% == install goto doInstall
if /i %SERVICE_CMD% == remove goto doRemove
@ -222,11 +222,10 @@ if "%JVM_SS%" == "" (
)
CALL "%ES_HOME%\bin\elasticsearch.in.bat"
if "%DATA_DIR%" == "" set DATA_DIR=%ES_HOME%\data
if "%CONF_DIR%" == "" set CONF_DIR=%ES_HOME%\config
set ES_PARAMS=-Delasticsearch;-Des.path.home="%ES_HOME%";-Des.default.path.logs="%LOG_DIR%";-Des.default.path.data="%DATA_DIR%"
set ES_PARAMS=-Delasticsearch;-Des.path.home="%ES_HOME%"
if "%ES_START_TYPE%" == "" set ES_START_TYPE=manual
if "%ES_STOP_TIMEOUT%" == "" set ES_STOP_TIMEOUT=0

View File

@ -30,11 +30,11 @@
#
# Path to directory where to store the data (separate multiple locations by comma):
#
#path.data: /path/to/data
${path.data}
#
# Path to log files:
#
#path.logs: /path/to/logs
${path.logs}
#
# ----------------------------------- Memory -----------------------------------
#

View File

@ -19,3 +19,13 @@ Elasticsearch should use another config file. Instead, `path.conf` is now a
command-line flag. To start Elasticsearch with a custom config file, use `-c
/path/to/config` or `--path.conf /path/to/config`. Here, `/path/to/config` is
the *directory* containing the config file.
==== Default path settings are removed
Previous versions of Elasticsearch enabled setting `default.path.data` and
`default.path.logs` to set the default data path and default logs path if they
were not otherwise set in the configuration file. These settings have been
removed and now data paths and log paths can be configured via settings
only. Related, this means that the environment variables `DATA_DIR` and
`LOG_DIR` no longer have any effect as these were used to set
`default.path.data` and `default.path.logs` in the packaging scripts.

View File

@ -21,14 +21,6 @@
about `max_map_count`. This is set via `sysctl` before starting
elasticsearch. Defaults to `262144`.
`LOG_DIR`::
Log directory, defaults to `/var/log/elasticsearch`.
`DATA_DIR`::
Data directory, defaults to `/var/lib/elasticsearch`.
`CONF_DIR`::
Configuration file directory (which needs to include `elasticsearch.yml`

View File

@ -163,13 +163,12 @@ The Elasticsearch service can be configured prior to installation by setting the
The installation directory of the desired JVM to run the service under.
`LOG_DIR`::
`SERVICE_LOG_DIR`::
Log directory, defaults to `%ES_HOME%\logs`.
`DATA_DIR`::
Data directory, defaults to `%ES_HOME%\data`.
Service log directory, defaults to `%ES_HOME%\logs`. Note that this does
not control the path for the Elasticsearch logs; the path for these is set
via the setting `path.logs` in the `elasticsearch.yml` configuration file,
or on the command line.
`CONF_DIR`::

View File

@ -1,84 +0,0 @@
/*
* 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.
*/
package org.elasticsearch.node;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.util.Constants;
import org.elasticsearch.common.UUIDs;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.test.ESTestCase;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyNoMoreInteractions;
public class EvilNodeTests extends ESTestCase {
public void testDefaultPathDataIncludedInPathData() throws IOException {
final Path zero = createTempDir().toAbsolutePath();
final Path one = createTempDir().toAbsolutePath();
// creating hard links to directories is okay on macOS so we exercise it here
final int random;
if (Constants.MAC_OS_X) {
random = randomFrom(0, 1, 2);
} else {
random = randomFrom(0, 1);
}
final Path defaultPathData;
final Path choice = randomFrom(zero, one);
switch (random) {
case 0:
defaultPathData = choice;
break;
case 1:
defaultPathData = createTempDir().toAbsolutePath().resolve("link");
Files.createSymbolicLink(defaultPathData, choice);
break;
case 2:
defaultPathData = createTempDir().toAbsolutePath().resolve("link");
Files.createLink(defaultPathData, choice);
break;
default:
throw new AssertionError(Integer.toString(random));
}
final Settings settings = Settings.builder()
.put("path.home", createTempDir().toAbsolutePath())
.put("path.data.0", zero)
.put("path.data.1", one)
.put("default.path.data", defaultPathData)
.build();
try (NodeEnvironment nodeEnv = new NodeEnvironment(settings, new Environment(settings))) {
final Path defaultPathDataWithNodesAndId = defaultPathData.resolve("nodes/0");
Files.createDirectories(defaultPathDataWithNodesAndId);
final NodeEnvironment.NodePath defaultNodePath = new NodeEnvironment.NodePath(defaultPathDataWithNodesAndId);
Files.createDirectories(defaultNodePath.indicesPath.resolve(UUIDs.randomBase64UUID()));
final Logger mock = mock(Logger.class);
// nothing should happen here
Node.checkForIndexDataInDefaultPathData(settings, nodeEnv, mock);
verifyNoMoreInteractions(mock);
}
}
}

View File

@ -118,27 +118,6 @@ setup() {
[ "$status" -eq 3 ] || [ "$status" -eq 4 ]
}
@test "[INIT.D] don't mkdir when it contains a comma" {
# Remove these just in case they exist beforehand
rm -rf /tmp/aoeu,/tmp/asdf
rm -rf /tmp/aoeu,
# set DATA_DIR to DATA_DIR=/tmp/aoeu,/tmp/asdf
sed -i 's/DATA_DIR=.*/DATA_DIR=\/tmp\/aoeu,\/tmp\/asdf/' /etc/init.d/elasticsearch
cat /etc/init.d/elasticsearch | grep "DATA_DIR"
run service elasticsearch start
if [ "$status" -ne 0 ]; then
cat /var/log/elasticsearch/*
fail
fi
wait_for_elasticsearch_status
assert_file_not_exist /tmp/aoeu,/tmp/asdf
assert_file_not_exist /tmp/aoeu,
service elasticsearch stop
run service elasticsearch status
# precise returns 4, trusty 3
[ "$status" -eq 3 ] || [ "$status" -eq 4 ]
}
@test "[INIT.D] start Elasticsearch with custom JVM options" {
assert_file_exist $ESENVFILE
local es_java_opts=$ES_JAVA_OPTS

View File

@ -1,82 +0,0 @@
#!/usr/bin/env bats
# Tests data.path settings which in the past have misbehaving, leaking the
# default.data.path setting into the data.path even when it doesn't belong.
# WARNING: This testing file must be executed as root and can
# 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
}
# The test case can be executed with the Bash Automated
# Testing System tool available at https://github.com/sstephenson/bats
# Thanks to Sam Stephenson!
# 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.
# Load test utilities
load $BATS_UTILS/packages.bash
load $BATS_UTILS/tar.bash
load $BATS_UTILS/utils.bash
@test "[BAD data.path] install package" {
clean_before_test
skip_not_dpkg_or_rpm
install_package
}
@test "[BAD data.path] setup funny path.data in package install" {
skip_not_dpkg_or_rpm
local temp=`mktemp -d`
chown elasticsearch:elasticsearch "$temp"
echo "path.data: [$temp]" > "/etc/elasticsearch/elasticsearch.yml"
}
@test "[BAD data.path] start installed from package" {
skip_not_dpkg_or_rpm
start_elasticsearch_service green
}
@test "[BAD data.path] check for bad dir after starting from package" {
skip_not_dpkg_or_rpm
assert_file_not_exist /var/lib/elasticsearch/nodes
}
@test "[BAD data.path] install tar" {
clean_before_test
install_archive
}
@test "[BAD data.path] setup funny path.data in tar install" {
local temp=`mktemp -d`
chown elasticsearch:elasticsearch "$temp"
echo "path.data: [$temp]" > "/tmp/elasticsearch/config/elasticsearch.yml"
}
@test "[BAD data.path] start installed from tar" {
start_elasticsearch_service green "" "-Edefault.path.data=/tmp/elasticsearch/data"
}
@test "[BAD data.path] check for bad dir after starting from tar" {
assert_file_not_exist "/tmp/elasticsearch/data/nodes"
}