From 5583426115b7c472973dd13a9261ffac28c1cc82 Mon Sep 17 00:00:00 2001 From: lexluo09 <39718951+lexluo09@users.noreply.github.com> Date: Fri, 13 Oct 2023 16:32:59 +0800 Subject: [PATCH] (improvement)(chat) optimize start stop build scripts and the runtime dir does not exist move all to runtime (#209) --- assembly/bin/supersonic-build.sh | 35 +--------- assembly/bin/supersonic-common.sh | 104 ++++++++++++++++++++++++++++++ assembly/bin/supersonic-daemon.sh | 94 ++++----------------------- 3 files changed, 118 insertions(+), 115 deletions(-) create mode 100755 assembly/bin/supersonic-common.sh diff --git a/assembly/bin/supersonic-build.sh b/assembly/bin/supersonic-build.sh index f09043f3f..023258e7c 100755 --- a/assembly/bin/supersonic-build.sh +++ b/assembly/bin/supersonic-build.sh @@ -1,14 +1,8 @@ #!/usr/bin/env bash set -x - -# pip path -pip_path=${PIP_PATH:-"pip3"} - -sbinDir=$(cd "$(dirname "$0")"; pwd) -baseDir=$(cd "$sbinDir/.." && pwd -P) -runtimeDir=$baseDir/../runtime -buildDir=$baseDir/build +chmod +x supersonic-common.sh +source supersonic-common.sh cd $baseDir @@ -44,30 +38,7 @@ ${pip_path} install -r ${requirementPath} echo "install python modules success" #6. reset runtime -function setEnvToWeb { - model_name=$1 - json='{"env": "'$model_name'"}' - echo $json > ${runtimeDir}/supersonic-${model_name}/webapp/supersonic.config.json - echo $json > ../../launchers/${model_name}/target/classes/webapp/supersonic.config.json -} - -function moveToRuntime { - model_name=$1 - tar -zxvf ${buildDir}/supersonic-${model_name}.tar.gz -C ${runtimeDir} - mv ${runtimeDir}/launchers-${model_name}-* ${runtimeDir}/supersonic-${model_name} - - mkdir -p ${runtimeDir}/supersonic-${model_name}/webapp - cp -fr ${buildDir}/webapp/* ${runtimeDir}/supersonic-${model_name}/webapp -} - -mkdir -p ${runtimeDir} rm -fr $runtimeDir/* - -moveToRuntime chat -moveToRuntime semantic -moveToRuntime standalone - -setEnvToWeb chat -setEnvToWeb semantic +moveAllToRuntime rm -fr ${buildDir}/webapp diff --git a/assembly/bin/supersonic-common.sh b/assembly/bin/supersonic-common.sh new file mode 100755 index 000000000..b8d884479 --- /dev/null +++ b/assembly/bin/supersonic-common.sh @@ -0,0 +1,104 @@ +#!/usr/bin/env bash + +# environment parameters +python_path=${PYTHON_PATH:-"python3"} +pip_path=${PIP_PATH:-"pip3"} + +readonly CHAT_APP_NAME="supersonic_chat" +readonly SEMANTIC_APP_NAME="supersonic_semantic" +readonly LLMPARSER_APP_NAME="supersonic_llmparser" +readonly STANDALONE_APP_NAME="supersonic_standalone" +readonly CHAT_SERVICE="chat" +readonly SEMANTIC_SERVICE="semantic" +readonly LLMPARSER_SERVICE="llmparser" +readonly STANDALONE_SERVICE="standalone" +readonly LLMPARSER_HOST="127.0.0.1" +readonly LLMPARSER_PORT="9092" + +sbinDir=$(cd "$(dirname "$0")"; pwd) +baseDir=$(cd "$sbinDir/.." && pwd -P) +runtimeDir=$baseDir/../runtime +buildDir=$baseDir/build + +function setEnvToWeb { + model_name=$1 + json='{"env": "'$model_name'"}' + echo $json > ${runtimeDir}/supersonic-${model_name}/webapp/supersonic.config.json + echo $json > ../../launchers/${model_name}/target/classes/webapp/supersonic.config.json +} + +function moveToRuntime { + model_name=$1 + tar -zxvf ${buildDir}/supersonic-${model_name}.tar.gz -C ${runtimeDir} + mv ${runtimeDir}/launchers-${model_name}-* ${runtimeDir}/supersonic-${model_name} + + mkdir -p ${runtimeDir}/supersonic-${model_name}/webapp + cp -fr ${buildDir}/webapp/* ${runtimeDir}/supersonic-${model_name}/webapp +} + +function moveAllToRuntime { + mkdir -p ${runtimeDir} + moveToRuntime chat + moveToRuntime semantic + moveToRuntime standalone + + setEnvToWeb chat + setEnvToWeb semantic +} + +# run java service +function runJavaService { + javaRunDir=${runtimeDir}/supersonic-${model_name} + local_app_name=$1 + libDir=$javaRunDir/lib + confDir=$javaRunDir/conf + + CLASSPATH="" + CLASSPATH=$CLASSPATH:$confDir + + for jarPath in $libDir/*.jar; do + CLASSPATH=$CLASSPATH:$jarPath + done + + export CLASSPATH + export LANG="zh_CN.UTF-8" + + cd $javaRunDir + if [[ "$JAVA_HOME" == "" ]]; then + JAVA_HOME=$(ls /usr/jdk64/jdk* -d 2>/dev/null | xargs | awk '{print "'$local_app_name'"}') + fi + export PATH=$JAVA_HOME/bin:$PATH + command="-Dfile.encoding="UTF-8" -Duser.language="Zh" -Duser.region="CN" -Duser.timezone="GMT+08" -Dapp_name=${local_app_name} -Xms1024m -Xmx2048m "$main_class + + mkdir -p $javaRunDir/logs + if [[ "$is_test" == "true" ]]; then + java -Dspring.profiles.active="dev" $command >/dev/null 2>$javaRunDir/logs/error.log & + else + java $command $javaRunDir >/dev/null 2>$javaRunDir/logs/error.log & + fi +} + +# run python service +function runPythonService { + pythonRunDir=${runtimeDir}/supersonic-${model_name}/llmparser + cd $pythonRunDir + nohup ${python_path} supersonic_llmparser.py > $pythonRunDir/llmparser.log 2>&1 & + # add health check + for i in {1..10} + do + echo "llmparser health check attempt $i..." + response=$(curl -s http://${LLMPARSER_HOST}:${LLMPARSER_PORT}/health) + echo "llmparser health check response: $response" + status_ok="Healthy" + if [[ $response == *$status_ok* ]] ; then + echo "llmparser Health check passed." + break + else + if [ "$i" -eq 10 ]; then + echo "llmparser Health check failed after 10 attempts. Exiting." + fi + echo "Retrying after 5 seconds..." + sleep 5 + fi + done +} \ No newline at end of file diff --git a/assembly/bin/supersonic-daemon.sh b/assembly/bin/supersonic-daemon.sh index 791fecac3..dd63442e1 100755 --- a/assembly/bin/supersonic-daemon.sh +++ b/assembly/bin/supersonic-daemon.sh @@ -1,27 +1,16 @@ #!/usr/bin/env bash -python_path=${PYTHON_PATH:-"python3"} -set -x +chmod +x supersonic-common.sh +source supersonic-common.sh -readonly CHAT_APP_NAME="supersonic_chat" -readonly SEMANTIC_APP_NAME="supersonic_semantic" -readonly LLMPARSER_APP_NAME="supersonic_llmparser" -readonly STANDALONE_APP_NAME="supersonic_standalone" -readonly CHAT_SERVICE="chat" -readonly SEMANTIC_SERVICE="semantic" -readonly LLMPARSER_SERVICE="llmparser" -readonly STANDALONE_SERVICE="standalone" -readonly LLMPARSER_HOST="127.0.0.1" -readonly LLMPARSER_PORT="9092" - -sbinDir=$(cd "$(dirname "$0")"; pwd) -baseDir=$(cd "$sbinDir/.." && pwd -P) -runtimeDir=$baseDir/../runtime -buildDir=$baseDir/build +# 1.init environment parameters +if [ ! -d "$runtimeDir" ]; then + echo "the runtime dir does not exist move all to runtime" + moveAllToRuntime +fi command=$1 service=$2 - if [ -z "$service" ]; then service=${STANDALONE_SERVICE} fi @@ -36,6 +25,7 @@ fi cd $baseDir +# 2.set main class function setMainClass { if [ "$service" == $CHAT_SERVICE ]; then main_class="com.tencent.supersonic.ChatLauncher" @@ -43,7 +33,8 @@ function setMainClass { main_class="com.tencent.supersonic.SemanticLauncher" fi } - +setMainClass +# 3.set app name function setAppName { if [ "$service" == $CHAT_SERVICE ]; then app_name=$CHAT_APP_NAME @@ -53,64 +44,7 @@ function setAppName { app_name=$LLMPARSER_APP_NAME fi } - setAppName -setMainClass - -function runJavaService { - javaRunDir=${runtimeDir}/supersonic-${model_name} - local_app_name=$1 - libDir=$javaRunDir/lib - confDir=$javaRunDir/conf - - CLASSPATH="" - CLASSPATH=$CLASSPATH:$confDir - - for jarPath in $libDir/*.jar; do - CLASSPATH=$CLASSPATH:$jarPath - done - - export CLASSPATH - export LANG="zh_CN.UTF-8" - - cd $javaRunDir - if [[ "$JAVA_HOME" == "" ]]; then - JAVA_HOME=$(ls /usr/jdk64/jdk* -d 2>/dev/null | xargs | awk '{print "'$local_app_name'"}') - fi - export PATH=$JAVA_HOME/bin:$PATH - command="-Dfile.encoding="UTF-8" -Duser.language="Zh" -Duser.region="CN" -Duser.timezone="GMT+08" -Dapp_name=${local_app_name} -Xms1024m -Xmx2048m "$main_class - - mkdir -p $javaRunDir/logs - if [[ "$is_test" == "true" ]]; then - java -Dspring.profiles.active="dev" $command >/dev/null 2>$javaRunDir/logs/error.log & - else - java $command $javaRunDir >/dev/null 2>$javaRunDir/logs/error.log & - fi -} - -function runPythonService { - pythonRunDir=${runtimeDir}/supersonic-${model_name}/llmparser - cd $pythonRunDir - nohup ${python_path} supersonic_llmparser.py > $pythonRunDir/llmparser.log 2>&1 & - # Add health check - for i in {1..10} - do - echo "llmparser health check attempt $i..." - response=$(curl -s http://${LLMPARSER_HOST}:${LLMPARSER_PORT}/health) - echo "llmparser health check response: $response" - status_ok="Healthy" - if [[ $response == *$status_ok* ]] ; then - echo "llmparser Health check passed." - break - else - if [ "$i" -eq 10 ]; then - echo "llmparser Health check failed after 10 attempts. Exiting." - fi - echo "Retrying after 5 seconds..." - sleep 5 - fi - done -} function reloadExamples { pythonRunDir=${runtimeDir}/supersonic-${model_name}/llmparser @@ -118,13 +52,6 @@ function reloadExamples { ${python_path} examples_reload_run.py } -function getProcesName { - process_name=$main_class - if [[ ${app_name} == $LLMPARSER_APP_NAME ]]; then - process_name=$app_name - fi - echo $process_name -} function start() { @@ -162,6 +89,7 @@ function reload() fi } +# 4. execute command operation case "$command" in start) if [ "$service" == $STANDALONE_SERVICE ]; then