mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2025-12-25 11:36:35 +08:00
服务配置校验错误后仍然继续解析,不再停止运行
This commit is contained in:
@@ -7,8 +7,10 @@ import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"io/ioutil"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
var sharedNodeConfig *NodeConfig = nil
|
||||
@@ -76,7 +78,8 @@ func (this *NodeConfig) Init() error {
|
||||
for _, server := range this.Servers {
|
||||
err := server.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
// 这里不返回错误,而是继续往下,防止单个服务错误而影响其他服务
|
||||
logs.Println("[INIT]server '" + strconv.FormatInt(server.Id, 10) + "' init failed: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,6 +121,9 @@ func (this *NodeConfig) Init() error {
|
||||
this.firewallPolicies = append(this.firewallPolicies, this.HTTPFirewallPolicy)
|
||||
}
|
||||
for _, server := range this.Servers {
|
||||
if !server.IsOk() || !server.IsOn {
|
||||
continue
|
||||
}
|
||||
if server.Web != nil {
|
||||
this.lookupWeb(server.Web)
|
||||
}
|
||||
@@ -130,7 +136,7 @@ func (this *NodeConfig) Init() error {
|
||||
func (this *NodeConfig) AvailableGroups() []*serverconfigs.ServerGroup {
|
||||
groupMapping := map[string]*serverconfigs.ServerGroup{} // protocol://addr => Server Group
|
||||
for _, server := range this.Servers {
|
||||
if !server.IsOn {
|
||||
if !server.IsOk() || !server.IsOn {
|
||||
continue
|
||||
}
|
||||
for _, addr := range server.FullAddresses() {
|
||||
|
||||
@@ -30,6 +30,8 @@ type ServerConfig struct {
|
||||
// 反向代理配置
|
||||
ReverseProxyRef *ReverseProxyRef `yaml:"reverseProxyRef" json:"reverseProxyRef"`
|
||||
ReverseProxy *ReverseProxyConfig `yaml:"reverseProxy" json:"reverseProxy"`
|
||||
|
||||
isOk bool
|
||||
}
|
||||
|
||||
// 从JSON中解析Server配置
|
||||
@@ -107,9 +109,16 @@ func (this *ServerConfig) Init() error {
|
||||
}
|
||||
}
|
||||
|
||||
this.isOk = true
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 配置是否正确
|
||||
func (this *ServerConfig) IsOk() bool {
|
||||
return this.isOk
|
||||
}
|
||||
|
||||
func (this *ServerConfig) FullAddresses() []string {
|
||||
result := []string{}
|
||||
if this.HTTP != nil && this.HTTP.IsOn {
|
||||
|
||||
Reference in New Issue
Block a user