Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional port parameter to Elasticsearch management functions #360

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions cmd/elastic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function elastic_schema_drop(){ compose_run 'schema' node scripts/drop_index "$@
function elastic_schema_create(){ compose_run 'schema' ./bin/create_index; }
function elastic_start(){
mkdir -p $DATA_DIR/elasticsearch
# attemp to set proper permissions if running as root
# Attempt to set proper permissions if running as root
chown $DOCKER_USER $DATA_DIR/elasticsearch 2>/dev/null || true
compose_exec up -d elasticsearch
}
Expand All @@ -24,11 +24,11 @@ function elastic_status(){
--output /dev/null \
--silent \
--write-out "%{http_code}" \
"http://${ELASTIC_HOST:-localhost:9200}/_cluster/health?wait_for_status=yellow&timeout=1s" \
"http://${ELASTIC_HOST:-localhost}:${ELASTIC_PORT:-9200}/_cluster/health?wait_for_status=yellow&timeout=1s" \
|| true;
}

# the same function but with a trailing newline
# Function to get HTTP status with a trailing newline, using optional port
function elastic_status_newline(){ echo $(elastic_status); }
register 'elastic' 'status' 'HTTP status code of the elasticsearch service' elastic_status_newline

Expand All @@ -39,10 +39,10 @@ function elastic_wait(){
i=1
while [[ "$i" -le "$retry_count" ]]; do
if [[ $(elastic_status) -eq 200 ]]; then
echo "Elasticsearch up!"
echo "Elasticsearch up on port ${ELASTIC_PORT:-9200}!"
exit 0
elif [[ $(elastic_status) -eq 408 ]]; then
# 408 indicates the server is up but not yet yellow status
# 408 indicates the server is up but has not reached yellow status yet
printf ":"
else
printf "."
Expand All @@ -58,11 +58,13 @@ function elastic_wait(){

register 'elastic' 'wait' 'wait for elasticsearch to start up' elastic_wait

function elastic_info(){ curl -s "http://${ELASTIC_HOST:-localhost:9200}/"; }
# Function to get Elasticsearch version and build info with an optional port argument
function elastic_info(){ curl -s "http://${ELASTIC_HOST:-localhost}:${ELASTIC_PORT:-9200}/"; }
register 'elastic' 'info' 'display elasticsearch version and build info' elastic_info

# Function to display a summary of document counts per source/layer with optional port
function elastic_stats(){
curl -s "http://${ELASTIC_HOST:-localhost:9200}/pelias/_search?request_cache=true&timeout=10s&pretty=true" \
curl -s "http://${ELASTIC_HOST:-localhost}:${ELASTIC_PORT:-9200}/pelias/_search?request_cache=true&timeout=10s&pretty=true" \
-H 'Content-Type: application/json' \
-d '{
"aggs": {
Expand Down