Skip to content

Commit 0067fdb

Browse files
committed
Attempt to catch cases of incorrect datadir ownership
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
1 parent bdba26a commit 0067fdb

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

cmd/elastic.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,25 @@ set -e;
33

44
function elastic_schema_drop(){ compose_run 'schema' node scripts/drop_index "$@" || true; }
55
function elastic_schema_create(){ compose_run 'schema' ./bin/create_index; }
6+
7+
# perform pre-start checks and start the elasticsearch container
68
function elastic_start(){
79
mkdir -p $DATA_DIR/elasticsearch
810
# attemp to set proper permissions if running as root
911
chown $DOCKER_USER $DATA_DIR/elasticsearch 2>/dev/null || true
12+
13+
# record the owner of the Elasticsearch directory
14+
elasticsearch_owner_uid=$(stat --format '%u' $DATA_DIR/elasticsearch)
15+
16+
# grab just the first part of the $DOCKER_USER variable which may have format uid:gid (or just uid)
17+
desired_owner_uid=(${DOCKER_USER//:/ })
18+
19+
# check permissions, and if $DOCKER_USER cannot read the data dir, quit with error
20+
if [[ "$desired_owner_uid" != "$elasticsearch_owner_uid" ]]; then
21+
echo "user $DOCKER_USER cannot access elasticsearch directory at $DATA_DIR"
22+
echo "please run 'sudo chown $DOCKER_USER $DATA_DIR/elasticsearch'"
23+
exit 1
24+
fi
1025
compose_exec up -d elasticsearch
1126
}
1227

0 commit comments

Comments
 (0)