mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-04-12 23:27:30 +08:00
ci cross-platform fix: make gateway reload/signal handling windows-safe with build-tagged helpers
This commit is contained in:
@@ -11,7 +11,6 @@ import (
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"clawgo/pkg/agent"
|
||||
@@ -203,7 +202,7 @@ func gatewayCmd() {
|
||||
return out
|
||||
})
|
||||
registryServer.SetConfigAfterHook(func() {
|
||||
_ = syscall.Kill(os.Getpid(), syscall.SIGHUP)
|
||||
_ = requestGatewayReloadSignal()
|
||||
})
|
||||
registryServer.SetCronHandler(func(action string, args map[string]interface{}) (interface{}, error) {
|
||||
getStr := func(k string) string {
|
||||
@@ -353,11 +352,11 @@ func gatewayCmd() {
|
||||
go runGatewayBootstrapInit(ctx, cfg, agentLoop)
|
||||
|
||||
sigChan := make(chan os.Signal, 1)
|
||||
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP)
|
||||
signal.Notify(sigChan, gatewayNotifySignals()...)
|
||||
for {
|
||||
sig := <-sigChan
|
||||
switch sig {
|
||||
case syscall.SIGHUP:
|
||||
switch {
|
||||
case isGatewayReloadSignal(sig):
|
||||
fmt.Println("\n↻ Reloading config...")
|
||||
newCfg, err := config.LoadConfig(getConfigPath())
|
||||
if err != nil {
|
||||
|
||||
12
cmd/clawgo/reload_unix.go
Normal file
12
cmd/clawgo/reload_unix.go
Normal file
@@ -0,0 +1,12 @@
|
||||
//go:build !windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func requestGatewayReloadSignal() error {
|
||||
return syscall.Kill(os.Getpid(), syscall.SIGHUP)
|
||||
}
|
||||
7
cmd/clawgo/reload_windows.go
Normal file
7
cmd/clawgo/reload_windows.go
Normal file
@@ -0,0 +1,7 @@
|
||||
//go:build windows
|
||||
|
||||
package main
|
||||
|
||||
func requestGatewayReloadSignal() error {
|
||||
return nil
|
||||
}
|
||||
16
cmd/clawgo/signals_unix.go
Normal file
16
cmd/clawgo/signals_unix.go
Normal file
@@ -0,0 +1,16 @@
|
||||
//go:build !windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func gatewayNotifySignals() []os.Signal {
|
||||
return []os.Signal{os.Interrupt, syscall.SIGTERM, syscall.SIGHUP}
|
||||
}
|
||||
|
||||
func isGatewayReloadSignal(sig os.Signal) bool {
|
||||
return sig == syscall.SIGHUP
|
||||
}
|
||||
13
cmd/clawgo/signals_windows.go
Normal file
13
cmd/clawgo/signals_windows.go
Normal file
@@ -0,0 +1,13 @@
|
||||
//go:build windows
|
||||
|
||||
package main
|
||||
|
||||
import "os"
|
||||
|
||||
func gatewayNotifySignals() []os.Signal {
|
||||
return []os.Signal{os.Interrupt}
|
||||
}
|
||||
|
||||
func isGatewayReloadSignal(sig os.Signal) bool {
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user