From 3851cf15117f12155bc2794136d6f3fd31943eac Mon Sep 17 00:00:00 2001 From: nbari Date: Tue, 18 Apr 2017 22:40:49 +0200 Subject: [PATCH] watch on start either service start or not --- kqueue.go | 4 ++-- openmode.go | 5 ++++- openmode_darwin.go | 5 ++++- scandir.go | 4 +--- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/kqueue.go b/kqueue.go index 7ead0d6..2dcc1c3 100644 --- a/kqueue.go +++ b/kqueue.go @@ -10,7 +10,7 @@ import ( // WatchDir check for changes on a directory via Kqueue EVFILT_VNODE func WatchDir(dir string, ch chan<- struct{}) error { - watchfd, err := syscall.Open(dir, openMode, 0700) + watchfd, err := syscall.Open(dir, openModeDir, 0700) if err != nil { return err } @@ -56,7 +56,7 @@ func WatchDir(dir string, ch chan<- struct{}) error { // WatchFile check for changes on a file via kqueue EVFILT_VNODE func WatchFile(f string, ch chan<- string) error { - watchfd, err := syscall.Open(f, openMode, 0700) + watchfd, err := syscall.Open(f, openModeFile, 0700) if err != nil { return err } diff --git a/openmode.go b/openmode.go index 659a4b8..8bc30eb 100644 --- a/openmode.go +++ b/openmode.go @@ -4,4 +4,7 @@ package immortal import "syscall" -const openMode = syscall.O_NONBLOCK | syscall.O_RDONLY +const ( + openModeDir = syscall.O_NONBLOCK | syscall.O_RDONLY | syscall.O_DIRECTORY + openModeFile = syscall.O_NONBLOCK | syscall.O_RDONLY +) diff --git a/openmode_darwin.go b/openmode_darwin.go index 06ce209..60a06ee 100644 --- a/openmode_darwin.go +++ b/openmode_darwin.go @@ -4,4 +4,7 @@ package immortal import "syscall" -const openMode = syscall.O_EVTONLY +const ( + openModeDir = syscall.O_EVTONLY | syscall.O_DIRECTORY + openModeFile = syscall.O_EVTONLY +) diff --git a/scandir.go b/scandir.go index fc9954f..f32dc06 100644 --- a/scandir.go +++ b/scandir.go @@ -105,7 +105,7 @@ func (s *ScanDir) Start(ctl Control) { log.Printf("Exiting: %s\n", serviceName) } } - // Block for 100 ms on each call to kevent + // Block for 100 ms on each call to kevent (WatchFile) time.Sleep(100 * time.Millisecond) } } @@ -129,8 +129,6 @@ func (s *ScanDir) Scandir(ctl Control) error { s.services[name] = md5 log.Printf("Starting: %s\n", name) if out, err := ctl.Run(fmt.Sprintf("immortal -c %s -ctl %s", path, name)); err != nil { - // keep retrying - delete(s.services, name) log.Println(err) } else { log.Printf("%s\n", out)