AdvisorServer/shell/prod/deploy_advisor.sh
2025-02-24 20:05:20 +08:00

56 lines
1.4 KiB
Bash
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
# 当前服务器上的文件路径
JAR_FILE="/tmp/AdvisorServer-2.6.7.jar"
# 目标服务器信息格式IP地址:端口)
SERVERS=(
"172.26.1.3:22"
"172.26.1.7:22"
"172.26.1.9:22"
"172.26.1.15:22"
)
# 目标路径
TARGET_DIR="/home/ubuntu"
# 1. 循环拷贝文件到所有服务器
for SERVER in "${SERVERS[@]}"; do
# 获取 IP 和端口
IP=$(echo $SERVER | cut -d ':' -f 1)
PORT=$(echo $SERVER | cut -d ':' -f 2)
# 拷贝 JAR 文件到目标服务器
echo "Copying $JAR_FILE to $IP:$TARGET_DIR"
scp -P $PORT $JAR_FILE ubuntu@$IP:$TARGET_DIR
done
echo "Files copied to all servers."
# 2. 所有文件拷贝完成后,停止服务
for SERVER in "${SERVERS[@]}"; do
# 获取 IP 和端口
IP=$(echo $SERVER | cut -d ':' -f 1)
PORT=$(echo $SERVER | cut -d ':' -f 2)
# 执行 start.sh 脚本
echo "Stopping $START_SCRIPT on $IP"
ssh -p $PORT ubuntu@$IP "sudo systemctl stop advisor-server"
done
echo "All services stopped."
# 3. 所有文件拷贝完成后,启动服务
for SERVER in "${SERVERS[@]}"; do
# 获取 IP 和端口
IP=$(echo $SERVER | cut -d ':' -f 1)
PORT=$(echo $SERVER | cut -d ':' -f 2)
# 执行 start.sh 脚本
echo "Starting $START_SCRIPT on $IP"
ssh -p $PORT ubuntu@$IP "sudo systemctl start advisor-server"
done
echo "All services started."
echo "All tasks completed."