Skip to content

Commit

Permalink
Attempt to catch cases of incorrect datadir ownership
Browse files Browse the repository at this point in the history
If the Elasticsearch datadir is not owned by the user specified in
$DOCKER_USER, Elasticsearch will fail to start.

Since #55 the helper scripts
attempt to remedy this situation if the `pelias` script is run as root
(which is not recommended but is often done).

However, if the `pelias` script is not run as root and the permissions
are incorrect, this situation cannot be automatically fixed.

This code attempts to detect that case and recommend the proper command
to run (with sudo) and set proper directory permissions.

Connects #31
Connects #73
  • Loading branch information
orangejulius committed Mar 6, 2019
1 parent bdba26a commit 0067fdb
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cmd/elastic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,25 @@ set -e;

function elastic_schema_drop(){ compose_run 'schema' node scripts/drop_index "$@" || true; }
function elastic_schema_create(){ compose_run 'schema' ./bin/create_index; }

# perform pre-start checks and start the elasticsearch container
function elastic_start(){
mkdir -p $DATA_DIR/elasticsearch
# attemp to set proper permissions if running as root
chown $DOCKER_USER $DATA_DIR/elasticsearch 2>/dev/null || true

# record the owner of the Elasticsearch directory
elasticsearch_owner_uid=$(stat --format '%u' $DATA_DIR/elasticsearch)

# grab just the first part of the $DOCKER_USER variable which may have format uid:gid (or just uid)
desired_owner_uid=(${DOCKER_USER//:/ })

# check permissions, and if $DOCKER_USER cannot read the data dir, quit with error
if [[ "$desired_owner_uid" != "$elasticsearch_owner_uid" ]]; then
echo "user $DOCKER_USER cannot access elasticsearch directory at $DATA_DIR"
echo "please run 'sudo chown $DOCKER_USER $DATA_DIR/elasticsearch'"
exit 1
fi
compose_exec up -d elasticsearch
}

Expand Down

0 comments on commit 0067fdb

Please sign in to comment.