Skip to content

Instantly share code, notes, and snippets.

@limansky

limansky/conf.d

Created Sep 12, 2013
Embed
What would you like to do?
Initscript for headless virtualbox
# Virtual machine name
VMNAME="guest"
# User, owing virtual machine
VMUSER="vboxuser"
# Stop mode. One off acpipowerbutton | savestate
VMSTOP="savestate"
#!/sbin/runscript
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $
extra_commands="state"
vboxmanage="/usr/bin/VBoxManage"
sucmd="su - $VMUSER -c "
depend() {
before iptables
after net
}
state() {
local state=`$sucmd "$vboxmanage showvminfo $VMNAME | grep '^State:' | sed -s 's/^State: \+//'"`
einfo "Machine $VMNAME state: $state"
}
start() {
ebegin "Starting Virtual machine $VMNAME"
$sucmd "$vboxmanage startvm $VMNAME -t headless"
eend $?
}
stop() {
local state=`$sucmd "$vboxmanage showvminfo $VMNAME | grep '^State:' | sed -s 's/^State: \+//'"`
ebegin "Stoping Virtual machine $VMNAME"
if grep -q "powered off" <<< $state ; then
einfo "Machine is powered off, nothing to do"
else
$sucmd "$vboxmanage controlvm $VMNAME $VMSTOP"
fi
eend $?
}
restart() {
stop
sleep 1
start
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment