aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2018-01-04 14:36:49 +0100
committerKarel Kočí <cynerd@email.cz>2018-01-04 14:36:49 +0100
commitc7a5e8a06539dce8dd09649bbb8e7fd6fa062b67 (patch)
tree056ecb2ae69a1f2f25123780e60ef50389e6ed2f
parent2e28aa8097ac675db8019d7d5e6b46c2fdef1611 (diff)
downloadmulticonfig-c7a5e8a06539dce8dd09649bbb8e7fd6fa062b67.tar.gz
multiconfig-c7a5e8a06539dce8dd09649bbb8e7fd6fa062b67.tar.bz2
multiconfig-c7a5e8a06539dce8dd09649bbb8e7fd6fa062b67.zip
Add virt
-rwxr-xr-xvirt/virt-monitor2
-rwxr-xr-xvirt/virt-serial2
-rwxr-xr-xvirt/virt.init51
3 files changed, 55 insertions, 0 deletions
diff --git a/virt/virt-monitor b/virt/virt-monitor
new file mode 100755
index 0000000..cd6e173
--- /dev/null
+++ b/virt/virt-monitor
@@ -0,0 +1,2 @@
+#!/bin/sh
+socat - UNIX-CONNECT:/run/virt/$1/serial.sock
diff --git a/virt/virt-serial b/virt/virt-serial
new file mode 100755
index 0000000..cd6e173
--- /dev/null
+++ b/virt/virt-serial
@@ -0,0 +1,2 @@
+#!/bin/sh
+socat - UNIX-CONNECT:/run/virt/$1/serial.sock
diff --git a/virt/virt.init b/virt/virt.init
new file mode 100755
index 0000000..6ccbd9e
--- /dev/null
+++ b/virt/virt.init
@@ -0,0 +1,51 @@
+#!/sbin/openrc-run
+# vim: ft=sh
+VM_NAME="${RC_SVCNAME#virt.}"
+
+depend() {
+ need networking
+ after iptables ip6tables
+ use logger
+}
+
+pid_file="/run/virt/$VM_NAME/pid"
+
+status() {
+ if [ -f "$pid_file" ]; then
+ if kill -0 "$(cat "$pid_file")" >/dev/null 2>&1; then
+ einfo "Virtual $VM_NAME is running"
+ else
+ eerror "Virtual $VM_NAME isn't running but some garbage was left"
+ fi
+ else
+ ewarn "Virtual $VM_NAME isn't running"
+ fi
+}
+
+start() {
+ if [ "$RC_SVCNAME" = 'virt' ]; then
+ eerror 'You are not supposed to run this runscript directly. Instead, you should create a symlink for the VM you want to run.'
+ return 1
+ fi
+
+ mkdir -p /run/virt/$VM_NAME
+ chown :qemu /run/virt/$VM_NAME
+ chmod 775 /run/virt/$VM_NAME
+
+ qemu-system-x86_64 $ARGS -daemonize -runas qemu \
+ -pidfile "$pid_file" -D /var/log/virt.$VM_NAME.log \
+ -monitor unix:/run/virt/$VM_NAME/monitor.sock,server,nowait \
+ -serial unix:/run/virt/$VM_NAME/serial.sock,server,nowait
+}
+
+stop() {
+ if [ -f "$pid_file" ] && kill -0 $(cat "$pid_file") >/dev/null 2>&1; then
+ PID=$(cat "$pid_file")
+ kill $PID
+ # TODO if there are problems we should implement also timeout
+ while kill -0 $PID >/dev/null 2>&1; do sleep 1; done
+ else
+ ewarn "Virtual $VM_NAME is not running"
+ fi
+}
+