diff options
-rw-r--r-- | .gitignore | 5 | ||||
-rw-r--r-- | Makefile | 73 | ||||
-rw-r--r-- | README.md | 9 | ||||
-rw-r--r-- | examples/beefcake (renamed from conf.d/qemu.d/beefcake) | 0 | ||||
-rw-r--r-- | examples/qemutest (renamed from conf.d/qemu.d/qemutest) | 0 | ||||
-rw-r--r-- | examples/testbox (renamed from conf.d/qemu.d/testbox) | 0 | ||||
-rwxr-xr-x | qemu.in (renamed from systemd/system/qemu) | 10 | ||||
-rw-r--r-- | qemu@.service.in (renamed from systemd/system/qemu@.service) | 6 | ||||
-rwxr-xr-x | write-ifchanged | 26 |
9 files changed, 121 insertions, 8 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8c156ea --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/qemu +/qemu@.service +.var.* +.tmp.* +*.tmp diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f3e2a11 --- /dev/null +++ b/Makefile @@ -0,0 +1,73 @@ +# Copyright (C) 2016-2018 Luke Shumaker +# SPDX-License-Identifier: AGPL-3.0-or-later + +# GNU standard settings +prefix = /usr/local +exec_prefix = $(prefix) +bindir = $(exec_prefix)/bin +localstatedir = $(prefix)/var +runstatedir = $(or $(shell systemd-path system-runtime 2>/dev/null),$(localstatedir)/run) +sysconfdir = $(prefix)/etc + +# systemd settings +rootprefix = $(prefix) +systemunitdir = $(or $(shell pkg-config --variable=systemdsystemunitdir systemd 2>/dev/null),$(rootprefix)/lib/systemd/system) + +# other +pkgconfdir = $(sysconfdir)/conf.d/qemu.d +BINPROG = $(bindir)/qemu +SOCAT = /bin/socat + +outdir = . +srcdir = . + +#### + +files.out.all += qemu qemu@.service + +files.sys.all += $(BINPROG) +files.sys.all += $(systemunitdir)/qemu@.service +files.sys.all += $(pkgconfdir) + +var = $(patsubst ./%,%,$(outdir)/.var.) + +all: $(addprefix $(outdir)/,$(files.out.all)) +clean: + rm -f -- $(addprefix $(outdir)/,$(files.out.all)) +install: $(addprefix $(DESTDIR),$(files.sys.all)) +.PHONY: all clean install +.SECONDARY: +.DELETE_ON_ERROR: + +$(outdir)/qemu: $(var)runstatedir $(var)pkgconfdir +$(outdir)/qemu@.service: $(var)runstatedir $(var)BINPROG $(var)SOCAT +$(outdir)/%: $(srcdir)/%.in + sed $(foreach v,$(patsubst $(var)%,%,$(filter $(var)%,$^)),-e 's|@$v@|$($v)|g') < $< > $@ + +$(DESTDIR)$(BINPROG): $(outdir)/qemu + install -DTm755 $< $@ +$(DESTDIR)$(systemunitdir)/%: $(outdir)/% + install -DTm644 $< $@ +$(DESTDIR)$(pkgconfdir): $(wildcard $(srcdir)/examples/*) + install -Dm644 -t $@ -- $^ + test -d $@ + touch $@ + +#### + +# Magic to depend on the value of variables + +.PHONY: FORCE +$(var)%: FORCE + @printf '%s' $(call quote.shell,$($*)) | sed 's/^/#/' | ./write-ifchanged $@ +-include $(wildcard $(var)*) + +define at.nl + + +endef + +# I put this as the last line in the file because it confuses Emacs +# syntax highlighting and makes the remainder of the file difficult to +# edit. +quote.shell = $(subst $(at.nl),'$$'\n'','$(subst ','\'',$1)') diff --git a/README.md b/README.md new file mode 100644 index 0000000..d10fa6b --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +A tiny libvirtd alternative that integrates better with systemd + +Requirements: + + - QEMU + - GNU Bash 4.4+ + - numactl + - socat + - taskset (from util-linux) diff --git a/conf.d/qemu.d/beefcake b/examples/beefcake index 21b7e74..21b7e74 100644 --- a/conf.d/qemu.d/beefcake +++ b/examples/beefcake diff --git a/conf.d/qemu.d/qemutest b/examples/qemutest index 04d9046..04d9046 100644 --- a/conf.d/qemu.d/qemutest +++ b/examples/qemutest diff --git a/conf.d/qemu.d/testbox b/examples/testbox index 6e76886..6e76886 100644 --- a/conf.d/qemu.d/testbox +++ b/examples/testbox diff --git a/systemd/system/qemu b/qemu.in index ad58ae3..566cacf 100755 --- a/systemd/system/qemu +++ b/qemu.in @@ -4,12 +4,12 @@ set -euE -o pipefail declare -A vcpu2cpulist numactl=() -source "/etc/conf.d/qemu.d/$1" +source "@pkgconfdir@/$1" args+=( -name "$1",debug-threads=on - -pidfile "/run/qemu-$1/pid" - -vnc unix:"/run/qemu-$1/vnc.sock" - -monitor unix:"/run/qemu-$1/monitor.sock",server,nowait + -pidfile "@runstatedir@/qemu-$1/pid" + -vnc unix:"@runstatedir@/qemu-$1/vnc.sock" + -monitor unix:"@runstatedir@/qemu-$1/monitor.sock",server,nowait -serial file:"/dev/stdout" -daemonize ) @@ -26,7 +26,7 @@ args+=( vcpu=${line#?' CPU #'}; vcpu=${vcpu%%:*} tid=${line#thread_id=}; tid=${tid%% *} vcpu2tid[$vcpu]=$tid - done < <(socat STDIO UNIX-CONNECT:"/run/qemu-$1/monitor.sock" <<<'info cpus') + done < <(socat STDIO UNIX-CONNECT:"@runstatedir@/qemu-$1/monitor.sock" <<<'info cpus') for vcpu in "${!vcpu_pins[@]}"; do taskset --cpu-list --pid -- "${vcpu2cpulist[@]}" "${vcpu2tid[$vcpu]}" diff --git a/systemd/system/qemu@.service b/qemu@.service.in index 95cbefc..000419e 100644 --- a/systemd/system/qemu@.service +++ b/qemu@.service.in @@ -8,9 +8,9 @@ Before=machines.target Type=notify NotifyAccess=all RuntimeDirectory=qemu-%I -PIDFile=/run/qemu-%I/pid -ExecStart=/etc/systemd/system/qemu %I -ExecStop=/bin/socat SYSTEM:'echo system_powerdown; sleep infinity' UNIX-CONNECT:/run/qemu-%I/monitor.sock +PIDFile=@runstatedir@/qemu-%I/pid +ExecStart=@BINPROG@ %I +ExecStop=@SOCAT@ SYSTEM:'echo system_powerdown; sleep infinity' UNIX-CONNECT:@runstatedir@/qemu-%I/monitor.sock [Install] WantedBy=machines.target diff --git a/write-ifchanged b/write-ifchanged new file mode 100755 index 0000000..bd702a8 --- /dev/null +++ b/write-ifchanged @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +# Copyright (C) 2015 Luke Shumaker +# SPDX-License-Identifier: AGPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +outfile=$1 +tmpfile="$(dirname "$outfile")/.tmp.${outfile##*/}.tmp" + +cat > "$tmpfile" || exit $? +if cmp -s "$tmpfile" "$outfile"; then + rm -f "$tmpfile" || : +else + mv -f "$tmpfile" "$outfile" +fi |