fix: Check valkey version, stop if < 8

Fix https://github.com/Lookyloo/lookyloo/issues/970
pull/986/head
Raphaël Vinot 2024-11-04 17:00:14 +01:00
parent 6c3fa8074f
commit c41d720a2e
4 changed files with 64 additions and 7 deletions

View File

@ -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:

View File

@ -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'])

14
cache/run_redis.sh vendored
View File

@ -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

View File

@ -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