From 35504070c2dd36e8486e0d077a9b94277ddd6254 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Meireles?= Date: Tue, 5 Jan 2016 11:19:23 +0000 Subject: [PATCH] wait up to 30s for a VM to halt gracefully. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: António Meireles --- halt.go | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/halt.go b/halt.go index fd4808c..c8376bb 100644 --- a/halt.go +++ b/halt.go @@ -101,20 +101,24 @@ func (vm VMInfo) halt() (err error) { } } // wait until it's _really_ dead, but not forever - select { - case <-time.After(3 * time.Second): - err = fmt.Errorf("VM didn't shutdown normally after 3s (!)... ") - case <-time.Tick(100 * time.Millisecond): - if _, ee := os.FindProcess(vm.Pid); ee == nil { - if e := - os.RemoveAll(filepath.Join(engine.runDir, - vm.UUID)); e != nil { - log.Println(e.Error()) + for { + select { + // unmounts may take a bit in slow drives... + case <-time.After(30 * time.Second): + return fmt.Errorf(fmt.Sprintf("'%s' didn't shutdown normally "+ + "after 30s (!)... ", vm.Name)) + case <-time.Tick(100 * time.Millisecond): + if _, ee := os.FindProcess(vm.Pid); ee == nil { + if e := + os.RemoveAll(filepath.Join(engine.runDir, + vm.UUID)); e != nil { + log.Println(e.Error()) + } + log.Printf("successfully halted '%s'\n", vm.Name) + return } - log.Printf("successfully halted '%s'\n", vm.Name) } } - return } func init() {