From fa0e36f53d4ad5ef2c2c3a6d431a1266926994d6 Mon Sep 17 00:00:00 2001 From: David Scott Date: Thu, 30 Apr 2015 16:38:28 +0100 Subject: [PATCH] xenvm shutdown: block until the daemon has gone A quick start/shutdown loop tended to fail when more than one daemon is alive at once. This makes the shutdown command wait until the RPCs to xenvmd start to fail, and assumes that xenvmd is now effectively offline. Signed-off-by: David Scott --- xenvm/xenvm.ml | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/xenvm/xenvm.ml b/xenvm/xenvm.ml index 164ce04..b9b03b5 100644 --- a/xenvm/xenvm.ml +++ b/xenvm/xenvm.ml @@ -139,8 +139,25 @@ let host_list config = let shutdown config = set_uri config None; - Lwt_main.run - (Client.shutdown ()) + let t = + Client.shutdown () + >>= fun () -> + (* wait for the daemon to disappear *) + let finished = ref false in + let rec wait () = + Lwt.catch + (fun () -> + Client.Host.all () + >>= fun _ -> + Printf.fprintf stderr "Xenvmd is still alive: will sleep 5s and try again\n%!"; + Lwt_unix.sleep 5. + ) (fun _ -> + finished := true; + return ()) + >>= fun () -> + if !finished then return () else wait () in + wait () in + Lwt_main.run t let benchmark config = set_uri config None;