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