调整后的代码
This commit is contained in:
+1
-1
@@ -19,7 +19,7 @@ RUN CGO_ENABLED=0 GOOS=linux go build \
|
|||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
# 先切换到国内镜像源,再安装包
|
# 先切换到国内镜像源,再安装包
|
||||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
|
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
|
||||||
RUN apk --no-cache add ca-certificates tzdata sqlite
|
RUN apk --no-cache add ca-certificates tzdata sqlite bash
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ poolCount = {{.PoolCount}}
|
|||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
[webServer]
|
[webServer]
|
||||||
addr = "127.0.0.1:{{.AdminPort}}"
|
addr = "127.0.0.1"
|
||||||
|
port = {{.AdminPort}}
|
||||||
|
|
||||||
{{range .Proxies}}
|
{{range .Proxies}}
|
||||||
[[proxies]]
|
[[proxies]]
|
||||||
|
|||||||
+14
-13
@@ -58,8 +58,8 @@ const (
|
|||||||
PhaseDegraded ProcessPhase = "DEGRADED"
|
PhaseDegraded ProcessPhase = "DEGRADED"
|
||||||
PhaseFailed ProcessPhase = "FAILED"
|
PhaseFailed ProcessPhase = "FAILED"
|
||||||
PhaseStopped ProcessPhase = "STOPPED"
|
PhaseStopped ProcessPhase = "STOPPED"
|
||||||
PhaseStopping ProcessPhase = "STOPPING" // 正在停止中
|
PhaseStopping ProcessPhase = "STOPPING"
|
||||||
PhaseConflict ProcessPhase = "CONFLICT" // 检测到多实例冲突
|
PhaseConflict ProcessPhase = "CONFLICT"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ================================================================
|
// ================================================================
|
||||||
@@ -76,7 +76,7 @@ type FrpcInstance struct {
|
|||||||
ParentPID int
|
ParentPID int
|
||||||
ExecPath string
|
ExecPath string
|
||||||
CmdLine string
|
CmdLine string
|
||||||
Owned bool // 是否由当前 ProcessManager 管理
|
Owned bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProcessState struct {
|
type ProcessState struct {
|
||||||
@@ -98,15 +98,10 @@ type ProcessState struct {
|
|||||||
LastError string `json:"last_error,omitempty"`
|
LastError string `json:"last_error,omitempty"`
|
||||||
Error string `json:"error,omitempty"`
|
Error string `json:"error,omitempty"`
|
||||||
|
|
||||||
// 冲突检测信息
|
|
||||||
Conflicts []FrpcInstance `json:"conflicts,omitempty"`
|
Conflicts []FrpcInstance `json:"conflicts,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
// PortStatus 兼容旧接口
|
||||||
globalManager *ProcessManager
|
|
||||||
globalMu sync.Mutex
|
|
||||||
)
|
|
||||||
|
|
||||||
type PortStatus struct {
|
type PortStatus struct {
|
||||||
Port int `json:"port"`
|
Port int `json:"port"`
|
||||||
Occupied bool `json:"occupied"`
|
Occupied bool `json:"occupied"`
|
||||||
@@ -115,6 +110,7 @@ type PortStatus struct {
|
|||||||
ProcessCmd string `json:"process_cmd,omitempty"`
|
ProcessCmd string `json:"process_cmd,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FRPCStatus 来自 frpc admin API 的状态响应
|
||||||
type FRPCStatus struct {
|
type FRPCStatus struct {
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
RunID string `json:"run_id"`
|
RunID string `json:"run_id"`
|
||||||
@@ -126,6 +122,15 @@ type FRPCStatus struct {
|
|||||||
} `json:"proxies"`
|
} `json:"proxies"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ================================================================
|
||||||
|
// 全局变量
|
||||||
|
// ================================================================
|
||||||
|
|
||||||
|
var (
|
||||||
|
globalManager *ProcessManager
|
||||||
|
globalMu sync.Mutex
|
||||||
|
)
|
||||||
|
|
||||||
// ================================================================
|
// ================================================================
|
||||||
// ProcessManager 主结构
|
// ProcessManager 主结构
|
||||||
// ================================================================
|
// ================================================================
|
||||||
@@ -149,12 +154,8 @@ type ProcessManager struct {
|
|||||||
lockFile *os.File
|
lockFile *os.File
|
||||||
locked bool
|
locked bool
|
||||||
|
|
||||||
// 当前状态缓存
|
|
||||||
currentPhase ProcessPhase
|
currentPhase ProcessPhase
|
||||||
statusMu sync.RWMutex
|
statusMu sync.RWMutex
|
||||||
|
|
||||||
// 取消函数(用于停止健康检查)
|
|
||||||
cancelFunc context.CancelFunc
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================================================================
|
// ================================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user