From owner-freebsd-virtualization@FreeBSD.ORG Tue Feb 11 23:18:18 2014 Return-Path: Delivered-To: freebsd-virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 72350BBA; Tue, 11 Feb 2014 23:18:18 +0000 (UTC) Received: from mail-pa0-x235.google.com (mail-pa0-x235.google.com [IPv6:2607:f8b0:400e:c03::235]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 3189A1D66; Tue, 11 Feb 2014 23:18:18 +0000 (UTC) Received: by mail-pa0-f53.google.com with SMTP id lj1so8348793pab.12 for ; Tue, 11 Feb 2014 15:18:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=references:mime-version:in-reply-to:content-type :content-transfer-encoding:message-id:cc:from:subject:date:to; bh=5O3I49OdIm0d/X26UTs94XHvIXQysRMpKXTApcJ5TIo=; b=v1BIepLABuEDV+S+Vuie2HLQ1d0iRDdQ9cLJCEZrJOI+YZ7NlZoX68LwO8k9VIApn7 miI6VqkzSwDT2ZKdRsZ6UWWKl6E80+gMHdnibpe8IAAq9k+t55/ySNQf+u1PozloNQaN yfNOo5rzLKXL5gQjaJQoLZFyawJ1Sxeofcx5nobOnc4tkRHrp5TvMeXvZvYJrkDNHyN1 e9e5uZkjqTzk4K9+Tg7gsPCoWHSPEmAla3ujfGFpTTU7SNWoav82taiR10lInnxmAT6a 9qjZ8V1AauV9GLzMUuT37ddGzUrODaFYk3rqImywPnjwyJ8HZFVyLWSZNIS+vVYOOi3f MaAg== X-Received: by 10.68.255.101 with SMTP id ap5mr47332053pbd.41.1392160697886; Tue, 11 Feb 2014 15:18:17 -0800 (PST) Received: from [10.123.100.151] (mobile-166-137-214-162.mycingular.net. [166.137.214.162]) by mx.google.com with ESMTPSA id ei4sm56788404pbb.42.2014.02.11.15.18.16 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 11 Feb 2014 15:18:16 -0800 (PST) References: <201402111411.33269.jhb@freebsd.org> Mime-Version: 1.0 (1.0) In-Reply-To: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Message-Id: <21FA50D3-8092-40EA-9B66-9BAC34A4A548@gmail.com> X-Mailer: iPhone Mail (11B554a) From: Neel Natu Subject: Re: Detect of BHyve VM was powered off or rebooted? Date: Tue, 11 Feb 2014 15:18:11 -0800 To: Craig Rodrigues 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 23:18:18 -0000 Hi Craig, > On Feb 11, 2014, at 2:29 PM, Craig Rodrigues wrote: >=20 >> On Tue, Feb 11, 2014 at 11:11 AM, John Baldwin wrote: >>=20 >>> On Sunday, February 09, 2014 7:03:41 pm Neel Natu wrote: >>> Hi Craig, >>>=20 >>> On Sun, Feb 9, 2014 at 1:11 PM, Craig Rodrigues >> wrote: >>>> Hi, >>>>=20 >>>> 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: >>>>=20 >>>> http://lists.freebsd.org/pipermail/freebsd-virtualization/2014- >> January/002040.html >>>>=20 >>>> 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. >>>>=20 >>>> (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 >>>>=20 >>>> (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 >>>>=20 >>>> (3) If the VM was rebooted via "reboot" or "shutdown -r", >>>> then I *do* want the script to restart the VM. >>>>=20 >>>> I think if I change my start_vm.sh script to do something like: >>>>=20 >>>>=20 >>>>=20 >>>> ( >>>> 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 >>>>=20 >>>> ) & >>>>=20 >>>>=20 >>>> then this might cover cases (1) and (3), but what will cover >>>> case (2)? >>>=20 >>> 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). >>>=20 >>> 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. >>=20 >> 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: >>=20 >> while [ -e /dev/vmm/${VM} ]; do >> if ! bhyve ...; then >> break >> fi >> done >=20 >=20 >=20 > One question, if "bhyve" exits, do I have to call bhyveload again before > calling bhyve? Yes, that is correct. You will also need to destroy the VM after bhyve exits= . Best Neel >=20 > The /usr/share/examples/bhyve/vmrun.sh has a loop which does: >=20 > while [ 1 ] ; do >=20 > ... > bhyvectl --destroy > bhyveload > bhyve >=20 > ... > done >=20 > -- > Craig > _______________________________________________ > freebsd-virtualization@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-virtualization > To unsubscribe, send any mail to "freebsd-virtualization-unsubscribe@freeb= sd.org"