执行一般命令时不运行init()中内容

This commit is contained in:
刘祥超
2023-03-10 15:14:14 +08:00
parent f64b36f17a
commit de9e1a4515
40 changed files with 148 additions and 15 deletions

11
internal/apps/main.go Normal file
View File

@@ -0,0 +1,11 @@
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package apps
import teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
func RunMain(f func()) {
if teaconst.IsMain {
f()
}
}

View File

@@ -3,6 +3,7 @@ package caches
import ( import (
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/events" "github.com/TeaOSLab/EdgeNode/internal/events"
"github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/TeaOSLab/EdgeNode/internal/remotelogs"
"github.com/iwind/TeaGo/lists" "github.com/iwind/TeaGo/lists"
@@ -14,6 +15,10 @@ import (
var SharedManager = NewManager() var SharedManager = NewManager()
func init() { func init() {
if !teaconst.IsMain {
return
}
events.On(events.EventQuit, func() { events.On(events.EventQuit, func() {
remotelogs.Println("CACHE", "quiting cache manager") remotelogs.Println("CACHE", "quiting cache manager")
SharedManager.UpdatePolicies([]*serverconfigs.HTTPCachePolicy{}) SharedManager.UpdatePolicies([]*serverconfigs.HTTPCachePolicy{})

View File

@@ -11,7 +11,7 @@ import (
var sharedBrotliReaderPool *ReaderPool var sharedBrotliReaderPool *ReaderPool
func init() { func init() {
if teaconst.IsDaemon { if !teaconst.IsMain {
return return
} }

View File

@@ -11,7 +11,7 @@ import (
var sharedDeflateReaderPool *ReaderPool var sharedDeflateReaderPool *ReaderPool
func init() { func init() {
if teaconst.IsDaemon { if !teaconst.IsMain {
return return
} }

View File

@@ -11,7 +11,7 @@ import (
var sharedGzipReaderPool *ReaderPool var sharedGzipReaderPool *ReaderPool
func init() { func init() {
if teaconst.IsDaemon { if !teaconst.IsMain {
return return
} }

View File

@@ -11,7 +11,7 @@ import (
var sharedZSTDReaderPool *ReaderPool var sharedZSTDReaderPool *ReaderPool
func init() { func init() {
if teaconst.IsDaemon { if !teaconst.IsMain {
return return
} }

View File

@@ -12,7 +12,7 @@ import (
var sharedBrotliWriterPool *WriterPool var sharedBrotliWriterPool *WriterPool
func init() { func init() {
if teaconst.IsDaemon { if !teaconst.IsMain {
return return
} }

View File

@@ -12,7 +12,7 @@ import (
var sharedDeflateWriterPool *WriterPool var sharedDeflateWriterPool *WriterPool
func init() { func init() {
if teaconst.IsDaemon { if !teaconst.IsMain {
return return
} }

View File

@@ -12,7 +12,7 @@ import (
var sharedGzipWriterPool *WriterPool var sharedGzipWriterPool *WriterPool
func init() { func init() {
if teaconst.IsDaemon { if !teaconst.IsMain {
return return
} }

View File

@@ -12,7 +12,7 @@ import (
var sharedZSTDWriterPool *WriterPool var sharedZSTDWriterPool *WriterPool
func init() { func init() {
if teaconst.IsDaemon { if !teaconst.IsMain {
return return
} }

View File

@@ -15,7 +15,7 @@ var (
NodeId int64 = 0 NodeId int64 = 0
NodeIdString = "" NodeIdString = ""
IsDaemon = len(os.Args) > 1 && os.Args[1] == "daemon" IsMain = len(os.Args) == 1
GlobalProductName = nodeconfigs.DefaultProductName GlobalProductName = nodeconfigs.DefaultProductName

View File

@@ -9,6 +9,7 @@ import (
"errors" "errors"
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ddosconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ddosconfigs"
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/events" "github.com/TeaOSLab/EdgeNode/internal/events"
"github.com/TeaOSLab/EdgeNode/internal/firewalls/nftables" "github.com/TeaOSLab/EdgeNode/internal/firewalls/nftables"
"github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/TeaOSLab/EdgeNode/internal/remotelogs"
@@ -27,6 +28,10 @@ import (
var SharedDDoSProtectionManager = NewDDoSProtectionManager() var SharedDDoSProtectionManager = NewDDoSProtectionManager()
func init() { func init() {
if !teaconst.IsMain {
return
}
events.On(events.EventReload, func() { events.On(events.EventReload, func() {
if nftablesInstance == nil { if nftablesInstance == nil {
return return

View File

@@ -3,6 +3,7 @@
package firewalls package firewalls
import ( import (
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/events" "github.com/TeaOSLab/EdgeNode/internal/events"
"github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/TeaOSLab/EdgeNode/internal/remotelogs"
"runtime" "runtime"
@@ -14,6 +15,10 @@ var firewallLocker = &sync.Mutex{}
// 初始化 // 初始化
func init() { func init() {
if !teaconst.IsMain {
return
}
events.On(events.EventLoaded, func() { events.On(events.EventLoaded, func() {
var firewall = Firewall() var firewall = Firewall()
if firewall.Name() != "mock" { if firewall.Name() != "mock" {

View File

@@ -24,7 +24,7 @@ import (
// check nft status, if being enabled we load it automatically // check nft status, if being enabled we load it automatically
func init() { func init() {
if teaconst.IsDaemon { if !teaconst.IsMain {
return return
} }

View File

@@ -5,6 +5,7 @@ package nftables
import ( import (
"errors" "errors"
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/events" "github.com/TeaOSLab/EdgeNode/internal/events"
"github.com/TeaOSLab/EdgeNode/internal/goman" "github.com/TeaOSLab/EdgeNode/internal/goman"
"github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/TeaOSLab/EdgeNode/internal/remotelogs"
@@ -17,6 +18,10 @@ import (
) )
func init() { func init() {
if !teaconst.IsMain {
return
}
events.On(events.EventReload, func() { events.On(events.EventReload, func() {
// linux only // linux only
if runtime.GOOS != "linux" { if runtime.GOOS != "linux" {

View File

@@ -15,7 +15,7 @@ var instanceId = uint64(0)
// New 新创建goroutine // New 新创建goroutine
func New(f func()) { func New(f func()) {
if teaconst.IsDaemon { if !teaconst.IsMain {
return return
} }
@@ -47,7 +47,7 @@ func New(f func()) {
// NewWithArgs 创建带有参数的goroutine // NewWithArgs 创建带有参数的goroutine
func NewWithArgs(f func(args ...interface{}), args ...interface{}) { func NewWithArgs(f func(args ...interface{}), args ...interface{}) {
if teaconst.IsDaemon { if !teaconst.IsMain {
return return
} }

View File

@@ -20,7 +20,7 @@ var SharedIPListManager = NewIPListManager()
var IPListUpdateNotify = make(chan bool, 1) var IPListUpdateNotify = make(chan bool, 1)
func init() { func init() {
if teaconst.IsDaemon { if !teaconst.IsMain {
return return
} }

View File

@@ -4,6 +4,7 @@ package metrics
import ( import (
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/events" "github.com/TeaOSLab/EdgeNode/internal/events"
"github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/TeaOSLab/EdgeNode/internal/remotelogs"
"strconv" "strconv"
@@ -13,6 +14,10 @@ import (
var SharedManager = NewManager() var SharedManager = NewManager()
func init() { func init() {
if !teaconst.IsMain {
return
}
events.On(events.EventQuit, func() { events.On(events.EventQuit, func() {
SharedManager.Quit() SharedManager.Quit()
}) })

View File

@@ -5,6 +5,7 @@ package monitor
import ( import (
"encoding/json" "encoding/json"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/events" "github.com/TeaOSLab/EdgeNode/internal/events"
"github.com/TeaOSLab/EdgeNode/internal/goman" "github.com/TeaOSLab/EdgeNode/internal/goman"
"github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/TeaOSLab/EdgeNode/internal/remotelogs"
@@ -16,6 +17,10 @@ import (
var SharedValueQueue = NewValueQueue() var SharedValueQueue = NewValueQueue()
func init() { func init() {
if !teaconst.IsMain {
return
}
events.On(events.EventLoaded, func() { events.On(events.EventLoaded, func() {
goman.New(func() { goman.New(func() {
SharedValueQueue.Start() SharedValueQueue.Start()

View File

@@ -15,6 +15,10 @@ import (
// 发送监控流量 // 发送监控流量
func init() { func init() {
if !teaconst.IsMain {
return
}
events.On(events.EventStart, func() { events.On(events.EventStart, func() {
var ticker = time.NewTicker(1 * time.Minute) var ticker = time.NewTicker(1 * time.Minute)
goman.New(func() { goman.New(func() {

View File

@@ -9,6 +9,7 @@ import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeNode/internal/caches" "github.com/TeaOSLab/EdgeNode/internal/caches"
"github.com/TeaOSLab/EdgeNode/internal/compressions" "github.com/TeaOSLab/EdgeNode/internal/compressions"
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/events" "github.com/TeaOSLab/EdgeNode/internal/events"
"github.com/TeaOSLab/EdgeNode/internal/goman" "github.com/TeaOSLab/EdgeNode/internal/goman"
"github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/TeaOSLab/EdgeNode/internal/remotelogs"
@@ -23,6 +24,10 @@ import (
) )
func init() { func init() {
if !teaconst.IsMain {
return
}
events.On(events.EventStart, func() { events.On(events.EventStart, func() {
goman.New(func() { goman.New(func() {
SharedHTTPCacheTaskManager.Start() SharedHTTPCacheTaskManager.Start()

View File

@@ -10,6 +10,7 @@ import (
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/TeaOSLab/EdgeNode/internal/caches" "github.com/TeaOSLab/EdgeNode/internal/caches"
"github.com/TeaOSLab/EdgeNode/internal/compressions" "github.com/TeaOSLab/EdgeNode/internal/compressions"
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/TeaOSLab/EdgeNode/internal/remotelogs"
"github.com/TeaOSLab/EdgeNode/internal/utils" "github.com/TeaOSLab/EdgeNode/internal/utils"
"github.com/TeaOSLab/EdgeNode/internal/utils/readers" "github.com/TeaOSLab/EdgeNode/internal/utils/readers"
@@ -39,6 +40,10 @@ var webpMaxBufferSize int64 = 1_000_000_000
var webpTotalBufferSize int64 = 0 var webpTotalBufferSize int64 = 0
func init() { func init() {
if !teaconst.IsMain {
return
}
var systemMemory = utils.SystemMemoryGB() / 8 var systemMemory = utils.SystemMemoryGB() / 8
if systemMemory > 0 { if systemMemory > 0 {
webpMaxBufferSize = int64(systemMemory) * 1024 * 1024 * 1024 webpMaxBufferSize = int64(systemMemory) * 1024 * 1024 * 1024

View File

@@ -236,8 +236,6 @@ func (this *Node) Start() {
// Daemon 实现守护进程 // Daemon 实现守护进程
func (this *Node) Daemon() { func (this *Node) Daemon() {
teaconst.IsDaemon = true
var isDebug = lists.ContainsString(os.Args, "debug") var isDebug = lists.ContainsString(os.Args, "debug")
for { for {
conn, err := this.sock.Dial() conn, err := this.sock.Dial()

View File

@@ -4,6 +4,7 @@ package nodes
import ( import (
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/events" "github.com/TeaOSLab/EdgeNode/internal/events"
"github.com/TeaOSLab/EdgeNode/internal/goman" "github.com/TeaOSLab/EdgeNode/internal/goman"
"github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/TeaOSLab/EdgeNode/internal/remotelogs"
@@ -16,6 +17,10 @@ import (
var SharedOriginStateManager = NewOriginStateManager() var SharedOriginStateManager = NewOriginStateManager()
func init() { func init() {
if !teaconst.IsMain {
return
}
events.On(events.EventLoaded, func() { events.On(events.EventLoaded, func() {
goman.New(func() { goman.New(func() {
SharedOriginStateManager.Start() SharedOriginStateManager.Start()

View File

@@ -19,6 +19,10 @@ import (
) )
func init() { func init() {
if !teaconst.IsMain {
return
}
var manager = NewSystemServiceManager() var manager = NewSystemServiceManager()
events.On(events.EventReload, func() { events.On(events.EventReload, func() {
goman.New(func() { goman.New(func() {

View File

@@ -4,6 +4,7 @@ package nodes
import ( import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/events" "github.com/TeaOSLab/EdgeNode/internal/events"
"github.com/TeaOSLab/EdgeNode/internal/goman" "github.com/TeaOSLab/EdgeNode/internal/goman"
"github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/TeaOSLab/EdgeNode/internal/remotelogs"
@@ -15,6 +16,10 @@ import (
var sharedOCSPTask = NewOCSPUpdateTask() var sharedOCSPTask = NewOCSPUpdateTask()
func init() { func init() {
if !teaconst.IsMain {
return
}
events.On(events.EventLoaded, func() { events.On(events.EventLoaded, func() {
sharedOCSPTask.version = sharedNodeConfig.OCSPVersion sharedOCSPTask.version = sharedNodeConfig.OCSPVersion

View File

@@ -3,6 +3,7 @@ package nodes
import ( import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeNode/internal/configs" "github.com/TeaOSLab/EdgeNode/internal/configs"
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/events" "github.com/TeaOSLab/EdgeNode/internal/events"
"github.com/TeaOSLab/EdgeNode/internal/goman" "github.com/TeaOSLab/EdgeNode/internal/goman"
"github.com/TeaOSLab/EdgeNode/internal/rpc" "github.com/TeaOSLab/EdgeNode/internal/rpc"
@@ -16,6 +17,10 @@ import (
var sharedSyncAPINodesTask = NewSyncAPINodesTask() var sharedSyncAPINodesTask = NewSyncAPINodesTask()
func init() { func init() {
if !teaconst.IsMain {
return
}
events.On(events.EventStart, func() { events.On(events.EventStart, func() {
goman.New(func() { goman.New(func() {
sharedSyncAPINodesTask.Start() sharedSyncAPINodesTask.Start()

View File

@@ -3,6 +3,7 @@ package nodes
import ( import (
"errors" "errors"
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/events" "github.com/TeaOSLab/EdgeNode/internal/events"
"github.com/TeaOSLab/EdgeNode/internal/goman" "github.com/TeaOSLab/EdgeNode/internal/goman"
"github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/TeaOSLab/EdgeNode/internal/remotelogs"
@@ -17,6 +18,10 @@ import (
var sharedTOAManager = NewTOAManager() var sharedTOAManager = NewTOAManager()
func init() { func init() {
if !teaconst.IsMain {
return
}
events.On(events.EventReload, func() { events.On(events.EventReload, func() {
err := sharedTOAManager.Run(sharedNodeConfig.TOA) err := sharedTOAManager.Run(sharedNodeConfig.TOA)
if err != nil { if err != nil {

View File

@@ -20,6 +20,10 @@ import (
var logChan = make(chan *pb.NodeLog, 64) // 队列数量不需要太长,因为日志通常仅仅为调试用 var logChan = make(chan *pb.NodeLog, 64) // 队列数量不需要太长,因为日志通常仅仅为调试用
func init() { func init() {
if !teaconst.IsMain {
return
}
// 定期上传日志 // 定期上传日志
var ticker = time.NewTicker(60 * time.Second) var ticker = time.NewTicker(60 * time.Second)
if Tea.IsTesting() { if Tea.IsTesting() {

View File

@@ -5,6 +5,7 @@ package stats
import ( import (
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/events" "github.com/TeaOSLab/EdgeNode/internal/events"
"github.com/TeaOSLab/EdgeNode/internal/goman" "github.com/TeaOSLab/EdgeNode/internal/goman"
"github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/TeaOSLab/EdgeNode/internal/remotelogs"
@@ -21,6 +22,10 @@ var SharedBandwidthStatManager = NewBandwidthStatManager()
const bandwidthTimestampDelim = 2 // N秒平均更为精确 const bandwidthTimestampDelim = 2 // N秒平均更为精确
func init() { func init() {
if !teaconst.IsMain {
return
}
events.On(events.EventLoaded, func() { events.On(events.EventLoaded, func() {
goman.New(func() { goman.New(func() {
SharedBandwidthStatManager.Start() SharedBandwidthStatManager.Start()

View File

@@ -4,6 +4,7 @@ package agents
import ( import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/events" "github.com/TeaOSLab/EdgeNode/internal/events"
"github.com/TeaOSLab/EdgeNode/internal/goman" "github.com/TeaOSLab/EdgeNode/internal/goman"
"github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/TeaOSLab/EdgeNode/internal/remotelogs"
@@ -16,6 +17,10 @@ import (
var SharedManager = NewManager() var SharedManager = NewManager()
func init() { func init() {
if !teaconst.IsMain {
return
}
events.On(events.EventLoaded, func() { events.On(events.EventLoaded, func() {
goman.New(func() { goman.New(func() {
SharedManager.Start() SharedManager.Start()

View File

@@ -4,6 +4,7 @@ package agents
import ( import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/events" "github.com/TeaOSLab/EdgeNode/internal/events"
"github.com/TeaOSLab/EdgeNode/internal/goman" "github.com/TeaOSLab/EdgeNode/internal/goman"
"github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/TeaOSLab/EdgeNode/internal/remotelogs"
@@ -13,6 +14,10 @@ import (
) )
func init() { func init() {
if !teaconst.IsMain {
return
}
events.On(events.EventLoaded, func() { events.On(events.EventLoaded, func() {
goman.New(func() { goman.New(func() {
SharedQueue.Start() SharedQueue.Start()

View File

@@ -6,6 +6,7 @@ import (
"encoding/binary" "encoding/binary"
"errors" "errors"
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/events" "github.com/TeaOSLab/EdgeNode/internal/events"
"github.com/TeaOSLab/EdgeNode/internal/goman" "github.com/TeaOSLab/EdgeNode/internal/goman"
"github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/TeaOSLab/EdgeNode/internal/remotelogs"
@@ -21,6 +22,10 @@ var hasSynced = false
var sharedClockManager = NewClockManager() var sharedClockManager = NewClockManager()
func init() { func init() {
if !teaconst.IsMain {
return
}
events.On(events.EventLoaded, func() { events.On(events.EventLoaded, func() {
goman.New(sharedClockManager.Start) goman.New(sharedClockManager.Start)
}) })

View File

@@ -15,6 +15,10 @@ import (
) )
func init() { func init() {
if !teaconst.IsMain {
return
}
var ticker = time.NewTicker(5 * time.Second) var ticker = time.NewTicker(5 * time.Second)
events.On(events.EventLoaded, func() { events.On(events.EventLoaded, func() {

View File

@@ -10,6 +10,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/events" "github.com/TeaOSLab/EdgeNode/internal/events"
"github.com/iwind/TeaGo/logs" "github.com/iwind/TeaGo/logs"
"github.com/iwind/TeaGo/maps" "github.com/iwind/TeaGo/maps"
@@ -22,6 +23,10 @@ var (
) )
func init() { func init() {
if !teaconst.IsMain {
return
}
events.On(events.EventReload, func() { events.On(events.EventReload, func() {
nodeConfig, _ := nodeconfigs.SharedNodeConfig() nodeConfig, _ := nodeconfigs.SharedNodeConfig()
if nodeConfig != nil { if nodeConfig != nil {

View File

@@ -15,6 +15,10 @@ import (
var SharedFreeHoursManager = NewFreeHoursManager() var SharedFreeHoursManager = NewFreeHoursManager()
func init() { func init() {
if !teaconst.IsMain {
return
}
events.On(events.EventLoaded, func() { events.On(events.EventLoaded, func() {
goman.New(func() { goman.New(func() {
SharedFreeHoursManager.Start() SharedFreeHoursManager.Start()

View File

@@ -3,12 +3,17 @@
package utils package utils
import ( import (
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/shirou/gopsutil/v3/mem" "github.com/shirou/gopsutil/v3/mem"
) )
var systemTotalMemory = -1 var systemTotalMemory = -1
func init() { func init() {
if !teaconst.IsMain {
return
}
_ = SystemMemoryGB() _ = SystemMemoryGB()
} }

View File

@@ -1,6 +1,7 @@
package utils package utils
import ( import (
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/goman" "github.com/TeaOSLab/EdgeNode/internal/goman"
"github.com/iwind/TeaGo/types" "github.com/iwind/TeaGo/types"
"time" "time"
@@ -11,6 +12,10 @@ var unixTimeMilli = time.Now().UnixMilli()
var unixTimeMilliString = types.String(unixTimeMilli) var unixTimeMilliString = types.String(unixTimeMilli)
func init() { func init() {
if !teaconst.IsMain {
return
}
var ticker = time.NewTicker(200 * time.Millisecond) var ticker = time.NewTicker(200 * time.Millisecond)
goman.New(func() { goman.New(func() {
for range ticker.C { for range ticker.C {

View File

@@ -4,6 +4,7 @@ package waf
import ( import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/events" "github.com/TeaOSLab/EdgeNode/internal/events"
"github.com/TeaOSLab/EdgeNode/internal/goman" "github.com/TeaOSLab/EdgeNode/internal/goman"
"github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/TeaOSLab/EdgeNode/internal/remotelogs"
@@ -25,6 +26,10 @@ type notifyTask struct {
var notifyChan = make(chan *notifyTask, 128) var notifyChan = make(chan *notifyTask, 128)
func init() { func init() {
if !teaconst.IsMain {
return
}
events.On(events.EventLoaded, func() { events.On(events.EventLoaded, func() {
goman.New(func() { goman.New(func() {
rpcClient, err := rpc.SharedRPC() rpcClient, err := rpc.SharedRPC()

View File

@@ -33,6 +33,10 @@ type recordIPTask struct {
var recordIPTaskChan = make(chan *recordIPTask, 1024) var recordIPTaskChan = make(chan *recordIPTask, 1024)
func init() { func init() {
if !teaconst.IsMain {
return
}
events.On(events.EventLoaded, func() { events.On(events.EventLoaded, func() {
goman.New(func() { goman.New(func() {
rpcClient, err := rpc.SharedRPC() rpcClient, err := rpc.SharedRPC()