Compare commits

...

3 Commits

Author SHA1 Message Date
Egor Zavialov
bfab436295
Merge 95681518606083c638840a31835c36d9efa289d2 into c6f9d8d4031f6fba9a39fe9e1a79907ceedf0f5f 2024-06-26 14:56:06 +08:00
fatedier
c6f9d8d403
update sponsors (#4303) 2024-06-26 14:51:34 +08:00
Egor Zavialov
9568151860 feat: add client reload on config change 2024-06-01 16:28:15 +09:00
11 changed files with 87 additions and 0 deletions

View File

@ -9,6 +9,11 @@
<h3 align="center">Gold Sponsors</h3>
<!--gold sponsors start-->
<p align="center">
<a href="https://lokal.so/?utm_campaign=github_repo&utm_medium=referral&utm_content=frp&utm_source=github" target="_blank">
<img width="420px" src="https://raw.githubusercontent.com/fatedier/frp/dev/doc/pic/sponsor_lokal.png">
</a>
</p>
<p align="center">
<a href="https://workos.com/?utm_campaign=github_repo&utm_medium=referral&utm_content=frp&utm_source=github" target="_blank">
<img width="420px" src="https://raw.githubusercontent.com/fatedier/frp/dev/doc/pic/sponsor_workos.png">

View File

@ -11,6 +11,11 @@ frp 是一个专注于内网穿透的高性能的反向代理应用,支持 TCP
<h3 align="center">Gold Sponsors</h3>
<!--gold sponsors start-->
<p align="center">
<a href="https://lokal.so/?utm_campaign=github_repo&utm_medium=referral&utm_content=frp&utm_source=github" target="_blank">
<img width="420px" src="https://raw.githubusercontent.com/fatedier/frp/dev/doc/pic/sponsor_lokal.png">
</a>
</p>
<p align="center">
<a href="https://workos.com/?utm_campaign=github_repo&utm_medium=referral&utm_content=frp&utm_source=github" target="_blank">
<img width="420px" src="https://raw.githubusercontent.com/fatedier/frp/dev/doc/pic/sponsor_workos.png">

View File

@ -30,6 +30,9 @@ import (
"github.com/fatedier/frp/client/proxy"
"github.com/fatedier/frp/pkg/auth"
v1 "github.com/fatedier/frp/pkg/config/v1"
"github.com/fatedier/frp/pkg/config/v1/validation"
"github.com/radovskyb/watcher"
"github.com/fatedier/frp/pkg/config"
"github.com/fatedier/frp/pkg/msg"
httppkg "github.com/fatedier/frp/pkg/util/http"
"github.com/fatedier/frp/pkg/util/log"
@ -156,6 +159,11 @@ func NewService(options ServiceOptions) (*Service, error) {
if webServer != nil {
webServer.RouteRegister(s.registerRouteHandlers)
}
if options.Common.ConfigAutoReload {
go s.MonitorClientConfig(options.ConfigFilePath)
}
return s, nil
}
@ -408,3 +416,63 @@ type statusExporterImpl struct {
func (s *statusExporterImpl) GetProxyStatus(name string) (*proxy.WorkingStatus, bool) {
return s.getProxyStatusFunc(name)
}
func (s *Service) MonitorClientConfig(cfgFilePath string) {
cliCfg, _, _, _, err := config.LoadClientConfig(cfgFilePath, false)
if err != nil {
log.Errorf("%v", err)
}
if !cliCfg.ConfigAutoReload {
log.Infof("auto reload on config change is disabled.")
return
}
w := watcher.New()
w.SetMaxEvents(1)
w.FilterOps(watcher.Write)
done := make(chan bool)
go func() {
for {
select {
case event := <-w.Event:
log.Infof("config file changed: %s", event.Path)
cliCfg, pxyCfgs, visitorCfgs, _, err := config.LoadClientConfig(cfgFilePath, false)
if err != nil {
log.Infof("reload frpc proxy config error: %s", err.Error())
continue
}
if _, err := validation.ValidateAllClientConfig(cliCfg, pxyCfgs, visitorCfgs); err != nil {
log.Infof("reload frpc proxy config error: %s", err.Error())
continue
}
if err := s.UpdateAllConfigurer(pxyCfgs, visitorCfgs); err != nil {
log.Infof("reload frpc proxy config error: %s", err.Error())
continue
}
log.Infof("success reload conf")
case err := <-w.Error:
log.Infof("error: %s", err.Error())
case <-w.Closed:
done <- true
return
}
}
}()
if err := w.Add(cfgFilePath); err != nil {
log.Infof("error adding file to watcher: %s", err.Error())
}
go func() {
if err := w.Start(time.Second); err != nil {
log.Infof("error starting watcher: %s", err.Error())
}
}()
<-done
}

View File

@ -12,6 +12,9 @@ serverPort = 7000
# STUN server to help penetrate NAT hole.
# natHoleStunServer = "stun.easyvoip.com:3478"
# if true, autoreload is enabled
configAutoReload = true
# Decide if exit program when first login failed, otherwise continuous relogin to frps
# default is true
loginFailExit = true

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

BIN
doc/pic/sponsor_lokal.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

1
go.mod
View File

@ -59,6 +59,7 @@ require (
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/radovskyb/watcher v1.0.7 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/templexxx/cpu v0.1.0 // indirect
github.com/templexxx/xorsimd v0.4.2 // indirect

2
go.sum
View File

@ -112,6 +112,8 @@ github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
github.com/quic-go/quic-go v0.42.0 h1:uSfdap0eveIl8KXnipv9K7nlwZ5IqLlYOpJ58u5utpM=
github.com/quic-go/quic-go v0.42.0/go.mod h1:132kz4kL3F9vxhW3CtQJLDVwcFe5wdWeJXXijhsO57M=
github.com/radovskyb/watcher v1.0.7 h1:AYePLih6dpmS32vlHfhCeli8127LzkIgwJGcwwe8tUE=
github.com/radovskyb/watcher v1.0.7/go.mod h1:78okwvY5wPdzcb1UYnip1pvrZNIVEIh/Cm+ZuvsUYIg=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rodaine/table v1.2.0 h1:38HEnwK4mKSHQJIkavVj+bst1TEY7j9zhLMWu4QJrMA=

View File

@ -46,6 +46,9 @@ type ClientCommonConfig struct {
ServerPort int `json:"serverPort,omitempty"`
// STUN server to help penetrate NAT hole.
NatHoleSTUNServer string `json:"natHoleStunServer,omitempty"`
//
ConfigAutoReload bool `json:"configAutoReload,omitempty"`
// DNSServer specifies a DNS server address for FRPC to use. If this value
// is "", the default DNS will be used.
DNSServer string `json:"dnsServer,omitempty"`