Skip to content

Commit

Permalink
watch on start either service start or not
Browse files Browse the repository at this point in the history
  • Loading branch information
nbari committed Apr 18, 2017
1 parent 9604595 commit 3851cf1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions kqueue.go
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 4 additions & 1 deletion openmode.go
Expand Up @@ -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
)
5 changes: 4 additions & 1 deletion openmode_darwin.go
Expand Up @@ -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
)
4 changes: 1 addition & 3 deletions scandir.go
Expand Up @@ -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)
}
}
Expand All @@ -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)
Expand Down

0 comments on commit 3851cf1

Please sign in to comment.