fusenapi/run_all_server.sh
2023-07-19 10:59:13 +08:00

48 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
# 定义一个函数来在每个服务器目录下运行 go run <server_name>.go
run_server() {
server_name=$1
echo "Running $server_name"
# 如果之前存在相同名字的 screen 会话,先将其终止
existing_session=$(screen -ls | grep -w "$server_name")
if [ -n "$existing_session" ]; then
echo "Terminating existing screen session for $server_name"
screen -S "$server_name" -X quit
fi
# 导航到相应的目录
cd server/$server_name
# 使用 screen 运行 go run <server_name>.go
screen -dmS $server_name -L go run $server_name.go
# 返回到上一级目录
cd - > /dev/null
}
# 列出所有服务器目录
server_dirs=("backend" "canteen" "data-transfer" "home-user-auth" "inventory" "map-library" "orders" "product" "product-model" "product-template" "shopping-cart-confirmation" "upload" "webset")
# 在每个服务器目录下运行相应的 go 程序
for server_dir in "${server_dirs[@]}"; do
run_server $server_dir
done
# 定义目录和screen名称
dir_path="./proxyserver"
screen_name="proxyserver"
# 进入目录
cd $dir_path
# 检查是否存在screen session
if screen -list | grep -q "$screen_name"; then
# 结束存在的screen session
screen -S $screen_name -X quit
fi
# 启动新的screen session并运行go程序
screen -dmS $screen_name -L go run main.go