Problem: Cannot use 'curl' in 'Tasks > /Init/Shutdown Scripts': "curl: not found". I'm using curl in a script to shut down Windows VM's gracefully.
The only way I have come across to ensure gracefully shutdown a Windows 10/2016/2019 bhyve vm (created in gui) is to ssh in to the vm and issue a shutdown from there. (The bhyve 'poweroff' kills the Windows VM and the 'stop' is very inconsistent - sometimes it works and sometimes not). Then, to figure out when the VM actually has stopped (after the ssh shutdown command) I use curl to access the FreeNAS api (2.0). To my knowledge there are no bhyve command line wrapper that interface the FreeNAS bhyve gui. I've tried iohyve, vm, bhyvectl, and none of them worked for the gui-created VMs.
My questions are: Why can I not use curl in the freenas shutdown script? Are there any other ways (than accessing the freenas api) to tell when the state of a gui-created VM has switched from 'running' to 'stopped'? It would be great to have a command line bhyve wrapper that also works for bhyve gui-created vm's (similar to iocage for jails) of course...
Script:
There was a ticket on bhyve vm shutdown some time back, but whatever was done doesn't seem to work for Windows 10/2016/2019. I do however understand that without guest tools installed in the VM shutting down gracefully can be tricky.
The only way I have come across to ensure gracefully shutdown a Windows 10/2016/2019 bhyve vm (created in gui) is to ssh in to the vm and issue a shutdown from there. (The bhyve 'poweroff' kills the Windows VM and the 'stop' is very inconsistent - sometimes it works and sometimes not). Then, to figure out when the VM actually has stopped (after the ssh shutdown command) I use curl to access the FreeNAS api (2.0). To my knowledge there are no bhyve command line wrapper that interface the FreeNAS bhyve gui. I've tried iohyve, vm, bhyvectl, and none of them worked for the gui-created VMs.
My questions are: Why can I not use curl in the freenas shutdown script? Are there any other ways (than accessing the freenas api) to tell when the state of a gui-created VM has switched from 'running' to 'stopped'? It would be great to have a command line bhyve wrapper that also works for bhyve gui-created vm's (similar to iocage for jails) of course...
Script:
Code:
#!/bin/sh VMID=$1 VMIP=$2 initialstate=$( curl --silent --show-error -u root:<password> "http://192.168.1.14/api/v2.0/vm/id/$VMID" | grep "state" | awk '{print $2}' | tr -d ',"' ) if [ "$initialstate" != "STOPPED" ]; then sshshutdown=$( ssh Administrator@$VMIP 'shutdown /s /t 0' 2>&1 ) if [ `echo $sshshutdown | wc -w ` -ne 0 ]; then printf "Shutdown failed VM $VMID: $sshshutdown" exit 1 fi fi state=$( curl --silent --show-error -u root:<password> "http://192.168.1.14/api/v2.0/vm/id/$VMID" | grep "state" | awk '{print $2}' | tr -d ',"' ) counter=0 while [ "$state" != "STOPPED" ]; do state=$( curl --silent --show-error -u root:<password> "http://192.168.1.14/api/v2.0/vm/id/$VMID" | grep "state" | awk '{print $2}' | tr -d ',"' ) counter=$((counter+1)) sleep 10 if [ `echo $counter` -gt 1080 ]; then printf "Shutdown failed VM $VMID: \n$state" exit 1 fi done
There was a ticket on bhyve vm shutdown some time back, but whatever was done doesn't seem to work for Windows 10/2016/2019. I do however understand that without guest tools installed in the VM shutting down gracefully can be tricky.
Last edited: