On Sat, Feb 17, 2018 at 08:36:41PM +0000, Stuart Henderson wrote:
> On 2018/02/17 10:47, Mike Larkin wrote:
> > On Sat, Feb 17, 2018 at 10:10:37AM +0000, Stuart Henderson wrote:
> > > On 2018/02/16 17:55, Aaron Bieber wrote:
> > > > Hola,
> > > >
> > > > Here is a stab at telling /etc/rc.d/vmd to wait for vms to shutdown
> > > > before killing vmd.
> > > >
> > > > Since there is no linux vmmci layer - linux machines still get killed.
> > >
> > > Simpler and less busy-waiting. Do we need a timeout though?
> > >
> >
> > vmmci auto shutdown will just kill the OpenBSD guests after 30 seconds if
> > they don't shutdown on their own.
> >
> > That means we would need 30*n seconds, where n is the number of active
> > OpenBSD guests, plus a small amount of time for each not-OpenBSD guest.
> >
> > Is this the timeout you were referring to?
>
> that should be ok in the normal situation, but i'm wondering if we need
> something extra in case things gets stuck and we don't actually get shutdown
> following the "vmctl stop" command.
>
> (rc.subr normally has its own timeout after which time it gives up on a
> command and reports it as failed, but doing the while-loop waiting for
> the vm to exit means that the normal mechanism won't work).
>
> the earlier versions of the script (abieber's and my shorter one) were
> firing off all the shutdown requests together ("30-and-a-bit seconds"
> total, rather than Nx30). one at a time is probably a better idea to
> avoid thundering herd though, that looks something like the diff below.
>
>
> Index: vmd
> ===================================================================
> RCS file: /cvs/src/etc/rc.d/vmd,v
> retrieving revision 1.6
> diff -u -p -r1.6 vmd
> --- vmd 11 Jan 2018 22:44:44 -0000 1.6
> +++ vmd 17 Feb 2018 20:16:25 -0000
> @@ -11,4 +11,19 @@ rc_pre() {
> ${daemon} -n ${daemon_flags}
> }
>
> +list_running() {
> + vmctl status | awk '$2 ~ "[0-9]" {print $8}'
> +}
> +
> +rc_stop() {
> + for vm in $(list_running); do
> + _rc_do vmctl stop "$vm"
> + while list_running | fgrep -wq "$vm"; do
> + sleep .1
> + done
> + done
> +
> + pkill -T "${daemon_rtable}" -xf "${pexp}"
> +}
> +
> rc_cmd $1
>
>
> > PS - not to bikeshed here, but would it be worthwhile to print a list
> > of which VMs are being shutdown?
>
> I've added _rc_do on the "vmctl stop" line above so that it will show up
> with "rcctl -d stop vmd", but rcctl intentionally hides output unless -d
> is used and I'm not sure how/whether we should get around that.
>
> input from real rc.d hackers would be appreciated :)
>
I welcome any improvement in this area and will defer to you and "real rc.d
hackers" as to the best approach.
-ml