#!/bin/sh
#


# Loop running vms to shutdown
# For each one, send the ACPI shutdown command
# Allow 2 mins for shutdown
# If still has not shut down, kill the Bhyve vm process
# Then destroy the vm 

vmname=$1
echo "Attempting to shutdown Bhyve VM $vmname gracefully.  "
pkill -TERM -f "bhyve: $vmname"




# Useful commands
#
# Find the VM PID:
# pgrep -f "bhyve: <vm_name>"

# Send the TERM signal:
# kill -s TERM $(pgrep -f "bhyve: <vm_name>")

# See which vms are running:
# 
# ls -F /dev/vmm

# Using ps (Process List)
# You can search for the bhyve processes directly to see which VMs are currently active in the process table:
# ps ax | grep 'bhyve: '

# Using bhyvectl
# You can try to list VMs with the bhyvectl command, although this is usually used for managing individual VMs rather than listing all at once.
