From e7949fd615fc4389164251af79519f730a2a28fb Mon Sep 17 00:00:00 2001 From: nbari Date: Mon, 10 Apr 2017 22:25:01 +0200 Subject: [PATCH] modified: scandir.go --- scandir.go | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/scandir.go b/scandir.go index 289a299..a17403e 100644 --- a/scandir.go +++ b/scandir.go @@ -58,12 +58,8 @@ func NewScanDir(path string) (*ScanDir, error) { // Start check for changes on directory func (s *ScanDir) Start(ctl Control) { - var activeServices = make(map[string]string) - log.Printf("immortal scandir: %s", s.scandir) - s.watchDir <- struct{}{} - for { select { case <-s.watchDir: @@ -71,13 +67,6 @@ func (s *ScanDir) Start(ctl Control) { if err := s.Scandir(s.scandir); err != nil && !os.IsPermission(err) { log.Fatal(err) } - for service := range s.services { - if _, ok := activeServices[service]; !ok { - activeServices[service] = filepath.Join(s.scandir, fmt.Sprintf("%s.yml", service)) - log.Printf("Starting service: %s socket: %s\n", service, filepath.Join(s.sdir, service, "immortal.sock")) - go WatchFile(activeServices[service], s.watchFile) - } - } go WatchDir(s.scandir, s.watchDir) case file := <-s.watchFile: serviceFile := filepath.Base(file) @@ -93,14 +82,12 @@ func (s *ScanDir) Start(ctl Control) { log.Printf("Restarting (halt): %s socket: %s\n", serviceName, filepath.Join(s.sdir, serviceName, "immortal.sock")) } log.Printf("Starting: %s socket: %s\n", serviceName, filepath.Join(s.sdir, serviceName, "immortal.sock")) - fmt.Printf("%s = %s\n", file, md5) go WatchFile(file, s.watchFile) } else { // remove service log.Printf("Exiting: %s socket: %s\n", serviceName, filepath.Join(s.sdir, serviceName, "immortal.sock")) delete(s.services, serviceName) - delete(activeServices, serviceName) } } time.Sleep(100 * time.Millisecond) @@ -122,6 +109,8 @@ func (s *ScanDir) Scandir(dir string) error { } if _, ok := s.services[name]; !ok { s.services[name] = md5 + log.Printf("Starting service: %s socket: %s\n", name, filepath.Join(s.sdir, name, "immortal.sock")) + go WatchFile(path, s.watchFile) } } }