Merge pull request #2653 from aledbf/remove-watch
Remove dummy file watcher
This commit is contained in:
commit
373f8f5f73
2 changed files with 27 additions and 59 deletions
|
@ -163,44 +163,42 @@ Error loading new template: %v
|
|||
|
||||
n.t = ngxTpl
|
||||
|
||||
// TODO: refactor
|
||||
if _, ok := fs.(filesystem.DefaultFs); !ok {
|
||||
watch.NewDummyFileWatcher(tmplPath, onTemplateChange)
|
||||
} else {
|
||||
// do not setup watchers on tests
|
||||
return n
|
||||
}
|
||||
|
||||
_, err = watch.NewFileWatcher(tmplPath, onTemplateChange)
|
||||
_, err = watch.NewFileWatcher(tmplPath, onTemplateChange)
|
||||
if err != nil {
|
||||
glog.Fatalf("Error creating file watcher for %v: %v", tmplPath, err)
|
||||
}
|
||||
|
||||
filesToWatch := []string{}
|
||||
err = filepath.Walk("/etc/nginx/geoip/", func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
glog.Fatalf("Error creating file watcher for %v: %v", tmplPath, err)
|
||||
return err
|
||||
}
|
||||
|
||||
filesToWatch := []string{}
|
||||
err := filepath.Walk("/etc/nginx/geoip/", func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
||||
filesToWatch = append(filesToWatch, path)
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
||||
filesToWatch = append(filesToWatch, path)
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
glog.Fatalf("Error creating file watchers: %v", err)
|
||||
}
|
||||
|
||||
for _, f := range filesToWatch {
|
||||
_, err = watch.NewFileWatcher(f, func() {
|
||||
glog.Info("File %v changed. Reloading NGINX", f)
|
||||
n.SetForceReload(true)
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
glog.Fatalf("Error creating file watchers: %v", err)
|
||||
glog.Fatalf("Error creating file watcher for %v: %v", f, err)
|
||||
}
|
||||
|
||||
for _, f := range filesToWatch {
|
||||
_, err = watch.NewFileWatcher(f, func() {
|
||||
glog.Info("File %v changed. Reloading NGINX", f)
|
||||
n.SetForceReload(true)
|
||||
})
|
||||
if err != nil {
|
||||
glog.Fatalf("Error creating file watcher for %v: %v", f, err)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return n
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package watch
|
||||
|
||||
// DummyFileWatcher noop implementation of a file watcher
|
||||
type DummyFileWatcher struct{}
|
||||
|
||||
// NewDummyFileWatcher creates a FileWatcher using the DummyFileWatcher
|
||||
func NewDummyFileWatcher(file string, onEvent func()) FileWatcher {
|
||||
return DummyFileWatcher{}
|
||||
}
|
||||
|
||||
// Close ends the watch
|
||||
func (f DummyFileWatcher) Close() error {
|
||||
return nil
|
||||
}
|
Loading…
Reference in a new issue