Skip to content

Instantly share code, notes, and snippets.

@limansky
Created September 12, 2013 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save limansky/6541885 to your computer and use it in GitHub Desktop.
Save limansky/6541885 to your computer and use it in GitHub Desktop.
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