diff --git a/server/Dockerfile b/server/Dockerfile index 0b0664d2..ee459f9d 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 d0306c28..b03e2197 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 b21ea6eb..00000000 --- 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()