aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShyam Sunder2019-09-21 14:22:07 -0400
committerShyam Sunder2019-09-21 14:22:07 -0400
commitdd56c287b5cee2576317cb16d5059f1a845ccb76 (patch)
tree311774d9d9c42dd8912e446267e4a004830e535c
parentfa3b6275b321aeba92395fbe563befb10aab5e90 (diff)
server/facade: integrated elasticsearch wait into entrypoint
-rw-r--r--server/Dockerfile1
-rw-r--r--server/szurubooru/facade.py4
-rwxr-xr-xserver/wait-for-es32
3 files changed, 3 insertions, 34 deletions
diff --git a/server/Dockerfile b/server/Dockerfile
index 0b0664d..ee459f9 100644
--- a/server/Dockerfile
+++ b/server/Dockerfile
@@ -25,7 +25,6 @@ RUN \
echo "#!/bin/sh" >> /init && \
echo "set -e" >> /init && \
echo "cd /opt/app" >> /init && \
- echo "./wait-for-es" >> /init && \
echo "alembic upgrade head" >> /init && \
echo "exec waitress-serve --port ${PORT} szurubooru.facade:app" \
>> /init && \
diff --git a/server/szurubooru/facade.py b/server/szurubooru/facade.py
index d0306c2..b03e219 100644
--- a/server/szurubooru/facade.py
+++ b/server/szurubooru/facade.py
@@ -8,7 +8,7 @@ import coloredlogs
import sqlalchemy as sa
import sqlalchemy.orm.exc
from szurubooru import config, db, errors, rest
-from szurubooru.func import posts, file_uploads
+from szurubooru.func import posts, file_uploads, image_hash
# pylint: disable=unused-import
from szurubooru import api, middleware
@@ -130,6 +130,8 @@ def create_app() -> Callable[[Any, Any], Any]:
purge_thread.start()
try:
+ image_hash.get_session().cluster.health(
+ wait_for_status='yellow', request_timeout=30)
posts.populate_reverse_search()
db.session.commit()
except errors.ThirdPartyError:
diff --git a/server/wait-for-es b/server/wait-for-es
deleted file mode 100755
index b21ea6e..0000000
--- a/server/wait-for-es
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/usr/bin/env python3
-
-'''
-Docker helper script. Blocks until the ElasticSearch service is ready.
-'''
-
-import logging
-import time
-from szurubooru import errors
-from szurubooru.func.image_hash import get_session
-
-
-def main():
- print('Looking for ElasticSearch connection...')
- logging.basicConfig(level=logging.ERROR)
- es = get_session()
-
- TIMEOUT = 30
- DELAY = 0.1
- for _ in range(int(TIMEOUT / DELAY)):
- try:
- es.cluster.health(wait_for_status='yellow')
- print('Connected to ElasticSearch!')
- return
- except Exception:
- time.sleep(DELAY)
- pass
- raise errors.ThirdPartyError('Error connecting to ElasticSearch')
-
-
-if __name__ == '__main__':
- main()

© 2015 - 2026 Jakob L. Kreuze