服务配置校验错误后仍然继续解析,不再停止运行
This commit is contained in:
@@ -7,8 +7,10 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
|
"github.com/iwind/TeaGo/logs"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
var sharedNodeConfig *NodeConfig = nil
|
var sharedNodeConfig *NodeConfig = nil
|
||||||
@@ -76,7 +78,8 @@ func (this *NodeConfig) Init() error {
|
|||||||
for _, server := range this.Servers {
|
for _, server := range this.Servers {
|
||||||
err := server.Init()
|
err := server.Init()
|
||||||
if err != nil {
|
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)
|
this.firewallPolicies = append(this.firewallPolicies, this.HTTPFirewallPolicy)
|
||||||
}
|
}
|
||||||
for _, server := range this.Servers {
|
for _, server := range this.Servers {
|
||||||
|
if !server.IsOk() || !server.IsOn {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if server.Web != nil {
|
if server.Web != nil {
|
||||||
this.lookupWeb(server.Web)
|
this.lookupWeb(server.Web)
|
||||||
}
|
}
|
||||||
@@ -130,7 +136,7 @@ func (this *NodeConfig) Init() error {
|
|||||||
func (this *NodeConfig) AvailableGroups() []*serverconfigs.ServerGroup {
|
func (this *NodeConfig) AvailableGroups() []*serverconfigs.ServerGroup {
|
||||||
groupMapping := map[string]*serverconfigs.ServerGroup{} // protocol://addr => Server Group
|
groupMapping := map[string]*serverconfigs.ServerGroup{} // protocol://addr => Server Group
|
||||||
for _, server := range this.Servers {
|
for _, server := range this.Servers {
|
||||||
if !server.IsOn {
|
if !server.IsOk() || !server.IsOn {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for _, addr := range server.FullAddresses() {
|
for _, addr := range server.FullAddresses() {
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ type ServerConfig struct {
|
|||||||
// 反向代理配置
|
// 反向代理配置
|
||||||
ReverseProxyRef *ReverseProxyRef `yaml:"reverseProxyRef" json:"reverseProxyRef"`
|
ReverseProxyRef *ReverseProxyRef `yaml:"reverseProxyRef" json:"reverseProxyRef"`
|
||||||
ReverseProxy *ReverseProxyConfig `yaml:"reverseProxy" json:"reverseProxy"`
|
ReverseProxy *ReverseProxyConfig `yaml:"reverseProxy" json:"reverseProxy"`
|
||||||
|
|
||||||
|
isOk bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从JSON中解析Server配置
|
// 从JSON中解析Server配置
|
||||||
@@ -107,9 +109,16 @@ func (this *ServerConfig) Init() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.isOk = true
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 配置是否正确
|
||||||
|
func (this *ServerConfig) IsOk() bool {
|
||||||
|
return this.isOk
|
||||||
|
}
|
||||||
|
|
||||||
func (this *ServerConfig) FullAddresses() []string {
|
func (this *ServerConfig) FullAddresses() []string {
|
||||||
result := []string{}
|
result := []string{}
|
||||||
if this.HTTP != nil && this.HTTP.IsOn {
|
if this.HTTP != nil && this.HTTP.IsOn {
|
||||||
|
|||||||
Reference in New Issue
Block a user