summaryrefslogtreecommitdiff
blob: 891137a2d26724c19fd599daec85883b4adb2876 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/sbin/openrc-run

description="Controls VirtualBox sessions"

. /etc/conf.d/vboxwebsrv

su_command="su - ${VBOXWEBSRV_USER} -c"

depend() {
	need localmount
	after bootmisc
}

start() {
	einfo "Starting VirtualBox machines"
	eindent
	MACHINES=$($su_command "VBoxManage list vms | awk '{ print \$NF }' | sed -e 's/[{}]//g'")
	for UUID in $MACHINES; do
		STARTUP=$($su_command "VBoxManage getextradata $UUID 'pvbx/startupMode'" | awk '{ print $NF }')
		VMNAME=$($su_command "VBoxManage showvminfo $UUID | sed -n '0,/^Name:/s/^Name:[ \t]*//p'")
		if [ "${STARTUP}" == "auto" ]; then
			ebegin "Starting machine ${VMNAME}"
			$su_command "VBoxManage startvm $UUID --type headless" &>> /var/log/vboxinit.log
			eend $?
		fi
	done
}

stop() {
	einfo "Saving VirtualBox machines"
	eindent
	MACHINES=$($su_command "VBoxManage list runningvms | awk '{ print \$NF }' | sed -e 's/[{}]//g'")
	for UUID in $MACHINES; do
		VMNAME=$($su_command "VBoxManage showvminfo $UUID | sed -n '0,/^Name:/s/^Name:[ \t]*//p'")
		ebegin "Stopping machine ${VMNAME}"
		$su_command "VBoxManage controlvm $UUID savestate" &>> /var/log/vboxinit.log
		eend $?
	done
}