Don't run `mkdir` when $DATA_DIR contains a comma-separated list

Resolves #16992
Resolves https://github.com/elastic/cookbook-elasticsearch/issues/441
This commit is contained in:
Lee Hinman 2016-03-30 12:42:58 -06:00
parent 864ba8dac1
commit ff5c7965ed
2 changed files with 24 additions and 1 deletions

View File

@ -117,7 +117,13 @@ case "$1" in
fi
# Prepare environment
mkdir -p "$LOG_DIR" "$DATA_DIR" && chown "$ES_USER":"$ES_GROUP" "$LOG_DIR" "$DATA_DIR"
# Check $DATA_DIR for a comma
if [ "${DATA_DIR#*,}" != "$DATA_DIR" ]; then
# $DATA_DIR contains a comma, so we should not mkdir it
mkdir -p "$LOG_DIR" && chown "$ES_USER":"$ES_GROUP" "$LOG_DIR"
else
mkdir -p "$LOG_DIR" "$DATA_DIR" && chown "$ES_USER":"$ES_GROUP" "$LOG_DIR" "$DATA_DIR"
fi
# Ensure that the PID_DIR exists (it is cleaned at OS startup time)
if [ -n "$PID_DIR" ] && [ ! -e "$PID_DIR" ]; then

View File

@ -117,6 +117,23 @@ 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"
service elasticsearch start
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 ]
}
# Simulates the behavior of a system restart:
# the PID directory is deleted by the operating system
# but it should not block ES from starting