针对控制面自重启问题的调整
This commit is contained in:
+1
-1
@@ -19,7 +19,7 @@ RUN CGO_ENABLED=0 GOOS=linux go build \
|
||||
FROM alpine:latest
|
||||
# 先切换到国内镜像源,再安装包
|
||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
|
||||
RUN apk --no-cache add ca-certificates tzdata sqlite bash net-tools curl iproute2
|
||||
RUN apk --no-cache add ca-certificates tzdata sqlite bash curl iproute2
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
|
||||
+12
-3
@@ -2,6 +2,7 @@ package frp
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -104,13 +105,20 @@ func Reload() error {
|
||||
return err
|
||||
}
|
||||
|
||||
if status.Phase != "RUNNING" {
|
||||
// 只有在 FAILED 或 STOPPED 时才启动(恢复)
|
||||
// 其他状态(RUNNING、DEGRADED、STARTING)应该执行热加载而不是启动
|
||||
if status.Phase == "FAILED" || status.Phase == "STOPPED" {
|
||||
log.Printf("[DEBUG] Reload: 状态 %s,执行启动恢复", status.Phase)
|
||||
return pm.Start(context.Background())
|
||||
}
|
||||
|
||||
// RUNNING / DEGRADED / STARTING 状态:执行真正的热加载
|
||||
log.Printf("[DEBUG] Reload: 状态 %s,执行配置热加载", status.Phase)
|
||||
|
||||
// 执行 frpc reload 命令
|
||||
frpcPath, err := GetFrpcPath()
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("获取 frpc 路径失败: %w", err)
|
||||
}
|
||||
|
||||
cmd := exec.Command(frpcPath, "reload", "-c", "./data/frpc.toml")
|
||||
@@ -118,8 +126,9 @@ func Reload() error {
|
||||
if err != nil {
|
||||
log.Printf("⚠️ 热加载失败 (%v),降级为重启 frpc", err)
|
||||
log.Printf(" reload 输出: %s", string(output))
|
||||
// 降级:重启
|
||||
if err := pm.Restart(context.Background()); err != nil {
|
||||
return err
|
||||
return fmt.Errorf("重启 frpc 失败: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user