Files
wiki/tasks/snowbike-rag/start.sh
2026-04-12 21:55:33 +03:00

47 lines
1.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Snowbike RAG - Запуск с автоперезапуском
DIR="$(cd "$(dirname "$0")" && pwd)"
LOG="$DIR/data/logs/flask.log"
PIDFILE="$DIR/data/logs/flask.pid"
# Проверить, не запущен ли уже Flask (по health endpoint)
if curl -s http://localhost:5557/health > /dev/null 2>&1; then
echo "✓ Flask уже запущен"
exit 0
fi
# Остановить старый bash-цикл если есть (чистим стale PID)
if [ -f "$PIDFILE" ]; then
OLD_PID=$(cat "$PIDFILE")
kill "$OLD_PID" 2>/dev/null
rm -f "$PIDFILE"
fi
# Запустить Meilisearch если не запущен
if ! curl -s http://localhost:7700/health > /dev/null 2>&1; then
nohup "$DIR/bin/meilisearch" \
--db-path "$DIR/data/meilisearch" \
--http-addr 127.0.0.1:7700 \
--no-analytics \
> "$DIR/data/logs/meilisearch.log" 2>&1 &
sleep 2
fi
# Запустить Flask с auto-restart
nohup bash -c "while true; do
cd '$DIR'
'$DIR/venv/bin/python3' server.py >> '$LOG' 2>&1
echo '[\$(date)] Flask crashed, restarting in 3s...' >> '$LOG'
sleep 3
done" > /dev/null 2>&1 &
echo $! > "$PIDFILE"
sleep 2
if curl -s http://localhost:5557/health > /dev/null 2>&1; then
echo "✓ Snowbike RAG запущен"
else
echo "✗ Ошибка запуска, смотри $LOG"
fi