Auto start phpvirtualbox VMs on server reboot

NethServer Version: 7.6.1810
Module: phpvirtualbox

I am new to Nethserver. After working with phpvirtualbox and trying to install ERPNext VM.
Login and importing official ERPNext VM was succesfull after following:

https://docs.nethserver.org/en/latest/phpVirtualBox.html#vm-networking
and

My goal was to achieve autostart vms when server reboot.
After following this link, I was able to create pausevms and resumevms scripts :
https://vorkbaard.nl/how-to-set-up-a-virtualbox-server-in-debian-9-web-interface-autostart-backup/

modified pausevms script:

#!/bin/bash
# Pause running VMs
 
STATUSFILE=/home/vboxweb/vm-status
# Clear the previous status file if it exists
if [ -e $STATUSFILE ]; then rm $STATUSFILE; fi

# List all VMs
for VM in $(sudo -H -u vboxweb vboxmanage list vms | rev | cut -d' ' -f1 | rev)
do
    # Get VM state
    STATE=$(sudo -H -u vboxweb vboxmanage showvminfo $VM --machinereadable | grep "VMState=" | cut -d'=' -f2)
    
    # Pause if state is running or paused, write to status file
    if [[ $STATE == \"running\" || $STATE == \"paused\" ]]; then
        sudo -H -u vboxweb vboxmanage controlvm $VM savestate
    # No need to restart paused vm's; just let them remain saved.
    if [[ $STATE == \"running\" ]]; then echo "$VM">>$STATUSFILE; fi
    fi
done

modified resuemvms script:

#!/bin/bash
# Restart VMs saved earlier

STATUSFILE=/home/vboxweb/vm-status

# If no status file exists then apparently there are no VMs to resume.
if [ ! -f $STATUSFILE ]; then exit; fi

while read VM; do
    sudo -H -u vboxweb vboxmanage startvm $VM --type headless
done <$STATUSFILE

On server shutdown the created pausevms script worked well with the help of this link:
https://docs.nethserver.org/projects/nethserver-devel/en/v7/events.html

commands to configure shutdown script:

vi /etc/e-smith/events/actions/pausevms
chmod +x /etc/e-smith/events/actions/pausevms
ln -s /etc/e-smith/events/actions/pausevms /etc/e-smith/events/system-shutdown/S15pausevms

Same method used to configure resumevms on server reboot, but it didn’t work:

vi /etc/e-smith/events/actions/resumevms
chmod +x /etc/e-smith/events/actions/resumevms
ls -s /etc/e-smith/events/actions/resumevms /etc/e-smith/events/system-init/S99resumevms

kindly support how can I configure the resumevms script to auto run on sever reboot?

1 Like

Hi @Mohanadab and welcome to the NethServer community.
You picked a not so much used module for your first question. However, we will try to help you with this.
@support_team Do you have any ideas to help him?

I found this link that might be of use: https://www.glump.net/howto/virtualization/setup-virtualbox-as-a-service-in-linux but at first glance, the tips in the link are already available in your usecase?

Sorry for long delay,
I don’t have installed php vbox, but perhaps the following link could help.

https://sourceforge.net/p/phpvirtualbox/discussion/help/thread/3880e013/?limit=25

1 Like