58 lines
1.5 KiB
Smarty
58 lines
1.5 KiB
Smarty
#! /bin/bash
|
||
|
||
# 获取当前脚本的全局路径
|
||
script_path=$(realpath "$0")
|
||
|
||
# 获取当前脚本的目录
|
||
script_dir=$(dirname "$script_path")
|
||
|
||
# 执行更新最新的包
|
||
$script_dir/update_fspkg_master.sh
|
||
|
||
# 拼接service_config.ini的路径
|
||
config_file="$script_dir/server/service_config.ini"
|
||
|
||
# 检查文件是否存在
|
||
if [[ ! -f "$config_file" ]]; then
|
||
echo "Error: service_config.ini 文件不存在"
|
||
exit 1
|
||
fi
|
||
|
||
echo "read $config_file"
|
||
service_name=$(grep "SERVICE_NAME=" $config_file | cut -d'=' -f2 | cut -d' ' -f1)
|
||
|
||
# 输出变量值
|
||
echo "service name: $service_name"
|
||
|
||
cd $script_dir/proto
|
||
git pull origin master
|
||
cd $script_dir
|
||
go run -gcflags="-N" proto/goutils/proto_build/main.go
|
||
|
||
run_server() {
|
||
# 导航到相应的目录
|
||
cd $script_dir/server
|
||
echo "build $service_name"
|
||
go build -o $service_name
|
||
|
||
# 如果之前存在相同名字的 screen 会话,先将其终止
|
||
# 首先尝试关闭已存在的screen会话
|
||
existing_session=$(screen -ls | grep -w "$service_name")
|
||
if [ -n "$existing_session" ]; then
|
||
echo "Terminating existing screen session for $service_name"
|
||
screen -S "$service_name" -X quit
|
||
while [[ $(screen -ls | grep "\.$service_name\s") ]]; do
|
||
sleep 0.1s # 等待0.1秒后再次检查
|
||
echo "wait for $service_name"
|
||
done
|
||
fi
|
||
|
||
# 循环检查screen进程是否存在
|
||
|
||
[ -f .gitignore ] || (echo "server" > .gitignore && echo "$service_name" >> .gitignore && echo "main" >> .gitignore)
|
||
|
||
echo "Running $service_name"
|
||
screen -dmS $service_name -L ./$service_name
|
||
}
|
||
|
||
run_server |