| 43 | } |
| 44 | |
| 45 | func NewProcessMonitor() *ProcessMonitor { |
| 46 | var cn garlic.CnConn |
| 47 | var err error |
| 48 | |
| 49 | for i := 1; i <= PCNStartupTries; i++ { |
| 50 | cn, err = garlic.DialPCNWithEvents([]garlic.EventType{garlic.ProcEventExit}) |
| 51 | if err != nil { |
| 52 | logrus.Errorf("Failed do start process monitor (attempt %d): (error: %s)", i, err.Error()) |
| 53 | continue |
| 54 | } |
| 55 | |
| 56 | break |
| 57 | } |
| 58 | |
| 59 | if err != nil { |
| 60 | // kill worker node daemon if process monitor doesn't start |
| 61 | logrus.Fatalf("Failed do start process monitor. Terminating worker daemon.") |
| 62 | } |
| 63 | |
| 64 | pm := &ProcessMonitor{ |
| 65 | PCN: cn, |
| 66 | NotifyChannels: make(map[uint32]chan uint32), |
| 67 | RWMutex: sync.RWMutex{}, |
| 68 | } |
| 69 | |
| 70 | go pm.internalEventHandler() |
| 71 | |
| 72 | return pm |
| 73 | } |
| 74 | |
| 75 | func (pm *ProcessMonitor) AddChannel(PID uint32, notifyChannel chan uint32) { |
| 76 | pm.Lock() |