Skip to content
Snippets Groups Projects
Commit d0deb35b authored by Vladimir Druzenko's avatar Vladimir Druzenko
Browse files

emulators/virtualbox-ose{,-nox11}: add vboxinit start/stop script for VMs...

emulators/virtualbox-ose{,-nox11}: add vboxinit start/stop script for VMs which is controlled from phpvirtualbox

Set the "Startup Mode" to "Automatic" for the virtual machine in
phpvirtualbox to automatically start the virtual machine during OS boot.

This script also stops virtual machines during reboot even if
vboxinit_enable="YES" is not present in /etc/rc.conf.

phpvirtualbox uses the "Web Service" (WEBSERVICE) to configure and
manage virtual machines, so we install the script only when the
WEBSERVICE option is enabled.

PR:	280062
parent e4facd44
No related branches found
No related tags found
No related merge requests found
PORTREVISION= 0
PORTREVISION= 1
PKGNAMESUFFIX= -nox11
OPTIONS_EXCLUDE= ALSA DBUS DEBUG GUESTADDITIONS DOCS NLS PULSEAUDIO \
......
PORTNAME= virtualbox-ose
PORTVERSION= 6.1.50
PORTREVISION?= 2
PORTREVISION?= 3
CATEGORIES= emulators
MASTER_SITES= https://download.virtualbox.org/virtualbox/${PORTVERSION}/:src \
LOCAL/bofh/emulators/virtualbox-ose:docs
......@@ -167,7 +167,7 @@ PLIST_SUB+= QT="@comment "
.endif
.if ${PORT_OPTIONS:MWEBSERVICE}
USE_RC_SUBR+= vboxwebsrv
USE_RC_SUBR+= vboxinit vboxwebsrv
VBOX_LINKS+= vboxwebsrv
VBOX_UTILS+= vboxwebsrv webtest
.endif
......
#!/bin/sh
# PROVIDE: vboxinit
# REQUIRE: LOGIN vboxnet vboxwebsrv sshd
# KEYWORD: shutdown
#
# Add the following line to /etc/rc.conf[.local] to enable vboxinit
#
# vboxinit_enable (bool): Set to "NO" by default.
# Set it to "YES" to enable vboxinit.
# stop and faststop are always enabled.
# vboxinit_user (str): Default user account to run with.
# (default: %%VBOXUSER%%)
# vboxinit_home (str): Default home directory to run with.
# (default: home of user ${vboxinit_user}
# vboxinit_stop (str): Default stop cmd for VBoxManage controlvm.
# (default: savestate)
# vboxinit_start_delay (int): Default startup delay in seconds.
# (default: 0)
# vboxinit_stop_delay (int): Default shutdown delay in seconds.
# (default: 0)
#
# Set the "Startup Mode" to "Automatic" for the virtual machine in
# phpvirtualbox to automatically start the virtual machine during OS boot.
#
. /etc/rc.subr
name="vboxinit"
rcvar="${name}_enable"
start_cmd="${name}_start"
stop_cmd="${name}_stop"
status_cmd="${name}_status"
restart_cmd="${name}_restart"
vboxinit_start()
{
# Get a list of all machines with autorun enabled in phpvirtualbox
${su_command} "${command} list vms | /usr/bin/tr -d '{}\"'" | while read VMNAME UUID; do
STARTUP=$(${su_command} "${command} getextradata ${UUID} 'pvbx/startupMode'" | /usr/bin/cut -d' ' -f2)
if [ "${STARTUP}" == "auto" ]; then
echo "${name}: starting machine ${VMNAME} ..."
${su_command} "${command} startvm ${UUID} --type headless"
sleep "${vboxinit_start_delay}"
fi
done
}
vboxinit_stop()
{
# Get all running machines
${su_command} "${command} list runningvms | /usr/bin/tr -d '{}\"'" | while read VMNAME UUID; do
echo "${name}: stopping machine ${VMNAME} with action '${vboxinit_stop}' ..."
${su_command} "${command} controlvm ${UUID} ${vboxinit_stop}"
sleep "${vboxinit_stop_delay}"
done
}
vboxinit_status()
{
# List all running machines
${su_command} "${command} list runningvms"
}
vboxinit_restart()
{
vboxinit_stop
vboxinit_start
}
load_rc_config $name
: ${vboxinit_enable="NO"}
: ${vboxinit_user="%%VBOXUSER%%"}
: ${vboxinit_home=$(/usr/sbin/pw usershow -7 -n "${vboxinit_user}" | /usr/bin/cut -d: -f6)}
: ${vboxinit_stop="savestate"}
: ${vboxinit_start_delay="0"}
: ${vboxinit_stop_delay="0"}
HOME=${vboxinit_home}
USER=${vboxinit_user}
export HOME USER
command="%%VBOXDIR%%/VBoxManage"
su_command="/usr/bin/su -m ${vboxinit_user} -c"
if [ "x$1" = "xstop" ] || [ "x$1" = "xfaststop" ]; then
vboxinit_enable="YES"
fi
run_rc_command "$1"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment