From 76e8d253b15bd99ef6e7b850fc8add89e8e76017 Mon Sep 17 00:00:00 2001 From: LXW <1264174498@qq.com> Date: Mon, 11 Sep 2023 10:47:36 +0800 Subject: [PATCH] [improvement](config) add bat script for standalone start and llm start (#69) --- assembly/bin/build-standalone.bat | 5 +-- assembly/bin/start-standalone.bat | 39 ++++++++++++++++ assembly/bin/stop-standalone.bat | 12 +++++ chat/core/src/main/python/bin/env.bat | 6 +++ chat/core/src/main/python/bin/install.bat | 22 ++++++++++ chat/core/src/main/python/bin/run.bat | 23 ++++++++++ chat/core/src/main/python/bin/service.bat | 44 +++++++++++++++++++ launchers/standalone/src/main/bin/env.bat | 3 ++ launchers/standalone/src/main/bin/run.bat | 30 +++++++++++++ launchers/standalone/src/main/bin/service.bat | 42 ++++++++++++++++++ 10 files changed, 223 insertions(+), 3 deletions(-) create mode 100644 assembly/bin/start-standalone.bat create mode 100644 assembly/bin/stop-standalone.bat create mode 100644 chat/core/src/main/python/bin/env.bat create mode 100644 chat/core/src/main/python/bin/install.bat create mode 100644 chat/core/src/main/python/bin/run.bat create mode 100644 chat/core/src/main/python/bin/service.bat create mode 100644 launchers/standalone/src/main/bin/env.bat create mode 100644 launchers/standalone/src/main/bin/run.bat create mode 100644 launchers/standalone/src/main/bin/service.bat diff --git a/assembly/bin/build-standalone.bat b/assembly/bin/build-standalone.bat index d1f630bf6..1fa89e2af 100644 --- a/assembly/bin/build-standalone.bat +++ b/assembly/bin/build-standalone.bat @@ -10,13 +10,12 @@ set "buildDir=%baseDir%\build" cd "%baseDir%" rem 1. build semantic chat service -del /q "%buildDir%\*.tar.gz" -rd /s /q dist +del /q "%buildDir%\*.tar.gz" 2>NUL call mvn -f "%baseDir%\..\pom.xml" clean package -DskipTests rem 2. move package to build -copy "%baseDir%\..\launchers\standalone\target\*.tar.gz" "%buildDir%\supersonic.tar.gz" +echo f|xcopy "%baseDir%\..\launchers\standalone\target\*.tar.gz" "%buildDir%\supersonic.tar.gz" rem 3. build webapp cd "%baseDir%\..\webapp" diff --git a/assembly/bin/start-standalone.bat b/assembly/bin/start-standalone.bat new file mode 100644 index 000000000..d9b29627b --- /dev/null +++ b/assembly/bin/start-standalone.bat @@ -0,0 +1,39 @@ +@echo off +setlocal + +set "sbinDir=%~dp0" +set "baseDir=%~dp0.." +set "runtimeDir=%baseDir%\..\runtime" +set "buildDir=%baseDir%\build" + +cd /d %baseDir% + +::1. clear file +rd /s /q "%runtimeDir%" +mkdir "%runtimeDir%" + + +::2. package lib +:: Assuming you have tar utility installed in Windows +tar -zxvf "%buildDir%\supersonic.tar.gz" -C "%runtimeDir%" + +for /d %%f in ("%runtimeDir%\launchers-standalone-*") do ( + move "%%f" "%runtimeDir%\supersonic-standalone" +) + +tar -zxvf "%buildDir%\supersonic-webapp.tar.gz" -C "%buildDir%" + +if not exist "%runtimeDir%\supersonic-standalone\webapp" mkdir "%runtimeDir%\supersonic-standalone\webapp" + +xcopy /s /e /h /y "%buildDir%\supersonic-webapp\*" "%runtimeDir%\supersonic-standalone\webapp" + +if not exist "%runtimeDir%\supersonic-standalone\conf\webapp" mkdir "%runtimeDir%\supersonic-standalone\conf\webapp" +xcopy /s /e /h /y "%runtimeDir%\supersonic-standalone\webapp\*" "%runtimeDir%\supersonic-standalone\conf\webapp" + +rd /s /q "%buildDir%\supersonic-webapp" + + +::3. start service +::start standalone service +call "%runtimeDir%\supersonic-standalone\bin\service.bat" restart +call "%runtimeDir%\supersonic-standalone\llm\bin\service.bat" restart diff --git a/assembly/bin/stop-standalone.bat b/assembly/bin/stop-standalone.bat new file mode 100644 index 000000000..e23017254 --- /dev/null +++ b/assembly/bin/stop-standalone.bat @@ -0,0 +1,12 @@ +@echo off +setlocal + +set "sbinDir=%~dp0" +set "baseDir=%~dp0.." +set "runtimeDir=%baseDir%\..\runtime" +set "buildDir=%baseDir%\build" + +::3. start service +::start standalone service +call "%runtimeDir%\supersonic-standalone\bin\service.bat" stop +call "%runtimeDir%\supersonic-standalone\llm\bin\service.bat" stop diff --git a/chat/core/src/main/python/bin/env.bat b/chat/core/src/main/python/bin/env.bat new file mode 100644 index 000000000..7f6a51207 --- /dev/null +++ b/chat/core/src/main/python/bin/env.bat @@ -0,0 +1,6 @@ +@echo off +set "python_path=python" +set "pip_path=pip3.9" +set "llm_host=127.0.0.1" +set "llm_port=9092" +set "start_name=api_service" diff --git a/chat/core/src/main/python/bin/install.bat b/chat/core/src/main/python/bin/install.bat new file mode 100644 index 000000000..6b114031a --- /dev/null +++ b/chat/core/src/main/python/bin/install.bat @@ -0,0 +1,22 @@ +@echo off +setlocal + +set "binDir=%~dp0" +cd /d "%binDir%.." +set "baseDir=%cd%" +echo %binDir% + +call "%binDir%\env.bat" + +"%pip_path%" install -r "%baseDir%\requirements.txt" + +"%python_path%" -c "import langchain,fastapi,chromadb,tiktoken,uvicorn" >nul 2>&1 +if "%errorlevel%" equ 0 ( + echo install ok, will pass +) else ( + if "%errorlevel%" equ 1 ( + echo install ok + ) else ( + echo install fail, but if it can be started normally, it will not affect + ) +) \ No newline at end of file diff --git a/chat/core/src/main/python/bin/run.bat b/chat/core/src/main/python/bin/run.bat new file mode 100644 index 000000000..90bf3fcf4 --- /dev/null +++ b/chat/core/src/main/python/bin/run.bat @@ -0,0 +1,23 @@ +@echo off +setlocal + +set "binDir=%~dp0" +cd /d "%binDir%.." +set "baseDir=%cd%" + +call "%binDir%\env.bat" +echo "%binDir%" + +if "%llm_host%"=="" ( + echo llm_host llm_port is not set + exit /b 1 +) + +if "%python_path%"=="" ( + echo please set env value python_path, pip_path to python, pip path by export cmd + exit /b 1 +) + +call "%binDir%\install.bat" +cd "%baseDir%\llm" +start "" /B uvicorn %start_name%:app --port %llm_port% --host %llm_host% > "%baseDir%\llm.log" 2>&1 \ No newline at end of file diff --git a/chat/core/src/main/python/bin/service.bat b/chat/core/src/main/python/bin/service.bat new file mode 100644 index 000000000..72b752953 --- /dev/null +++ b/chat/core/src/main/python/bin/service.bat @@ -0,0 +1,44 @@ +@echo off +setlocal + +set "binDir=%~dp0" +cd /d "%binDir%.." +set "baseDir=%cd%" + +call "%baseDir%\bin\env.bat" + +set "command=%~1" + + +if "%command%"=="start" ( + for /f "tokens=2" %%i in ('tasklist ^| findstr /i "Python"') do ( + taskkill /PID %%i /F + echo "Process (PID = %%i) is running." + goto :EOF + ) + "%baseDir%\bin\run.bat" + echo "llm service started, see logs/error with logs/error command" + goto :EOF +) + + +if "%command%"=="stop" ( + for /f "tokens=2" %%i in ('tasklist ^| findstr /i "Python"') do ( + taskkill /PID %%i /F + echo "Process (PID = %%i) is killed." + goto :EOF + ) + echo "Process is not running." + goto :EOF +) + + +if "%command%"=="restart" ( + for /f "tokens=2" %%i in ('tasklist ^| findstr /i "Python"') do ( + taskkill /PID %%i /F + echo "Process (PID = %%i) is killed." + ) + "%baseDir%\bin\run.bat" + echo "Process started, see logs/error with logs/error command" + goto :EOF +) \ No newline at end of file diff --git a/launchers/standalone/src/main/bin/env.bat b/launchers/standalone/src/main/bin/env.bat new file mode 100644 index 000000000..51376b384 --- /dev/null +++ b/launchers/standalone/src/main/bin/env.bat @@ -0,0 +1,3 @@ +@echo off +set "APP_NAME=chat-service" +set "MAIN_CLASS=com.tencent.supersonic.StandaloneLauncher" diff --git a/launchers/standalone/src/main/bin/run.bat b/launchers/standalone/src/main/bin/run.bat new file mode 100644 index 000000000..a5c21f02d --- /dev/null +++ b/launchers/standalone/src/main/bin/run.bat @@ -0,0 +1,30 @@ +@echo off +setlocal + +set "binDir=%~dp0" +set "baseDir=%~dp0.." +set "libDir=%baseDir%\lib" +set "confDir=%baseDir%\conf" +set "webDir=%baseDir%\webapp" + +call "%baseDir%\bin\env.bat" + +set "CLASSPATH=%confDir%;%webDir%;%libDir%\*" + +set "LANG=zh_CN.UTF-8" + +cd /d "%baseDir%" + +set "command=-Dfile.encoding=UTF-8 -Duser.language=Zh -Duser.region=CN -Duser.timezone=GMT+08 -Xms1024m -Xmx2048m -cp %CLASSPATH% %MAIN_CLASS%" + +if not exist "%baseDir%\logs" ( + mkdir "%baseDir%\logs" +) + +if "%is_test%"=="true" ( + start "supersonic" /B java -Dspring.profiles.active=dev %command% >nul 2>"%baseDir%\logs\error.log" +) else ( + start "supersonic" /B java %command% >nul 2>"%baseDir%\logs\error.log" +) + +endlocal \ No newline at end of file diff --git a/launchers/standalone/src/main/bin/service.bat b/launchers/standalone/src/main/bin/service.bat new file mode 100644 index 000000000..c72043bdd --- /dev/null +++ b/launchers/standalone/src/main/bin/service.bat @@ -0,0 +1,42 @@ +@echo off +setlocal + +set "binDir=%~dp0" +set "baseDir=%~dp0.." +set "confDir=%baseDir%\conf" +call "%baseDir%\bin\env.bat" + +set "command=%~1" + + +if "%command%"=="start" ( + for /f "tokens=2" %%i in ('tasklist ^| findstr /i "java"') do ( + echo "Process (PID = %%i) is running." + goto :EOF + ) + echo "Starting %APP_NAME%" + "%baseDir%\bin\run.bat" %MAIN_CLASS% + echo "Process started, see logs/error with logs/error command" + goto :EOF +) + + +if "%command%"=="stop" ( + for /f "tokens=2" %%i in ('tasklist ^| findstr /i "java"') do ( + taskkill /PID %%i /F + echo "Process (PID = %%i) is killed." + goto :EOF + ) + echo "Process is not running." + goto :EOF +) + + +if "%command%"=="restart" ( + for /f "tokens=2" %%i in ('tasklist ^| findstr /i "java"') do ( + taskkill /PID %%i /F + echo "Process (PID = %%i) is killed." + ) + "%baseDir%\bin\run.bat" %MAIN_CLASS% + echo "%APP_NAME% started, see logs/error with logs/error command" +) \ No newline at end of file