mirror of
https://github.com/fatedier/frp.git
synced 2025-06-17 09:08:21 +00:00
Compare commits
2 Commits
7e6f36f2d6
...
b3f1ac0e21
Author | SHA1 | Date | |
---|---|---|---|
|
b3f1ac0e21 | ||
|
9568151860 |
@ -30,6 +30,9 @@ import (
|
|||||||
"github.com/fatedier/frp/client/proxy"
|
"github.com/fatedier/frp/client/proxy"
|
||||||
"github.com/fatedier/frp/pkg/auth"
|
"github.com/fatedier/frp/pkg/auth"
|
||||||
v1 "github.com/fatedier/frp/pkg/config/v1"
|
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"
|
"github.com/fatedier/frp/pkg/msg"
|
||||||
httppkg "github.com/fatedier/frp/pkg/util/http"
|
httppkg "github.com/fatedier/frp/pkg/util/http"
|
||||||
"github.com/fatedier/frp/pkg/util/log"
|
"github.com/fatedier/frp/pkg/util/log"
|
||||||
@ -156,6 +159,11 @@ func NewService(options ServiceOptions) (*Service, error) {
|
|||||||
if webServer != nil {
|
if webServer != nil {
|
||||||
webServer.RouteRegister(s.registerRouteHandlers)
|
webServer.RouteRegister(s.registerRouteHandlers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if options.Common.ConfigAutoReload {
|
||||||
|
go s.MonitorClientConfig(options.ConfigFilePath)
|
||||||
|
}
|
||||||
|
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,3 +416,63 @@ type statusExporterImpl struct {
|
|||||||
func (s *statusExporterImpl) GetProxyStatus(name string) (*proxy.WorkingStatus, bool) {
|
func (s *statusExporterImpl) GetProxyStatus(name string) (*proxy.WorkingStatus, bool) {
|
||||||
return s.getProxyStatusFunc(name)
|
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
|
||||||
|
}
|
@ -12,6 +12,9 @@ serverPort = 7000
|
|||||||
# STUN server to help penetrate NAT hole.
|
# STUN server to help penetrate NAT hole.
|
||||||
# natHoleStunServer = "stun.easyvoip.com:3478"
|
# 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
|
# Decide if exit program when first login failed, otherwise continuous relogin to frps
|
||||||
# default is true
|
# default is true
|
||||||
loginFailExit = true
|
loginFailExit = true
|
||||||
|
1
go.mod
1
go.mod
@ -59,6 +59,7 @@ require (
|
|||||||
github.com/prometheus/client_model v0.5.0 // indirect
|
github.com/prometheus/client_model v0.5.0 // indirect
|
||||||
github.com/prometheus/common v0.48.0 // indirect
|
github.com/prometheus/common v0.48.0 // indirect
|
||||||
github.com/prometheus/procfs v0.12.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/rogpeppe/go-internal v1.11.0 // indirect
|
||||||
github.com/templexxx/cpu v0.1.0 // indirect
|
github.com/templexxx/cpu v0.1.0 // indirect
|
||||||
github.com/templexxx/xorsimd v0.4.2 // indirect
|
github.com/templexxx/xorsimd v0.4.2 // indirect
|
||||||
|
2
go.sum
2
go.sum
@ -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/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 h1:uSfdap0eveIl8KXnipv9K7nlwZ5IqLlYOpJ58u5utpM=
|
||||||
github.com/quic-go/quic-go v0.42.0/go.mod h1:132kz4kL3F9vxhW3CtQJLDVwcFe5wdWeJXXijhsO57M=
|
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 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||||
github.com/rodaine/table v1.2.0 h1:38HEnwK4mKSHQJIkavVj+bst1TEY7j9zhLMWu4QJrMA=
|
github.com/rodaine/table v1.2.0 h1:38HEnwK4mKSHQJIkavVj+bst1TEY7j9zhLMWu4QJrMA=
|
||||||
|
@ -46,6 +46,9 @@ type ClientCommonConfig struct {
|
|||||||
ServerPort int `json:"serverPort,omitempty"`
|
ServerPort int `json:"serverPort,omitempty"`
|
||||||
// STUN server to help penetrate NAT hole.
|
// STUN server to help penetrate NAT hole.
|
||||||
NatHoleSTUNServer string `json:"natHoleStunServer,omitempty"`
|
NatHoleSTUNServer string `json:"natHoleStunServer,omitempty"`
|
||||||
|
|
||||||
|
//
|
||||||
|
ConfigAutoReload bool `json:"configAutoReload,omitempty"`
|
||||||
// DNSServer specifies a DNS server address for FRPC to use. If this value
|
// DNSServer specifies a DNS server address for FRPC to use. If this value
|
||||||
// is "", the default DNS will be used.
|
// is "", the default DNS will be used.
|
||||||
DNSServer string `json:"dnsServer,omitempty"`
|
DNSServer string `json:"dnsServer,omitempty"`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user