mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-10-26 21:22:16 +08:00
feat: config
This commit is contained in:
parent
fa79fac6d5
commit
8acd21e180
@ -158,6 +158,12 @@ func compareAndSave[T any](c *gin.Context, old any, req *apistruct.SetConfigReq,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cm *ConfigManager) ResetConfig(c *gin.Context) {
|
func (cm *ConfigManager) ResetConfig(c *gin.Context) {
|
||||||
|
go cm.restart(c)
|
||||||
|
apiresp.GinSuccess(c, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cm *ConfigManager) restart(c *gin.Context) {
|
||||||
|
<-etcd.CanRestart
|
||||||
type initConf struct {
|
type initConf struct {
|
||||||
old any
|
old any
|
||||||
new any
|
new any
|
||||||
@ -214,5 +220,5 @@ func (cm *ConfigManager) ResetConfig(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
apiresp.GinSuccess(c, nil)
|
etcd.CanRestart <- struct{}{}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/openimsdk/tools/errs"
|
"github.com/openimsdk/tools/errs"
|
||||||
@ -20,8 +19,14 @@ const (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
ShutDowns []func() error
|
ShutDowns []func() error
|
||||||
|
CanRestart chan struct{}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
CanRestart = make(chan struct{}, 1)
|
||||||
|
CanRestart <- struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
func RegisterShutDown(shutDown ...func() error) {
|
func RegisterShutDown(shutDown ...func() error) {
|
||||||
ShutDowns = append(ShutDowns, shutDown...)
|
ShutDowns = append(ShutDowns, shutDown...)
|
||||||
}
|
}
|
||||||
@ -29,7 +34,6 @@ func RegisterShutDown(shutDown ...func() error) {
|
|||||||
type ConfigManager struct {
|
type ConfigManager struct {
|
||||||
client *clientv3.Client
|
client *clientv3.Client
|
||||||
watchConfigNames []string
|
watchConfigNames []string
|
||||||
lock sync.RWMutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BuildKey(s string) string {
|
func BuildKey(s string) string {
|
||||||
@ -57,12 +61,12 @@ func (c *ConfigManager) Watch(ctx context.Context) {
|
|||||||
for _, event := range watchResp.Events {
|
for _, event := range watchResp.Events {
|
||||||
if event.IsModify() {
|
if event.IsModify() {
|
||||||
if datautil.Contain(string(event.Kv.Key), c.watchConfigNames...) {
|
if datautil.Contain(string(event.Kv.Key), c.watchConfigNames...) {
|
||||||
c.lock.Lock()
|
<-CanRestart
|
||||||
err := restartServer(ctx)
|
err := restartServer(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZError(ctx, "restart server err", err)
|
log.ZError(ctx, "restart server err", err)
|
||||||
|
CanRestart <- struct{}{}
|
||||||
}
|
}
|
||||||
c.lock.Unlock()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user