Skip to content

Commit 05a9309

Browse files
committed
完善修改启动脚本中端口的逻辑,能正确让服务运行在指定端口
1 parent 4836b5a commit 05a9309

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

internal/deploy/service/deploy_service.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,22 @@ func (f *floyDeployService) modifyStartScript(tempDir string, port int) error {
14251425
return nil
14261426
}
14271427

1428+
// 检查是否已经是新版本的脚本(从配置文件读取端口)
1429+
if strings.Contains(contentStr, "从配置文件读取端口") {
1430+
// 如果已经是新版本脚本,只需要更新端口号
1431+
oldPattern := `SERVICE_PORT="8080"`
1432+
newPattern := fmt.Sprintf(`SERVICE_PORT="%d"`, port)
1433+
newContent := strings.Replace(contentStr, oldPattern, newPattern, -1)
1434+
1435+
err = os.WriteFile(startScriptPath, []byte(newContent), 0755)
1436+
if err != nil {
1437+
return fmt.Errorf("写入启动脚本失败: %v", err)
1438+
}
1439+
1440+
fmt.Printf("更新启动脚本端口,端口: %d\n", port)
1441+
return nil
1442+
}
1443+
14281444
// 替换环境变量设置,改为从配置文件读取端口
14291445
oldPattern := `export SERVICE_PORT="${SERVICE_PORT:-8080}"`
14301446
newPattern := fmt.Sprintf(`# 从配置文件读取端口

0 commit comments

Comments
 (0)