summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Elio 'Flameeyes' Pettenò <flameeyes@gmail.com>2009-11-17 18:05:22 +0100
committerDiego Elio 'Flameeyes' Pettenò <flameeyes@gmail.com>2009-11-17 18:05:22 +0100
commitf72458764d4cd3e1a7549a612c7511d7341de265 (patch)
tree9bdb065a7b885115f682b8c3b46839f1877ae5b7
downloadvm-init-scripts-f72458764d4cd3e1a7549a612c7511d7341de265.tar.gz
vm-init-scripts-f72458764d4cd3e1a7549a612c7511d7341de265.tar.bz2
vm-init-scripts-f72458764d4cd3e1a7549a612c7511d7341de265.zip
Initial import of the vm init script.HEADmaster
-rwxr-xr-xvm.init75
1 files changed, 75 insertions, 0 deletions
diff --git a/vm.init b/vm.init
new file mode 100755
index 0000000..70a9c0b
--- /dev/null
+++ b/vm.init
@@ -0,0 +1,75 @@
+#!/sbin/runscript
+# Copyright 2009 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+VMNAME=${SVCNAME#*.}
+PIDFILE=/var/run/vm/${VMNAME}.pid
+MONITOR=/var/run/vm/${VMNAME}.monitor
+
+opts="reboot"
+
+depend() {
+ if [ "${NETWORK}" = "vde" ]; then
+ need vde net.vde0
+ fi
+}
+
+send_command() {
+ echo "$@" | nc6 -U ${MONITOR} --send-only >/dev/null 2>&1
+}
+
+start() {
+ if [ ${VMNAME} = ${SVCNAME} ]; then
+ eerror "You have to create an init script for each vm:"
+ eerror " ln -s vm /etc/init.d/vm.vmname"
+ return 1
+ fi
+
+ _macaddr=$(fgrep ${VMNAME} /etc/ethers | awk '{ print $1 }')
+ if [ -z ${_macaddr} ]; then
+ eerror "Unable to find a mac address for the given machine"
+ eend 1
+ return 1
+ fi
+
+ ebegin "Starting ${VMSOFTWARE-qemu} for ${VMNAME}"
+ start-stop-daemon --start /usr/bin/${VMSOFTWARE-qemu} \
+ --pidfile ${PIDFILE} \
+ -- -daemonize -pidfile ${PIDFILE} -monitor unix:${MONITOR},server,nowait -runas nobody \
+ ${ENABLE_KVM+--enable-kvm} $(readlink ${IMAGE}) \
+ -net ${NETWORK} -net nic,macaddr=${_macaddr}${NETWORK_MODEL+,model=${NETWORK_MODEL}} \
+ ${MEMORY+-m ${MEMORY}} ${VNC_ADDRESS+-vnc ${VNC_ADDRESS}} ${OTHER_ARGS}
+ eend $?
+}
+
+reboot() {
+ if [ ${VMNAME} = ${SVCNAME} ]; then
+ eerror "You have to create an init script for each vm:"
+ eerror " ln -s vm /etc/init.d/vm.vmname"
+ return 1
+ fi
+
+ ebegin "Rebooting ${VMNAME}"
+ send_command system_reset
+ eend $?
+}
+
+stop() {
+ if [ ${VMNAME} = ${SVCNAME} ]; then
+ eerror "You have to create an init script for each vm:"
+ eerror " ln -s vm /etc/init.d/vm.vmname"
+ return 1
+ fi
+
+ ebegin "Powering off ${VMNAME}"
+ send_command system_powerdown
+ eend $?
+
+ sleep 15
+
+ ebegin "Stopping ${VMSOFTWARE-qemu} for ${VMNAME}"
+ start-stop-daemon --stop /usr/bin/${VMSOFTWARE-qemu} \
+ --user nobody \
+ --pidfile ${PIDFILE} \
+ --quiet
+}