Date: Tue, 11 Feb 2014 15:18:11 -0800 From: Neel Natu <neelnatu@gmail.com> To: Craig Rodrigues <rodrigc@FreeBSD.org> Cc: "freebsd-virtualization@freebsd.org" <freebsd-virtualization@freebsd.org> Subject: Re: Detect of BHyve VM was powered off or rebooted? Message-ID: <21FA50D3-8092-40EA-9B66-9BAC34A4A548@gmail.com> In-Reply-To: <CAG=rPVd15giiO_ugOAt2uBDqzePR3A3iCNpXFcXd2QzS1=oqJQ@mail.gmail.com> References: <CAG=rPVcfYQ2nUaZYuc6teL2r%2BQZzxhuoV052zgf6=Dxh8MeNcA@mail.gmail.com> <CAFgRE9Fw308%2BA14c1ttXj%2BYv-CMVRZ-DSE_9DWz46sfpdWg3PQ@mail.gmail.com> <201402111411.33269.jhb@freebsd.org> <CAG=rPVd15giiO_ugOAt2uBDqzePR3A3iCNpXFcXd2QzS1=oqJQ@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Hi Craig, > On Feb 11, 2014, at 2:29 PM, Craig Rodrigues <rodrigc@FreeBSD.org> wrote: >=20 >> On Tue, Feb 11, 2014 at 11:11 AM, John Baldwin <jhb@freebsd.org> 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 <rodrigc@freebsd.org> >> 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"
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?21FA50D3-8092-40EA-9B66-9BAC34A4A548>