From c41d720a2e3cdfa7b9aab1de940a4e7506a73c67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Mon, 4 Nov 2024 17:00:14 +0100 Subject: [PATCH] fix: Check valkey version, stop if < 8 Fix https://github.com/Lookyloo/lookyloo/issues/970 --- bin/run_backend.py | 37 +++++++++++++++++++++++++++++++++---- bin/start.py | 6 +++++- cache/run_redis.sh | 14 +++++++++++++- indexing/run_redis.sh | 14 +++++++++++++- 4 files changed, 64 insertions(+), 7 deletions(-) diff --git a/bin/run_backend.py b/bin/run_backend.py index e86ecc13..e26e96b2 100755 --- a/bin/run_backend.py +++ b/bin/run_backend.py @@ -4,6 +4,7 @@ from __future__ import annotations import argparse import os +import sys import time from pathlib import Path from subprocess import Popen @@ -29,7 +30,15 @@ def launch_cache(storage_directory: Path | None=None) -> None: if not storage_directory: storage_directory = get_homedir() if not check_running('cache'): - Popen(["./run_redis.sh"], cwd=(storage_directory / 'cache')) + process = Popen(["./run_redis.sh"], cwd=(storage_directory / 'cache')) + try: + # Give time for the process to start (and potentailly fail) + process.wait(timeout=5) + except TimeoutError: + pass + process.poll() + if process.returncode == 1: + raise Exception('Failed to start Redis cache database.') def shutdown_cache(storage_directory: Path | None=None) -> None: @@ -44,7 +53,15 @@ def launch_indexing(storage_directory: Path | None=None) -> None: if not storage_directory: storage_directory = get_homedir() if not check_running('indexing'): - Popen(["./run_redis.sh"], cwd=(storage_directory / 'indexing')) + process = Popen(["./run_redis.sh"], cwd=(storage_directory / 'indexing')) + try: + # Give time for the process to start (and potentailly fail) + process.wait(timeout=5) + except TimeoutError: + pass + process.poll() + if process.returncode == 1: + raise Exception('Failed to start Redis indexing database.') def shutdown_indexing(storage_directory: Path | None=None) -> None: @@ -59,7 +76,15 @@ def launch_full_index(storage_directory: Path | None=None) -> None: if not storage_directory: storage_directory = get_homedir() if not check_running('full_index'): - Popen(["./run_kvrocks.sh"], cwd=(storage_directory / 'full_index')) + process = Popen(["./run_kvrocks.sh"], cwd=(storage_directory / 'full_index')) + try: + # Give time for the process to start (and potentailly fail) + process.wait(timeout=5) + except TimeoutError: + pass + process.poll() + if process.returncode == 1: + raise Exception('Failed to start Kvrocks full indexing database.') def shutdown_full_index(storage_directory: Path | None=None) -> None: @@ -116,7 +141,11 @@ def main() -> None: args = parser.parse_args() if args.start: - launch_all() + try: + launch_all() + except Exception as e: + print(f"Failed to start some DBs: {e}") + sys.exit(1) if args.stop: stop_all() if not args.stop and args.status: diff --git a/bin/start.py b/bin/start.py index 2ec09836..8a32e92f 100755 --- a/bin/start.py +++ b/bin/start.py @@ -10,7 +10,11 @@ def main() -> None: get_homedir() print('Start backend (redis)...') p = run(['run_backend', '--start']) - p.check_returncode() + try: + p.check_returncode() + except Exception: + print('Failed to start the backend, exiting.') + return print('done.') print('Start archiving process...') Popen(['archiver']) diff --git a/cache/run_redis.sh b/cache/run_redis.sh index 8daf6d8b..f9acbc52 100755 --- a/cache/run_redis.sh +++ b/cache/run_redis.sh @@ -1,13 +1,25 @@ #!/bin/bash set -e -set -x +# set -x if [ -f ../../valkey/src/valkey-server ]; then + if [[ ` ../../valkey/src/valkey-server -v` == *"v=7."* ]] ; then + echo "You're using valkey 7, please upgrade do valkey 8" + exit 1 + fi ../../valkey/src/valkey-server ./cache.conf elif [ -f ../../redis/src/redis-server ]; then + if [[ ` ../../redis/src/redis-server -v` == *"v=7."* ]] ; then + echo "You're using redis 7, please upgrade do valkey 8"; + exit 1 + fi ../../redis/src/redis-server ./cache.conf else + if [[ `/usr/bin/redis-server -v` == *"v=7."* ]] ; then + echo "You're using redis 7, please upgrade do valkey 8"; + exit 1 + fi echo "Warning: using system redis-server. Valkey-server or redis-server from source is recommended." >&2 /usr/bin/redis-server ./cache.conf fi diff --git a/indexing/run_redis.sh b/indexing/run_redis.sh index d6924a0f..d2c7e3b3 100755 --- a/indexing/run_redis.sh +++ b/indexing/run_redis.sh @@ -1,13 +1,25 @@ #!/bin/bash set -e -set -x +# set -x if [ -f ../../valkey/src/valkey-server ]; then + if [[ ` ../../valkey/src/valkey-server -v` == *"v=7."* ]] ; then + echo "You're using valkey 7, please upgrade do valkey 8" + exit 1 + fi ../../valkey/src/valkey-server ./indexing.conf elif [ -f ../../redis/src/redis-server ]; then + if [[ ` ../../redis/src/redis-server -v` == *"v=7."* ]] ; then + echo "You're using redis 7, please upgrade do valkey 8"; + exit 1 + fi ../../redis/src/redis-server ./indexing.conf else + if [[ `/usr/bin/redis-server -v` == *"v=7."* ]] ; then + echo "You're using redis 7, please upgrade do valkey 8"; + exit 1 + fi echo "Warning: using system redis-server. Valkey-server or redis-server from source is recommended." >&2 /usr/bin/redis-server ./indexing.conf fi