mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-07 10:40:26 +08:00
节点启动时如果加载的是本地配置则在网络恢复后重新加载配置
This commit is contained in:
@@ -145,6 +145,16 @@ func (this *APIStream) handleConnectedAPINode(message *pb.NodeStreamMessage) err
|
|||||||
return errors.Wrap(err)
|
return errors.Wrap(err)
|
||||||
}
|
}
|
||||||
remotelogs.Println("API_STREAM", "connected to api node '"+strconv.FormatInt(msg.APINodeId, 10)+"'")
|
remotelogs.Println("API_STREAM", "connected to api node '"+strconv.FormatInt(msg.APINodeId, 10)+"'")
|
||||||
|
|
||||||
|
// 重新读取配置
|
||||||
|
if nodeConfigUpdatedAt == 0 {
|
||||||
|
select {
|
||||||
|
case nodeConfigChangedNotify <- true:
|
||||||
|
default:
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,11 +27,14 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var sharedNodeConfig *nodeconfigs.NodeConfig
|
var sharedNodeConfig *nodeconfigs.NodeConfig
|
||||||
var nodeTaskNotify = make(chan bool, 8)
|
var nodeTaskNotify = make(chan bool, 8)
|
||||||
|
var nodeConfigChangedNotify = make(chan bool, 8)
|
||||||
|
var nodeConfigUpdatedAt int64
|
||||||
var DaemonIsOn = false
|
var DaemonIsOn = false
|
||||||
var DaemonPid = 0
|
var DaemonPid = 0
|
||||||
|
|
||||||
@@ -39,6 +42,7 @@ var DaemonPid = 0
|
|||||||
type Node struct {
|
type Node struct {
|
||||||
isLoaded bool
|
isLoaded bool
|
||||||
sock *gosock.Sock
|
sock *gosock.Sock
|
||||||
|
locker sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNode() *Node {
|
func NewNode() *Node {
|
||||||
@@ -280,6 +284,9 @@ func (this *Node) loop() error {
|
|||||||
|
|
||||||
// 读取API配置
|
// 读取API配置
|
||||||
func (this *Node) syncConfig() error {
|
func (this *Node) syncConfig() error {
|
||||||
|
this.locker.Lock()
|
||||||
|
defer this.locker.Unlock()
|
||||||
|
|
||||||
// 检查api.yaml是否存在
|
// 检查api.yaml是否存在
|
||||||
apiConfigFile := Tea.ConfigFile("api.yaml")
|
apiConfigFile := Tea.ConfigFile("api.yaml")
|
||||||
_, err := os.Stat(apiConfigFile)
|
_, err := os.Stat(apiConfigFile)
|
||||||
@@ -315,6 +322,7 @@ func (this *Node) syncConfig() error {
|
|||||||
if !configResp.IsChanged {
|
if !configResp.IsChanged {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
nodeConfigUpdatedAt = time.Now().Unix()
|
||||||
|
|
||||||
configJSON := configResp.NodeJSON
|
configJSON := configResp.NodeJSON
|
||||||
nodeConfig := &nodeconfigs.NodeConfig{}
|
nodeConfig := &nodeconfigs.NodeConfig{}
|
||||||
@@ -398,6 +406,12 @@ func (this *Node) startSyncTimer() {
|
|||||||
remotelogs.Error("NODE", "sync config error: "+err.Error())
|
remotelogs.Error("NODE", "sync config error: "+err.Error())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
case <-nodeConfigChangedNotify:
|
||||||
|
err := this.syncConfig()
|
||||||
|
if err != nil {
|
||||||
|
remotelogs.Error("NODE", "sync config error: "+err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|||||||
Reference in New Issue
Block a user