mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-27 04:11:03 +00:00
gracefully shutdown agent when builds running
This commit is contained in:
parent
71de0d9408
commit
88df2520c8
2 changed files with 27 additions and 0 deletions
|
@ -1,7 +1,10 @@
|
|||
package agent
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/drone/drone/client"
|
||||
|
@ -201,5 +204,25 @@ func start(c *cli.Context) {
|
|||
}
|
||||
}()
|
||||
}
|
||||
handleSignals()
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
// tracks running builds
|
||||
var running sync.WaitGroup
|
||||
|
||||
func handleSignals() {
|
||||
// Graceful shut-down on SIGINT/SIGTERM
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, os.Interrupt)
|
||||
signal.Notify(c, syscall.SIGTERM)
|
||||
|
||||
go func() {
|
||||
<-c
|
||||
logrus.Debugln("SIGTERM received.")
|
||||
logrus.Debugln("wait for running builds to finish.")
|
||||
running.Wait()
|
||||
logrus.Debugln("done.")
|
||||
os.Exit(0)
|
||||
}()
|
||||
}
|
||||
|
|
|
@ -33,6 +33,10 @@ func (r *pipeline) run() error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
running.Add(1)
|
||||
defer func() {
|
||||
running.Done()
|
||||
}()
|
||||
|
||||
logrus.Infof("Starting build %s/%s#%d.%d",
|
||||
w.Repo.Owner, w.Repo.Name, w.Build.Number, w.Job.Number)
|
||||
|
|
Loading…
Reference in a new issue