fix output and config reload

This commit is contained in:
yusing 2024-03-14 02:46:01 +00:00
parent e14eeb914f
commit eee6ff4f15
6 changed files with 17 additions and 14 deletions

Binary file not shown.

View file

@ -64,6 +64,7 @@ func ListenConfigChanges() {
if err != nil {
glog.Fatalf("[Config] unable to read config: %v", err)
}
StartAllRoutes()
case event.Has(fsnotify.Remove), event.Has(fsnotify.Rename):
glog.Fatalf("[Config] file renamed / deleted")
}

View file

@ -195,7 +195,7 @@ func (p *Provider) grWatchDockerChanges() {
// TODO: handle actor only
p.Logf("Event", "container %s %s caused rebuild", msg.Actor.Attributes["name"], msg.Action)
p.StopAllRoutes()
p.BuildStartRoutes()
p.StartAllRoutes()
case err := <-errChan:
p.Logf("Event", "error %s", err)
time.Sleep(100 * time.Millisecond)

View file

@ -64,7 +64,7 @@ func (p *Provider) grWatchFileChanges() {
case event.Has(fsnotify.Write):
p.Logf("Watcher", "file change detected")
p.StopAllRoutes()
p.BuildStartRoutes()
p.StartAllRoutes()
case event.Has(fsnotify.Remove), event.Has(fsnotify.Rename):
p.Logf("Watcher", "file renamed / deleted")
p.StopAllRoutes()

View file

@ -4,7 +4,6 @@ import (
"flag"
"net/http"
"runtime"
"sync"
"time"
"github.com/golang/glog"
@ -12,7 +11,6 @@ import (
func main() {
var err error
var wg sync.WaitGroup
flag.Parse()
runtime.GOMAXPROCS(runtime.NumCPU())
@ -27,15 +25,7 @@ func main() {
glog.Fatal("unable to read config: ", err)
}
wg.Add(len(config.Providers))
for _, p := range config.Providers {
go func(p *Provider) {
p.BuildStartRoutes()
wg.Done()
}(p)
}
wg.Wait()
StartAllRoutes()
go ListenConfigChanges()
mux := http.NewServeMux()

View file

@ -31,6 +31,18 @@ func (p *Provider) GetProxyConfigs() ([]*ProxyConfig, error) {
}
}
func StartAllRoutes() {
var wg sync.WaitGroup
wg.Add(len(config.Providers))
for _, p := range config.Providers {
go func(p *Provider) {
p.StartAllRoutes()
wg.Done()
}(p)
}
wg.Wait()
}
func (p *Provider) StopAllRoutes() {
p.mutex.Lock()
defer p.mutex.Unlock()
@ -59,7 +71,7 @@ func (p *Provider) StopAllRoutes() {
p.routes = make(map[string]Route)
}
func (p *Provider) BuildStartRoutes() {
func (p *Provider) StartAllRoutes() {
p.mutex.Lock()
defer p.mutex.Unlock()