From owner-freebsd-virtualization@FreeBSD.ORG Tue Feb 11 22:29:21 2014 Return-Path: Delivered-To: freebsd-virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 50BCCC8E; Tue, 11 Feb 2014 22:29:21 +0000 (UTC) Received: from mail-la0-x22a.google.com (mail-la0-x22a.google.com [IPv6:2a00:1450:4010:c03::22a]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 896E119C1; Tue, 11 Feb 2014 22:29:20 +0000 (UTC) Received: by mail-la0-f42.google.com with SMTP id hr13so6455732lab.15 for ; Tue, 11 Feb 2014 14:29:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=kjnB8mcHjkDxBYrM0Gox27+p4rVBh4Vsd9cAj5w+ncw=; b=0BIsvBSAea6tPRaSk5W/FP3xJvvZ07aGIJg++0p8O1k5GRmqRkCA8kqFfm7QMkC0Mo RO3+heZMJnrUsS5OKTlVTHEXsG45akYyRy5TmaV9WahLIhlcftjG9SN6m0XBhTOLKMng +j6RAYLZC/D2gAttSC4A7r4D/7V+NThrYahKOxFXncL/OW6w4n9k5xDHTLFvpz0bM1HN OtGwxjKtpgszeaV7yObCidOmmjb6FubIHDO7AucLFJYHcvmIpEAYuxRb1lnwC2A76VD0 VXyPv5Xqfz2nDwY9/Ob+4Itpx+1eeVIJB61KTeS/I7sKRYweFogqchK52HsflNsCvO9P kvSw== MIME-Version: 1.0 X-Received: by 10.112.114.228 with SMTP id jj4mr26883596lbb.13.1392157758522; Tue, 11 Feb 2014 14:29:18 -0800 (PST) Sender: crodr001@gmail.com Received: by 10.112.30.211 with HTTP; Tue, 11 Feb 2014 14:29:18 -0800 (PST) In-Reply-To: <201402111411.33269.jhb@freebsd.org> References: <201402111411.33269.jhb@freebsd.org> Date: Tue, 11 Feb 2014 14:29:18 -0800 X-Google-Sender-Auth: IClU34vp_VhEINijhW9Jhoiq3RI Message-ID: Subject: Re: Detect of BHyve VM was powered off or rebooted? From: Craig Rodrigues To: John Baldwin Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.17 Cc: "freebsd-virtualization@freebsd.org" X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "Discussion of various virtualization techniques FreeBSD supports." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Feb 2014 22:29:21 -0000 On Tue, Feb 11, 2014 at 11:11 AM, John Baldwin wrote: > On Sunday, February 09, 2014 7:03:41 pm Neel Natu wrote: > > Hi Craig, > > > > On Sun, Feb 9, 2014 at 1:11 PM, Craig Rodrigues > wrote: > > > Hi, > > > > > > I posted some rc.d scripts that I am using to boot a BHyve VM > > > and send the output to a serial console using the /dev/nmdm > > > driver: > > > > > > http://lists.freebsd.org/pipermail/freebsd-virtualization/2014- > January/002040.html > > > > > > It works quite well. There is some things I would like to improve, > > > and would like some advice on the best way to do it. > > > > > > (1) If the VM was destroyed with bhyvectl --destroy --vm ${VM_NAME}, > > > then I do not want to automatically restart the VM in the script. > > > User should manually: service bhyvevm start > > > > > > (2) If the VM was powered down, via shutdown -p, or halt -p, > > > then in my script I do not want to restart the VM in the script. > > > User should manually: service bhyvevm start > > > > > > (3) If the VM was rebooted via "reboot" or "shutdown -r", > > > then I *do* want the script to restart the VM. > > > > > > I think if I change my start_vm.sh script to do something like: > > > > > > > > > > > > ( > > > while [ -e /dev/vmm/${VM} ]; do > > > /usr/sbin/bhyve -c 16 -m 8G -A -H -P -g 0 -s 0:0,hostbridge -s > 1:0,lpc > > > -s 2:0,virtio-net,${TAP} -s 3:0,virtio-blk,${IMG} -l com1,${CONS_A} > ${VM}" > > > done > > > > > > ) & > > > > > > > > > then this might cover cases (1) and (3), but what will cover > > > case (2)? > > > > The exit code of the bhyve process will be 0 if it exited because the > > guest rebooted and will be non-zero if the guest did an acpi poweroff. > > You can use that to distinguish between cases (2) and (3). > > > > Having said that there are error conditions for which bhyve exits with > > a non-zero exit code. So, we'll need to explicitly define an exit code > > to distinguish between an acpi poweroff and these error conditions. > > OTOH, in all the cases when bhyve exits with a non-zero exit code, you > will want to exit the loop which would treat it the same as shutdown -p. I > think you can just do this: > > while [ -e /dev/vmm/${VM} ]; do > if ! bhyve ...; then > break > fi > done > One question, if "bhyve" exits, do I have to call bhyveload again before calling bhyve? The /usr/share/examples/bhyve/vmrun.sh has a loop which does: while [ 1 ] ; do ... bhyvectl --destroy bhyveload bhyve ... done -- Craig