33 lines
797 B
Bash
33 lines
797 B
Bash
|
#!/bin/bash
|
||
|
|
||
|
replica_id=5
|
||
|
|
||
|
change_config(){
|
||
|
|
||
|
server_name=$1
|
||
|
config_file="server/${server_name}/etc/${server_name}.yaml"
|
||
|
|
||
|
# 无论ReplicaId存在与否,都重置replica_id
|
||
|
((replica_id+=5))
|
||
|
|
||
|
if ! grep -q "ReplicaId:" "$config_file"; then
|
||
|
|
||
|
sed -i "s/^Port:.*$/&\nReplicaId: $replica_id/" "$config_file"
|
||
|
echo "Added ReplicaId: $replica_id to $config_file"
|
||
|
|
||
|
else
|
||
|
|
||
|
exist_id=$(grep -oP "ReplicaId:\s*\K[0-9]+" "$config_file")
|
||
|
sed -i "s/^ReplicaId:.*$/ReplicaId: $replica_id/" "$config_file"
|
||
|
echo "Updated ReplicaId to $replica_id in $config_file"
|
||
|
|
||
|
fi
|
||
|
|
||
|
}
|
||
|
|
||
|
# 读取server目录,忽略指定的三个目录
|
||
|
server_dirs=($(cd server && ls | grep -vE "backend|product-template|product-model"))
|
||
|
|
||
|
for server_dir in "${server_dirs[@]}"; do
|
||
|
change_config $server_dir
|
||
|
done
|