X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/da0aee751d8cb039c9b6b85a03e7d62cb973e3b3..e356309e05714cd65d88456c563cea606f820394:/services/crunch-dispatch-local/crunch-dispatch-local.go diff --git a/services/crunch-dispatch-local/crunch-dispatch-local.go b/services/crunch-dispatch-local/crunch-dispatch-local.go index 0ca7651851..cfb0c7da94 100644 --- a/services/crunch-dispatch-local/crunch-dispatch-local.go +++ b/services/crunch-dispatch-local/crunch-dispatch-local.go @@ -10,7 +10,9 @@ import ( "log" "os" "os/exec" + "os/signal" "sync" + "syscall" "time" ) @@ -54,16 +56,24 @@ func doMain() error { arv.Retries = 25 dispatcher := dispatch.Dispatcher{ - Arv: arv, - RunContainer: run, - PollInterval: time.Duration(*pollInterval) * time.Second, - DoneProcessing: make(chan struct{})} + Arv: arv, + RunContainer: run, + PollInterval: time.Duration(*pollInterval) * time.Second, + } - err = dispatcher.RunDispatcher() + err = dispatcher.Run() if err != nil { return err } + c := make(chan os.Signal, 1) + signal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT) + sig := <-c + log.Printf("Received %s, shutting down", sig) + signal.Stop(c) + + dispatcher.Stop() + runningCmdsMutex.Lock() // Finished dispatching; interrupt any crunch jobs that are still running for _, cmd := range runningCmds {