diff --git a/pkg/supervisor/supervisor.go b/pkg/supervisor/supervisor.go index bc8eb81..2de361e 100644 --- a/pkg/supervisor/supervisor.go +++ b/pkg/supervisor/supervisor.go @@ -18,6 +18,7 @@ type Supervisor struct { cmd *exec.Cmd sigCh chan os.Signal startStopLock sync.Mutex + shutdown bool shutdownTimer *time.Timer } @@ -32,6 +33,7 @@ func New(name string, args ...string) *Supervisor { cmd.Env = os.Environ() return &Supervisor{ cmd: cmd, + shutdown: false, } } @@ -39,6 +41,10 @@ func (s *Supervisor) Start() error { s.startStopLock.Lock() defer s.startStopLock.Unlock() + if s.shutdown { + return errors.New("not starting child process: shutdown already started") + } + log.Printf("Starting: %s\n", s) if err := s.cmd.Start(); err != nil { return fmt.Errorf("failed to start child process: %v", err) @@ -90,6 +96,8 @@ func (s *Supervisor) ShutdownNow() error { s.startStopLock.Lock() defer s.startStopLock.Unlock() + s.shutdown = true + if !s.isRunning() { log.Println("Skipping ShutdownNow: child process not running") return nil @@ -109,6 +117,8 @@ func (s *Supervisor) ShutdownWithTimeout(timeout time.Duration) error { s.startStopLock.Lock() defer s.startStopLock.Unlock() + s.shutdown = true + if !s.isRunning() { log.Println("Skipping ShutdownWithTimeout: child process not running") return nil diff --git a/pkg/tombstone/tombstone.go b/pkg/tombstone/tombstone.go index 68acf65..4e59db5 100644 --- a/pkg/tombstone/tombstone.go +++ b/pkg/tombstone/tombstone.go @@ -166,5 +166,19 @@ func Watch(ctx context.Context, graveyard string, eventHandler EventHandler) err if err != nil { return fmt.Errorf("failed to add watcher: %v", err) } + + files, err := ioutil.ReadDir(graveyard) + if err != nil { + return fmt.Errorf("failed to read graveyard dir: %v", err) + } + + for _, f := range files { + event := fsnotify.Event{ + Name: filepath.Join(graveyard, f.Name()), + Op: fsnotify.Create, + } + eventHandler(event) + } + return nil }