Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Merge tombstone updates #3

Merged
merged 4 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions cmd/kubexit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,11 @@ func onDeathOfAny(deathDeps []string, callback func()) tombstone.EventHandler {
deathDepSet[depName] = struct{}{}
}

return func(event fsnotify.Event) {
if event.Op&fsnotify.Create != fsnotify.Create && event.Op&fsnotify.Write != fsnotify.Write {
// ignore other events
return func(graveyard string, name string, op fsnotify.Op) {
if op != 0 && op&fsnotify.Create != fsnotify.Create && op&fsnotify.Write != fsnotify.Write {
// ignore events other than initial, create and write
return
}
graveyard := filepath.Dir(event.Name)
name := filepath.Base(event.Name)

log.Info("Tombstone modified:", "name", name)
if _, ok := deathDepSet[name]; !ok {
Expand Down
10 changes: 10 additions & 0 deletions pkg/supervisor/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Supervisor struct {
cmd *exec.Cmd
sigCh chan os.Signal
startStopLock sync.Mutex
shutdown bool
shutdownTimer *time.Timer
}

Expand All @@ -32,13 +33,18 @@ func New(name string, args ...string) *Supervisor {
cmd.Env = os.Environ()
return &Supervisor{
cmd: cmd,
shutdown: false,
}
}

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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down