Wait for both api and agent chans if necessary when daemonize is false or running on windows (#2155)
This commit is contained in:
parent
0279e549bd
commit
1e018bdaf8
1 changed files with 16 additions and 6 deletions
|
@ -356,14 +356,24 @@ func Serve(cConfig *csconfig.Config, apiReady chan bool, agentReady chan bool) e
|
|||
return HandleSignals(cConfig)
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-apiTomb.Dead():
|
||||
waitChans := make([]<-chan struct{}, 0)
|
||||
|
||||
if !cConfig.DisableAgent {
|
||||
waitChans = append(waitChans, crowdsecTomb.Dead())
|
||||
}
|
||||
|
||||
if !cConfig.DisableAPI {
|
||||
waitChans = append(waitChans, apiTomb.Dead())
|
||||
}
|
||||
|
||||
for _, ch := range waitChans {
|
||||
<-ch
|
||||
switch ch {
|
||||
case apiTomb.Dead():
|
||||
log.Infof("api shutdown")
|
||||
return nil
|
||||
case <-crowdsecTomb.Dead():
|
||||
case crowdsecTomb.Dead():
|
||||
log.Infof("crowdsec shutdown")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue