From 74a8302297cb162f75d7ebea4b6e12fddc2289d6 Mon Sep 17 00:00:00 2001 From: Be-Mann <25839760+Be-Mann@users.noreply.github.com> Date: Wed, 23 Oct 2024 17:56:49 +0200 Subject: [PATCH 01/14] Add optional port parameter to Elasticsearch management functions - Introduced an optional port parameter to various Elasticsearch management functions (status, info, stats, wait) to allow flexibility in handling multiple instances running on different ports. - Implemented a fallback mechanism that defaults to port 9200 when no port is specified. - Updated all relevant functions to accept and use the provided port or fall back to the default. - Added comments in English to enhance clarity and maintainability of the script. --- cmd/elastic.sh | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/cmd/elastic.sh b/cmd/elastic.sh index 701c19c9..19c7ec71 100644 --- a/cmd/elastic.sh +++ b/cmd/elastic.sh @@ -1,11 +1,20 @@ #!/bin/bash set -e; +# Function to determine the Elasticsearch port with a fallback to the default port +function get_elastic_port(){ + if [[ -n "$1" ]]; then + echo "$1" + else + echo "9200" + fi +} + function elastic_schema_drop(){ compose_run 'schema' node scripts/drop_index "$@" || true; } 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 } @@ -17,32 +26,35 @@ register 'elastic' 'create' 'create elasticsearch index with pelias mapping' ela register 'elastic' 'start' 'start elasticsearch server' elastic_start register 'elastic' 'stop' 'stop elasticsearch server' elastic_stop -# to use this function: -# if test $(elastic_status) -ne 200; then +# Function to get HTTP status of Elasticsearch, with an optional port argument function elastic_status(){ + local port=$(get_elastic_port "$1") curl \ --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}:${port}/_cluster/health?wait_for_status=yellow&timeout=1s" \ || true; } -# the same function but with a trailing newline -function elastic_status_newline(){ echo $(elastic_status); } +# 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 function elastic_wait(){ echo 'waiting for elasticsearch service to come up'; retry_count=30 + local port=$(get_elastic_port "$1") i=1 while [[ "$i" -le "$retry_count" ]]; do - if [[ $(elastic_status) -eq 200 ]]; then - echo "Elasticsearch up!" + if [[ $(elastic_status "$port") -eq 200 ]]; then + echo "Elasticsearch up on port $port!" exit 0 - elif [[ $(elastic_status) -eq 408 ]]; then - # 408 indicates the server is up but not yet yellow status + elif [[ $(elastic_status "$port") -eq 408 ]]; then + # 408 indicates the server is up but has not reached yellow status yet printf ":" else printf "." @@ -58,11 +70,17 @@ 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(){ + local port=$(get_elastic_port "$1") + curl -s "http://${ELASTIC_HOST:-localhost}:${port}/"; +} 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" \ + local port=$(get_elastic_port "$1") + curl -s "http://${ELASTIC_HOST:-localhost}:${port}/pelias/_search?request_cache=true&timeout=10s&pretty=true" \ -H 'Content-Type: application/json' \ -d '{ "aggs": { From f174e5391334dea691c4a457dec43d9b2f76b363 Mon Sep 17 00:00:00 2001 From: Be-Mann <25839760+Be-Mann@users.noreply.github.com> Date: Thu, 24 Oct 2024 16:28:34 +0200 Subject: [PATCH 02/14] Ensure Consistent Usage of Environment Variables for Elasticsearch Host and Port Configuration ### What was specifically improved? - **Consistency in configuration**: Instead of passing the port as an argument or via a function, you now use an environment variable (`ELASTIC_PORT`), just like for the host. This brings consistency, allowing users to set both the host and port using environment variables, which fits better into automated environments like Docker. - **Simplification of code**: Since the `get_elastic_port` function was removed, the code becomes less complex, and reusing environment variables reduces unnecessary argument passing and functionality. --- cmd/elastic.sh | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/cmd/elastic.sh b/cmd/elastic.sh index 19c7ec71..4f092e05 100644 --- a/cmd/elastic.sh +++ b/cmd/elastic.sh @@ -1,15 +1,6 @@ #!/bin/bash set -e; -# Function to determine the Elasticsearch port with a fallback to the default port -function get_elastic_port(){ - if [[ -n "$1" ]]; then - echo "$1" - else - echo "9200" - fi -} - function elastic_schema_drop(){ compose_run 'schema' node scripts/drop_index "$@" || true; } function elastic_schema_create(){ compose_run 'schema' ./bin/create_index; } function elastic_start(){ @@ -28,12 +19,11 @@ register 'elastic' 'stop' 'stop elasticsearch server' elastic_stop # Function to get HTTP status of Elasticsearch, with an optional port argument function elastic_status(){ - local port=$(get_elastic_port "$1") curl \ --output /dev/null \ --silent \ --write-out "%{http_code}" \ - "http://${ELASTIC_HOST:-localhost}:${port}/_cluster/health?wait_for_status=yellow&timeout=1s" \ + "http://${ELASTIC_HOST:-localhost}:${ELASTIC_PORT:-9200}/_cluster/health?wait_for_status=yellow&timeout=1s" \ || true; } @@ -46,14 +36,13 @@ register 'elastic' 'status' 'HTTP status code of the elasticsearch service' elas function elastic_wait(){ echo 'waiting for elasticsearch service to come up'; retry_count=30 - local port=$(get_elastic_port "$1") i=1 while [[ "$i" -le "$retry_count" ]]; do - if [[ $(elastic_status "$port") -eq 200 ]]; then - echo "Elasticsearch up on port $port!" + if [[ $(elastic_status") -eq 200 ]]; then + echo "Elasticsearch up on port ${ELASTIC_PORT:-9200}!" exit 0 - elif [[ $(elastic_status "$port") -eq 408 ]]; then + elif [[ $(elastic_status") -eq 408 ]]; then # 408 indicates the server is up but has not reached yellow status yet printf ":" else @@ -72,15 +61,13 @@ register 'elastic' 'wait' 'wait for elasticsearch to start up' elastic_wait # Function to get Elasticsearch version and build info with an optional port argument function elastic_info(){ - local port=$(get_elastic_port "$1") - curl -s "http://${ELASTIC_HOST:-localhost}:${port}/"; + 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(){ - local port=$(get_elastic_port "$1") - curl -s "http://${ELASTIC_HOST:-localhost}:${port}/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": { From c4d9bc622ce755094b08f6f52bb2bd7afe6e85c4 Mon Sep 17 00:00:00 2001 From: Be-Mann <25839760+Be-Mann@users.noreply.github.com> Date: Thu, 24 Oct 2024 16:31:10 +0200 Subject: [PATCH 03/14] Syntax fix --- cmd/elastic.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/elastic.sh b/cmd/elastic.sh index 4f092e05..c20de842 100644 --- a/cmd/elastic.sh +++ b/cmd/elastic.sh @@ -39,10 +39,10 @@ function elastic_wait(){ i=1 while [[ "$i" -le "$retry_count" ]]; do - if [[ $(elastic_status") -eq 200 ]]; then + if [[ $(elastic_status) -eq 200 ]]; then echo "Elasticsearch up on port ${ELASTIC_PORT:-9200}!" exit 0 - elif [[ $(elastic_status") -eq 408 ]]; then + elif [[ $(elastic_status) -eq 408 ]]; then # 408 indicates the server is up but has not reached yellow status yet printf ":" else From f5e87e289e266bcc1c17ad49156c1a063d98b9e3 Mon Sep 17 00:00:00 2001 From: Be-Mann <25839760+Be-Mann@users.noreply.github.com> Date: Thu, 24 Oct 2024 16:37:55 +0200 Subject: [PATCH 04/14] Formatting adaptation to existing --- cmd/elastic.sh | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/cmd/elastic.sh b/cmd/elastic.sh index c20de842..f627d279 100644 --- a/cmd/elastic.sh +++ b/cmd/elastic.sh @@ -17,7 +17,8 @@ register 'elastic' 'create' 'create elasticsearch index with pelias mapping' ela register 'elastic' 'start' 'start elasticsearch server' elastic_start register 'elastic' 'stop' 'stop elasticsearch server' elastic_stop -# Function to get HTTP status of Elasticsearch, with an optional port argument +# to use this function: +# if test $(elastic_status) -ne 200; then function elastic_status(){ curl \ --output /dev/null \ @@ -28,9 +29,7 @@ function elastic_status(){ } # Function to get HTTP status with a trailing newline, using optional port -function elastic_status_newline(){ - echo $(elastic_status "$@") -} +function elastic_status_newline(){ echo $(elastic_status); } register 'elastic' 'status' 'HTTP status code of the elasticsearch service' elastic_status_newline function elastic_wait(){ @@ -60,9 +59,7 @@ function elastic_wait(){ register 'elastic' 'wait' 'wait for elasticsearch to start up' elastic_wait # 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}/"; -} +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 From 1ba3fe997a3b9890d7e2ffb75755952efae79b73 Mon Sep 17 00:00:00 2001 From: Be-Mann <25839760+Be-Mann@users.noreply.github.com> Date: Wed, 4 Dec 2024 17:35:51 +0100 Subject: [PATCH 05/14] Create generate.sh --- projects/germany /generate.sh | 161 ++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 projects/germany /generate.sh diff --git a/projects/germany /generate.sh b/projects/germany /generate.sh new file mode 100644 index 00000000..77b720f2 --- /dev/null +++ b/projects/germany /generate.sh @@ -0,0 +1,161 @@ +#!/bin/bash + +# Logdatei setzen +LOGFILE="logfile.txt" + +# Terminal-Sitzung in die Logdatei schreiben +exec > >(tee -a $LOGFILE) 2>&1 + +# Maximale Anzahl der Versuche +MAX_RETRIES=3 + +# Standardmäßig werden alle Schritte ausgeführt +SKIP_DOWNLOAD=true +SKIP_PREPARE=false +SKIP_IMPORT=false + +# Fehlerbehandlungsfunktion +handle_error() { + local error_message="Fehler: $1" + echo "$error_message" + + # E-Mail senden über msmtp + { + echo "From: no-reply@druckplanet24.de" + echo "To: admin@druckplanet24.de" + echo "Subject: Fehler im Pelias Setup" + echo + echo "$error_message" + echo + echo "Logfile-Inhalt:" + tail -n 50 "$LOGFILE" + } | msmtp admin@druckplanet24.de + + exit 1 +} + +# Sicheres Ausführen von Befehlen mit Wiederholungslogik +safe_execute() { + echo "Ausführen: $1" + local command=$1 + local retries=0 + + until [ $retries -ge $MAX_RETRIES ] + do + eval $command + if [ $? -eq 0 ]; then + echo "$command abgeschlossen" + return 0 + fi + + output=$(eval $command 2>&1) + if echo "$output" | grep -q "no such service"; then + echo "Dienst existiert nicht, überspringe: $command" + return 0 + fi + + retries=$((retries+1)) + echo "Fehler beim Ausführen von: $command. Versuch $retries von $MAX_RETRIES." + done + + handle_error "$command nach $MAX_RETRIES Versuchen fehlgeschlagen" +} + +# Syntaxprüfung +echo "Starte Syntaxprüfung..." + +# Überprüfen der .env-Datei +if [ -f ".env" ]; then + if grep -Eq '^[^#]*=.*$' .env; then + echo ".env Syntax ist korrekt." + else + handle_error ".env hat einen Syntaxfehler." + fi +else + handle_error ".env Datei existiert nicht." +fi + +# Überprüfen der docker-compose.yml-Datei +if [ -f "docker-compose.yml" ]; then + docker-compose config -q || handle_error "docker-compose.yml hat einen Syntaxfehler." + echo "docker-compose.yml Syntax ist korrekt." +else + handle_error "docker-compose.yml Datei existiert nicht." +fi + +# Überprüfen der pelias.json-Datei +if [ -f "pelias.json" ]; then + jq empty pelias.json || handle_error "pelias.json hat einen Syntaxfehler." + echo "pelias.json Syntax ist korrekt." +else + handle_error "pelias.json Datei existiert nicht." +fi + +# Überprüfen, ob Pelias Docker läuft +if docker ps | grep -q "pelias"; then + echo "Pelias Docker läuft, beende ihn..." + pelias compose down || handle_error "pelias compose down" +else + echo "Pelias Docker läuft nicht." +fi + +# Pelias-Befehle ausführen +safe_execute "pelias compose pull" +safe_execute "pelias elastic start" +safe_execute "pelias elastic wait" + +# Reset-Abfrage vor pelias elastic create +read -t 10 -p "Möchten Sie Elasticsearch zurücksetzen? (Standard: Nein) [ja/Nein]: " reset_choice +reset_choice=${reset_choice:-nein} +if [[ "$reset_choice" =~ ^[Jj]a$ ]]; then + echo "Zurücksetzen von Elasticsearch..." + pelias elastic drop || handle_error "pelias elastic drop" +else + echo "Kein Zurücksetzen von Elasticsearch durchgeführt." +fi + +# Elasticsearch Index erstellen, wenn er nicht bereits existiert +create_output=$(pelias elastic create 2>&1) +if echo "$create_output" | grep -q "resource_already_exists_exception"; then + echo "Index existiert bereits, weiter mit dem nächsten Schritt." +elif echo "$create_output" | grep -q "acknowledged"; then + echo "Index erfolgreich erstellt, weiter mit dem nächsten Schritt." +else + handle_error "pelias elastic create: $create_output" +fi + +# Download-Schritt (optional überspringen) +if [ "$SKIP_DOWNLOAD" = "false" ]; then + safe_execute "pelias download all" +else + echo "Pelias Download-Schritt wird übersprungen." +fi + +# Vorbereitungsschritte und Valhalla-Tiles erstellen (optional überspringen) +if [ "$SKIP_PREPARE" = "false" ]; then + safe_execute "mkdir -p data/valhalla" + safe_execute "docker run --rm -it \ + --network shared-net \ + --user 1000:1000 \ + -v '/nfs-data/docker/appdata/pelias/germany/data/valhalla:/data/valhalla' \ + -v '/nfs-data/docker/appdata/pelias/germany/data/openstreetmap:/data/openstreetmap' \ + -v '/nfs-data/docker/appdata/pelias/germany/data/polylines:/data/polylines' \ + pelias/valhalla_baseimage \ + /bin/bash -c \"./scripts/build_tiles.sh && \ + find /data/valhalla/valhalla_tiles | sort -n | tar cf /data/valhalla/valhalla_tiles.tar --no-recursion -T - && \ + ./scripts/export_edges.sh\"" + safe_execute "pelias prepare interpolation" + safe_execute "pelias prepare placeholder" +else + echo "Vorbereitungsschritte und Valhalla-Tiles-Erstellung werden übersprungen." +fi + +# Daten importieren (optional überspringen) +if [ "$SKIP_IMPORT" = "false" ]; then + safe_execute "pelias import all" +else + echo "Datenimport wird übersprungen." +fi + +# Pelias-Dienste starten +safe_execute "pelias compose up" From 656c2e67548a0f8b0ad318d4751fc864df542512 Mon Sep 17 00:00:00 2001 From: Be-Mann <25839760+Be-Mann@users.noreply.github.com> Date: Wed, 4 Dec 2024 17:36:49 +0100 Subject: [PATCH 06/14] Delete projects/germany /generate.sh --- projects/germany /generate.sh | 161 ---------------------------------- 1 file changed, 161 deletions(-) delete mode 100644 projects/germany /generate.sh diff --git a/projects/germany /generate.sh b/projects/germany /generate.sh deleted file mode 100644 index 77b720f2..00000000 --- a/projects/germany /generate.sh +++ /dev/null @@ -1,161 +0,0 @@ -#!/bin/bash - -# Logdatei setzen -LOGFILE="logfile.txt" - -# Terminal-Sitzung in die Logdatei schreiben -exec > >(tee -a $LOGFILE) 2>&1 - -# Maximale Anzahl der Versuche -MAX_RETRIES=3 - -# Standardmäßig werden alle Schritte ausgeführt -SKIP_DOWNLOAD=true -SKIP_PREPARE=false -SKIP_IMPORT=false - -# Fehlerbehandlungsfunktion -handle_error() { - local error_message="Fehler: $1" - echo "$error_message" - - # E-Mail senden über msmtp - { - echo "From: no-reply@druckplanet24.de" - echo "To: admin@druckplanet24.de" - echo "Subject: Fehler im Pelias Setup" - echo - echo "$error_message" - echo - echo "Logfile-Inhalt:" - tail -n 50 "$LOGFILE" - } | msmtp admin@druckplanet24.de - - exit 1 -} - -# Sicheres Ausführen von Befehlen mit Wiederholungslogik -safe_execute() { - echo "Ausführen: $1" - local command=$1 - local retries=0 - - until [ $retries -ge $MAX_RETRIES ] - do - eval $command - if [ $? -eq 0 ]; then - echo "$command abgeschlossen" - return 0 - fi - - output=$(eval $command 2>&1) - if echo "$output" | grep -q "no such service"; then - echo "Dienst existiert nicht, überspringe: $command" - return 0 - fi - - retries=$((retries+1)) - echo "Fehler beim Ausführen von: $command. Versuch $retries von $MAX_RETRIES." - done - - handle_error "$command nach $MAX_RETRIES Versuchen fehlgeschlagen" -} - -# Syntaxprüfung -echo "Starte Syntaxprüfung..." - -# Überprüfen der .env-Datei -if [ -f ".env" ]; then - if grep -Eq '^[^#]*=.*$' .env; then - echo ".env Syntax ist korrekt." - else - handle_error ".env hat einen Syntaxfehler." - fi -else - handle_error ".env Datei existiert nicht." -fi - -# Überprüfen der docker-compose.yml-Datei -if [ -f "docker-compose.yml" ]; then - docker-compose config -q || handle_error "docker-compose.yml hat einen Syntaxfehler." - echo "docker-compose.yml Syntax ist korrekt." -else - handle_error "docker-compose.yml Datei existiert nicht." -fi - -# Überprüfen der pelias.json-Datei -if [ -f "pelias.json" ]; then - jq empty pelias.json || handle_error "pelias.json hat einen Syntaxfehler." - echo "pelias.json Syntax ist korrekt." -else - handle_error "pelias.json Datei existiert nicht." -fi - -# Überprüfen, ob Pelias Docker läuft -if docker ps | grep -q "pelias"; then - echo "Pelias Docker läuft, beende ihn..." - pelias compose down || handle_error "pelias compose down" -else - echo "Pelias Docker läuft nicht." -fi - -# Pelias-Befehle ausführen -safe_execute "pelias compose pull" -safe_execute "pelias elastic start" -safe_execute "pelias elastic wait" - -# Reset-Abfrage vor pelias elastic create -read -t 10 -p "Möchten Sie Elasticsearch zurücksetzen? (Standard: Nein) [ja/Nein]: " reset_choice -reset_choice=${reset_choice:-nein} -if [[ "$reset_choice" =~ ^[Jj]a$ ]]; then - echo "Zurücksetzen von Elasticsearch..." - pelias elastic drop || handle_error "pelias elastic drop" -else - echo "Kein Zurücksetzen von Elasticsearch durchgeführt." -fi - -# Elasticsearch Index erstellen, wenn er nicht bereits existiert -create_output=$(pelias elastic create 2>&1) -if echo "$create_output" | grep -q "resource_already_exists_exception"; then - echo "Index existiert bereits, weiter mit dem nächsten Schritt." -elif echo "$create_output" | grep -q "acknowledged"; then - echo "Index erfolgreich erstellt, weiter mit dem nächsten Schritt." -else - handle_error "pelias elastic create: $create_output" -fi - -# Download-Schritt (optional überspringen) -if [ "$SKIP_DOWNLOAD" = "false" ]; then - safe_execute "pelias download all" -else - echo "Pelias Download-Schritt wird übersprungen." -fi - -# Vorbereitungsschritte und Valhalla-Tiles erstellen (optional überspringen) -if [ "$SKIP_PREPARE" = "false" ]; then - safe_execute "mkdir -p data/valhalla" - safe_execute "docker run --rm -it \ - --network shared-net \ - --user 1000:1000 \ - -v '/nfs-data/docker/appdata/pelias/germany/data/valhalla:/data/valhalla' \ - -v '/nfs-data/docker/appdata/pelias/germany/data/openstreetmap:/data/openstreetmap' \ - -v '/nfs-data/docker/appdata/pelias/germany/data/polylines:/data/polylines' \ - pelias/valhalla_baseimage \ - /bin/bash -c \"./scripts/build_tiles.sh && \ - find /data/valhalla/valhalla_tiles | sort -n | tar cf /data/valhalla/valhalla_tiles.tar --no-recursion -T - && \ - ./scripts/export_edges.sh\"" - safe_execute "pelias prepare interpolation" - safe_execute "pelias prepare placeholder" -else - echo "Vorbereitungsschritte und Valhalla-Tiles-Erstellung werden übersprungen." -fi - -# Daten importieren (optional überspringen) -if [ "$SKIP_IMPORT" = "false" ]; then - safe_execute "pelias import all" -else - echo "Datenimport wird übersprungen." -fi - -# Pelias-Dienste starten -safe_execute "pelias compose up" From a25c5275d7e76a6fa2b0a049fd1603b41d67e2c3 Mon Sep 17 00:00:00 2001 From: Be-Mann <25839760+Be-Mann@users.noreply.github.com> Date: Wed, 4 Dec 2024 17:37:06 +0100 Subject: [PATCH 07/14] Create generate.sh --- projects/germany/generate.sh | 161 +++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 projects/germany/generate.sh diff --git a/projects/germany/generate.sh b/projects/germany/generate.sh new file mode 100644 index 00000000..77b720f2 --- /dev/null +++ b/projects/germany/generate.sh @@ -0,0 +1,161 @@ +#!/bin/bash + +# Logdatei setzen +LOGFILE="logfile.txt" + +# Terminal-Sitzung in die Logdatei schreiben +exec > >(tee -a $LOGFILE) 2>&1 + +# Maximale Anzahl der Versuche +MAX_RETRIES=3 + +# Standardmäßig werden alle Schritte ausgeführt +SKIP_DOWNLOAD=true +SKIP_PREPARE=false +SKIP_IMPORT=false + +# Fehlerbehandlungsfunktion +handle_error() { + local error_message="Fehler: $1" + echo "$error_message" + + # E-Mail senden über msmtp + { + echo "From: no-reply@druckplanet24.de" + echo "To: admin@druckplanet24.de" + echo "Subject: Fehler im Pelias Setup" + echo + echo "$error_message" + echo + echo "Logfile-Inhalt:" + tail -n 50 "$LOGFILE" + } | msmtp admin@druckplanet24.de + + exit 1 +} + +# Sicheres Ausführen von Befehlen mit Wiederholungslogik +safe_execute() { + echo "Ausführen: $1" + local command=$1 + local retries=0 + + until [ $retries -ge $MAX_RETRIES ] + do + eval $command + if [ $? -eq 0 ]; then + echo "$command abgeschlossen" + return 0 + fi + + output=$(eval $command 2>&1) + if echo "$output" | grep -q "no such service"; then + echo "Dienst existiert nicht, überspringe: $command" + return 0 + fi + + retries=$((retries+1)) + echo "Fehler beim Ausführen von: $command. Versuch $retries von $MAX_RETRIES." + done + + handle_error "$command nach $MAX_RETRIES Versuchen fehlgeschlagen" +} + +# Syntaxprüfung +echo "Starte Syntaxprüfung..." + +# Überprüfen der .env-Datei +if [ -f ".env" ]; then + if grep -Eq '^[^#]*=.*$' .env; then + echo ".env Syntax ist korrekt." + else + handle_error ".env hat einen Syntaxfehler." + fi +else + handle_error ".env Datei existiert nicht." +fi + +# Überprüfen der docker-compose.yml-Datei +if [ -f "docker-compose.yml" ]; then + docker-compose config -q || handle_error "docker-compose.yml hat einen Syntaxfehler." + echo "docker-compose.yml Syntax ist korrekt." +else + handle_error "docker-compose.yml Datei existiert nicht." +fi + +# Überprüfen der pelias.json-Datei +if [ -f "pelias.json" ]; then + jq empty pelias.json || handle_error "pelias.json hat einen Syntaxfehler." + echo "pelias.json Syntax ist korrekt." +else + handle_error "pelias.json Datei existiert nicht." +fi + +# Überprüfen, ob Pelias Docker läuft +if docker ps | grep -q "pelias"; then + echo "Pelias Docker läuft, beende ihn..." + pelias compose down || handle_error "pelias compose down" +else + echo "Pelias Docker läuft nicht." +fi + +# Pelias-Befehle ausführen +safe_execute "pelias compose pull" +safe_execute "pelias elastic start" +safe_execute "pelias elastic wait" + +# Reset-Abfrage vor pelias elastic create +read -t 10 -p "Möchten Sie Elasticsearch zurücksetzen? (Standard: Nein) [ja/Nein]: " reset_choice +reset_choice=${reset_choice:-nein} +if [[ "$reset_choice" =~ ^[Jj]a$ ]]; then + echo "Zurücksetzen von Elasticsearch..." + pelias elastic drop || handle_error "pelias elastic drop" +else + echo "Kein Zurücksetzen von Elasticsearch durchgeführt." +fi + +# Elasticsearch Index erstellen, wenn er nicht bereits existiert +create_output=$(pelias elastic create 2>&1) +if echo "$create_output" | grep -q "resource_already_exists_exception"; then + echo "Index existiert bereits, weiter mit dem nächsten Schritt." +elif echo "$create_output" | grep -q "acknowledged"; then + echo "Index erfolgreich erstellt, weiter mit dem nächsten Schritt." +else + handle_error "pelias elastic create: $create_output" +fi + +# Download-Schritt (optional überspringen) +if [ "$SKIP_DOWNLOAD" = "false" ]; then + safe_execute "pelias download all" +else + echo "Pelias Download-Schritt wird übersprungen." +fi + +# Vorbereitungsschritte und Valhalla-Tiles erstellen (optional überspringen) +if [ "$SKIP_PREPARE" = "false" ]; then + safe_execute "mkdir -p data/valhalla" + safe_execute "docker run --rm -it \ + --network shared-net \ + --user 1000:1000 \ + -v '/nfs-data/docker/appdata/pelias/germany/data/valhalla:/data/valhalla' \ + -v '/nfs-data/docker/appdata/pelias/germany/data/openstreetmap:/data/openstreetmap' \ + -v '/nfs-data/docker/appdata/pelias/germany/data/polylines:/data/polylines' \ + pelias/valhalla_baseimage \ + /bin/bash -c \"./scripts/build_tiles.sh && \ + find /data/valhalla/valhalla_tiles | sort -n | tar cf /data/valhalla/valhalla_tiles.tar --no-recursion -T - && \ + ./scripts/export_edges.sh\"" + safe_execute "pelias prepare interpolation" + safe_execute "pelias prepare placeholder" +else + echo "Vorbereitungsschritte und Valhalla-Tiles-Erstellung werden übersprungen." +fi + +# Daten importieren (optional überspringen) +if [ "$SKIP_IMPORT" = "false" ]; then + safe_execute "pelias import all" +else + echo "Datenimport wird übersprungen." +fi + +# Pelias-Dienste starten +safe_execute "pelias compose up" From 85edee4be37b3077eee384cc81325edbe2849796 Mon Sep 17 00:00:00 2001 From: Be-Mann <25839760+Be-Mann@users.noreply.github.com> Date: Wed, 4 Dec 2024 17:37:28 +0100 Subject: [PATCH 08/14] Update generate.sh --- projects/germany/generate.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/germany/generate.sh b/projects/germany/generate.sh index 77b720f2..55e8cf48 100644 --- a/projects/germany/generate.sh +++ b/projects/germany/generate.sh @@ -10,7 +10,7 @@ exec > >(tee -a $LOGFILE) 2>&1 MAX_RETRIES=3 # Standardmäßig werden alle Schritte ausgeführt -SKIP_DOWNLOAD=true +SKIP_DOWNLOAD=false SKIP_PREPARE=false SKIP_IMPORT=false From d50e3721a94f2de98b2e57a780d722e27bcd7585 Mon Sep 17 00:00:00 2001 From: Be-Mann <25839760+Be-Mann@users.noreply.github.com> Date: Wed, 4 Dec 2024 17:38:50 +0100 Subject: [PATCH 09/14] Update pelias.json --- projects/germany/pelias.json | 41 ++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/projects/germany/pelias.json b/projects/germany/pelias.json index b7b83957..f3ff723b 100644 --- a/projects/germany/pelias.json +++ b/projects/germany/pelias.json @@ -4,7 +4,7 @@ "timestamp": false }, "esclient": { - "apiVersion": "7.5", + "apiVersion": "7.x", "hosts": [ { "host": "elasticsearch" } ] @@ -16,8 +16,45 @@ "number_of_replicas": "0", "number_of_shards": "1" } + }, + "accessLog": "common", + "host": "http://maps.druckplanet24.de/", + "indexName": "pelias", + "version": "1.0", + "targets": { + "auto_discover": true, + "canonical_sources": ["whosonfirst", "openstreetmap", "openaddresses", "geonames"], + "layers_by_source": { + "openstreetmap": [ "address", "venue", "street" ], + "openaddresses": [ "address" ], + "geonames": [ + "country", "macroregion", "region", "county", "localadmin", "locality", "borough", + "neighbourhood", "venue" + ], + "whosonfirst": [ + "continent", "empire", "country", "dependency", "macroregion", "region", "locality", + "localadmin", "macrocounty", "county", "macrohood", "borough", "neighbourhood", + "microhood", "disputed", "venue", "postalcode", "ocean", "marinearea" + ] + }, + "source_aliases": { + "osm": [ "openstreetmap" ], + "oa": [ "openaddresses" ], + "gn": [ "geonames" ], + "wof": [ "whosonfirst" ] + }, + "layer_aliases": { + "coarse": [ + "continent", "empire", "country", "dependency", "macroregion", "region", "locality", + "localadmin", "macrocounty", "county", "macrohood", "borough", "neighbourhood", + "microhood", "disputed", "postalcode", "ocean", "marinearea" + ] + } } }, + "schema": { + "indexName": "pelias" + }, "api": { "services": { "pip": { "url": "http://pip:4200" }, @@ -52,7 +89,7 @@ "whosonfirst": { "datapath": "/data/whosonfirst", "countryCode": "DE", - "importPostalcodes": false, + "importPostalcodes": true, "importPlace": [ "85633111" ] } } From f75c64785d4ffdfcdaad44ea49df26f7113f04b5 Mon Sep 17 00:00:00 2001 From: Be-Mann <25839760+Be-Mann@users.noreply.github.com> Date: Wed, 4 Dec 2024 17:39:49 +0100 Subject: [PATCH 10/14] Update docker-compose.yml --- projects/germany/docker-compose.yml | 39 ++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/projects/germany/docker-compose.yml b/projects/germany/docker-compose.yml index 5399075d..ef3b2d43 100644 --- a/projects/germany/docker-compose.yml +++ b/projects/germany/docker-compose.yml @@ -1,7 +1,8 @@ -version: '3' networks: default: driver: bridge + shared-net: + external: true # Dies gibt an, dass es sich um ein externes Netzwerk handelt services: libpostal: image: pelias/libpostal-service @@ -9,12 +10,18 @@ services: user: "${DOCKER_USER}" restart: always ports: [ "127.0.0.1:4400:4400" ] + networks: + - default + - shared-net schema: image: pelias/schema:master container_name: pelias_schema user: "${DOCKER_USER}" volumes: - "./pelias.json:/code/pelias.json" + networks: + - default + - shared-net api: image: pelias/api:master container_name: pelias_api @@ -24,6 +31,9 @@ services: ports: [ "0.0.0.0:4000:4000" ] volumes: - "./pelias.json:/code/pelias.json" + networks: + - default + - shared-net placeholder: image: pelias/placeholder:master container_name: pelias_placeholder @@ -35,6 +45,9 @@ services: - "./pelias.json:/code/pelias.json" - "${DATA_DIR}:/data" - "./blacklist/:/data/blacklist" + networks: + - default + - shared-net whosonfirst: image: pelias/whosonfirst:master container_name: pelias_whosonfirst @@ -42,6 +55,9 @@ services: volumes: - "./pelias.json:/code/pelias.json" - "${DATA_DIR}:/data" + networks: + - default + - shared-net openstreetmap: image: pelias/openstreetmap:master container_name: pelias_openstreetmap @@ -49,6 +65,9 @@ services: volumes: - "./pelias.json:/code/pelias.json" - "${DATA_DIR}:/data" + networks: + - default + - shared-net openaddresses: image: pelias/openaddresses:master container_name: pelias_openaddresses @@ -56,6 +75,9 @@ services: volumes: - "./pelias.json:/code/pelias.json" - "${DATA_DIR}:/data" + networks: + - default + - shared-net csv-importer: image: pelias/csv-importer:master container_name: pelias_csv_importer @@ -64,6 +86,9 @@ services: - "./pelias.json:/code/pelias.json" - "${DATA_DIR}:/data" - "./blacklist/:/data/blacklist" + networks: + - default + - shared-net polylines: image: pelias/polylines:master container_name: pelias_polylines @@ -71,6 +96,9 @@ services: volumes: - "./pelias.json:/code/pelias.json" - "${DATA_DIR}:/data" + networks: + - default + - shared-net interpolation: image: pelias/interpolation:master container_name: pelias_interpolation @@ -81,6 +109,9 @@ services: volumes: - "./pelias.json:/code/pelias.json" - "${DATA_DIR}:/data" + networks: + - default + - shared-net pip: image: pelias/pip-service:master container_name: pelias_pip-service @@ -91,6 +122,9 @@ services: volumes: - "./pelias.json:/code/pelias.json" - "${DATA_DIR}:/data" + networks: + - default + - shared-net elasticsearch: image: pelias/elasticsearch:7.16.1 container_name: pelias_elasticsearch @@ -110,3 +144,6 @@ services: cap_add: [ "IPC_LOCK" ] security_opt: - seccomp=unconfined + networks: + - default + - shared-net From e709b7bf1a60440abc358a7e8fa1209a07b163a0 Mon Sep 17 00:00:00 2001 From: Be-Mann <25839760+Be-Mann@users.noreply.github.com> Date: Wed, 4 Dec 2024 17:40:20 +0100 Subject: [PATCH 11/14] Update .env --- projects/germany/.env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/germany/.env b/projects/germany/.env index c27c8edb..0b44f0ba 100644 --- a/projects/germany/.env +++ b/projects/germany/.env @@ -1,2 +1,2 @@ -COMPOSE_PROJECT_NAME=pelias +COMPOSE_PROJECT_NAME=pelias_germany DATA_DIR=./data From 2c8fd9089aad12c8bdd265b9ca0e9e985f5af08f Mon Sep 17 00:00:00 2001 From: Be-Mann <25839760+Be-Mann@users.noreply.github.com> Date: Wed, 4 Dec 2024 17:40:55 +0100 Subject: [PATCH 12/14] Update README.md --- projects/germany/README.md | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/projects/germany/README.md b/projects/germany/README.md index 68e78bdb..6ca25727 100644 --- a/projects/germany/README.md +++ b/projects/germany/README.md @@ -14,18 +14,7 @@ Please ensure that's all working fine before continuing. # Run a Build -To run a complete build, execute the following commands: - -```bash -pelias compose pull -pelias elastic start -pelias elastic wait -pelias elastic create -pelias download all -pelias prepare all -pelias import all -pelias compose up -``` +To run a complete build, execute `generate.sh` # Make an Example Query From 39563e4286f7b7b502dbc19580318ef39ea3049f Mon Sep 17 00:00:00 2001 From: Be-Mann <25839760+Be-Mann@users.noreply.github.com> Date: Wed, 4 Dec 2024 17:41:16 +0100 Subject: [PATCH 13/14] Update README.md --- projects/germany/README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/projects/germany/README.md b/projects/germany/README.md index 6ca25727..950e8578 100644 --- a/projects/germany/README.md +++ b/projects/germany/README.md @@ -14,7 +14,10 @@ Please ensure that's all working fine before continuing. # Run a Build -To run a complete build, execute `generate.sh` +To run a complete build, execute +``` +generate.sh +``` # Make an Example Query From eefd5625dbddca5c042b111656e2e68a360526c0 Mon Sep 17 00:00:00 2001 From: Be-Mann <25839760+Be-Mann@users.noreply.github.com> Date: Wed, 4 Dec 2024 17:41:40 +0100 Subject: [PATCH 14/14] Update README.md --- projects/germany/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/projects/germany/README.md b/projects/germany/README.md index 950e8578..6ab11727 100644 --- a/projects/germany/README.md +++ b/projects/germany/README.md @@ -16,7 +16,8 @@ Please ensure that's all working fine before continuing. To run a complete build, execute ``` -generate.sh +chmod +x generate.sh +./generate.sh ``` # Make an Example Query