Auto start and stop VM in FreeNAS

I've done some googling and there are no guides on how to set an automated process to start and stop specific VM's in virtualbox FreeNAS. However I have encountered something along the lines of starting the virtualbox service upon start of the FreeNAS server: FreeNAS: How to auto start VM when FreeNAS boots

I just want to set a VM to start and stop at specific times everyday, is there perhaps a cronjob on doing this with the VM service itself? Or is it much more complicated then that?

Ok, I'm thinking this:

In the jail, create a windowsvmstart.sh and inside is:

#!bin/sh
su vbox -c "/usr/local/bin/VBoxManage startvm 'Windows 8.1' --type headless"

And for stopping it we replace the 'startvm' with 'controlvm' and '--type headless' with 'acpipowerbutton' in a new file named windowsvmstop.sh like so:

#!bin/sh
su vbox -c "/usr/local/bin/VBoxManage controlvm 'Windows 8.1' acpipowerbutton"

And create a cronjob that execute these at specific times in FreeNAS.

Is this viable?

Alrighty then, with some experimentation I can do this from root of freenas meaning I can use the gui cron function for this:

Power On:

#!bin/sh
jexec 1 su vbox -c "/usr/local/bin/VBoxManage startvm 'Windows 8.1' --type headless"

Power Off:

#!bin/sh
jexec 1 su vbox -c "/usr/local/bin/VBoxManage controlvm 'Windows 8.1' acpipowerbutton"

Then set this in the FreeNAS Cron GUI command text box:

/bin/sh /mnt/volume/scripts/windowvmstart.sh

And for VM stop:

/bin/sh /mnt/volume/scripts/windowvmstop.sh

Don't forget to chmod +x the scripts to allow them to execute, if it fails try chmod 775 on them. I've put my user to root/wheel in cron and the owner of the files. The rest of the settings are up to you, and that's it!

This is perfect when your server needs the freed up cores and memory for other day to day processes when there is high traffic and you don't need to manually keep doing ~5 steps to do it!

I guess I just answered my own question :P