blob: 70a9c0b22d28504b43cef5dd1d18e8e486fcbba1 (
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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
}
|