Created
September 12, 2013 18:30
-
-
Save limansky/6541885 to your computer and use it in GitHub Desktop.
Initscript for headless virtualbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Virtual machine name | |
VMNAME="guest" | |
# User, owing virtual machine | |
VMUSER="vboxuser" | |
# Stop mode. One off acpipowerbutton | savestate | |
VMSTOP="savestate" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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