From 592e97ce53e944a04e92a0b49d5f8725684805cc Mon Sep 17 00:00:00 2001 From: Andreas Fankhauser hiddenalpha.ch Date: Sun, 15 Oct 2023 17:26:38 +0200 Subject: (qemu) Doc how to setup socket mcast networks --- doc/note/qemu/qemu-networking.txt | 27 --------------------------- doc/note/qemu/qemu.txt | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 27 deletions(-) delete mode 100644 doc/note/qemu/qemu-networking.txt diff --git a/doc/note/qemu/qemu-networking.txt b/doc/note/qemu/qemu-networking.txt deleted file mode 100644 index 4318cb5..0000000 --- a/doc/note/qemu/qemu-networking.txt +++ /dev/null @@ -1,27 +0,0 @@ - -## Connect multiple VMs into one network - -TODO: All the (fu**) in here does NOT work, no matter how many RTFM -tutorials I try. - - -# launch one QEMU instance -qemu-system-whatever \ - -device e1000,netdev=n1,mac=52:54:00:12:34:56 \ - -netdev socket,id=n1,mcast=230.0.0.1:1234 \ - ; -# launch another QEMU instance on same "bus" -qemu-system-whatever \ - -device e1000,netdev=n2,mac=52:54:00:12:34:57 \ - -netdev socket,id=n2,mcast=230.0.0.1:1234 \ - ; -# launch yet another QEMU instance on same "bus" -qemu-system-whatever \ - -device e1000,netdev=n3,mac=52:54:00:12:34:58 \ - -netdev socket,id=n3,mcast=230.0.0.1:1234 \ - ; - -## Sources - -- [connect VM networks](https://qemu.weilnetz.de/doc/6.0/system/invocation.html#sec-005finvocation) - diff --git a/doc/note/qemu/qemu.txt b/doc/note/qemu/qemu.txt index b58b193..0abcd1d 100644 --- a/doc/note/qemu/qemu.txt +++ b/doc/note/qemu/qemu.txt @@ -32,6 +32,39 @@ Windoof: qemu-img convert -O qcow2 input.qcow output.qcow2 +## Example Params (Usage: CopyPaste, then delege what is not needed) +qemu-system-x86_64 \ + -enable-kvm -m size=4G -smp cores=$(nproc) \ + -monitor stdio \ + `# Drives & Boot.` \ + -boot order=dc \ + -cdrom "path/to/cd.iso" \ + -hda "$(dirname "$(realpath "$0")")/hda.qcow2" \ + `# 10.0.2.x network with host redirect` \ + -netdev user,id=n0,hostfwd=tcp:127.0.0.1:${SSH_PORT:-2222}-:22 \ + -device e1000,netdev=n0 \ + `# socket mcast shared network adapter` \ + -netdev socket,id=n1,mcast=230.0.0.1:1234 \ + -device e1000,netdev=n1 \ + `# Fix broken host systems` \ + -L "${QEMU_HOME:?}/Bios" -bios "${QEMU_HOME:?}/Bios/bios-256k.bin" \ + -device usb-ehci,id=usb,bus=pci.0,addr=0x4 -device usb-tablet \ + `# Choose ONE of those for graphic output` \ + -nographic \ + -display gtk \ + -display sdl \ + ; + +### Example manual adapter setup (inside VM) for socket mcast network: +true \ + && ADDR=192.168.42.101/24 \ + && DEV=ens4 \ + && SUDO=sudo \ + && $SUDO ip a add dev "${DEV:?}" "${ADDR:?}" \ + && $SUDO ip link set "${DEV:?}" up \ + && true + + ## amd64 # Choose whichever fits the need @@ -217,4 +250,5 @@ TODO: move this to a better place. Eg: debian/setup.txt or whatever. - [qemu monitor via telnet](https://unix.stackexchange.com/a/426951/292722) - [qemu monitor via stdio](https://unix.stackexchange.com/a/57835/292722) - [qemu raspberry pi TODO](https://blog.agchapman.com/using-qemu-to-emulate-a-raspberry-pi/) +- [connect VM networks](https://qemu.weilnetz.de/doc/6.0/system/invocation.html#sec-005finvocation) -- cgit v1.1 From 52b257d55141ce498f890b49b5092caccc256e6d Mon Sep 17 00:00:00 2001 From: Andreas Fankhauser hiddenalpha.ch Date: Tue, 17 Oct 2023 01:34:54 +0200 Subject: (qemu) Migrate gateleen from docker to qemu --- doc/note/qemu/build-gateleen.txt | 69 +++++++++++++++++++++++++++++++++++++ src/main/docker/gateleen.Dockerfile | 65 ---------------------------------- 2 files changed, 69 insertions(+), 65 deletions(-) create mode 100644 doc/note/qemu/build-gateleen.txt delete mode 100644 src/main/docker/gateleen.Dockerfile diff --git a/doc/note/qemu/build-gateleen.txt b/doc/note/qemu/build-gateleen.txt new file mode 100644 index 0000000..77dcab8 --- /dev/null +++ b/doc/note/qemu/build-gateleen.txt @@ -0,0 +1,69 @@ + + +### Alpine +true \ + && PKGS_TO_ADD="curl maven nodejs npm redis openjdk11-jre-headless" \ + && SUDO="${HOME:?}/.local/bin/mysudo" \ + && PKGINIT=true \ + && PKGADD="$SUDO apk add" \ + && PKGCLEAN=true \ + && true + + +### Generic +true \ + && GATELEEN_GIT_TAG="v1.3.28" \ + && WORKDIR="/${HOME:?}/work" \ + && CACHE_DIR="/var/tmp" \ + && true + + +## Setup Dependencies & get sources +true \ + && ${PKGINIT:?} && ${PKGADD:?} $PKGS_TO_ADD \ + \ + && curl -sSL https://github.com/swisspush/gateleen/archive/refs/tags/"${GATELEEN_GIT_TAG:?}".tar.gz > "${CACHE_DIR:?}/gateleen-${GATELEEN_GIT_TAG:?}.tgz" \ + && true + + +### Make +true \ + && mkdir -p "${WORKDIR:?}/gateleen" && cd "${WORKDIR:?}/gateleen" \ + && tar --strip-components 1 -xf "${CACHE_DIR:?}/gateleen-${GATELEEN_GIT_TAG:?}.tgz" \ + && (cd gateleen-hook-js && npm install) \ + && mkdir -p gateleen-hook-js/node/node_modules/npm/bin \ + && ln -s /usr/bin/node gateleen-hook-js/node/node \ + && printf "require('/usr/lib/node_modules/npm/lib/cli.js')\n" | tee gateleen-hook-js/node/node_modules/npm/bin/npm-cli.js >/dev/null \ + && mvn install -PpublicRepos -DskipTests -Dskip.installnodenpm -pl gateleen-hook-js \ + && mvn install -PpublicRepos -DfailIfNoTests=false \ + -pl !gateleen-test,!gateleen-hook-js \ + -Dtest=!ReleaseLockLuaScriptTests,!RedisCacheStorageTest,!DeltaHandlerTest,!QueueCircuitBreakerCloseCircuitLuaScriptTests,!QueueCircuitBreakerGetAllCircuitsLuaScriptTests,!QueueCircuitBreakerHalfOpenCircuitsLuaScriptTests,!QueueCircuitBreakerReOpenCircuitLuaScriptTests,!QueueCircuitBreakerUpdateStatsLuaScriptTests,!RemoveExpiredQueuesLuaScriptTests,!StartQueueTimerLuaScriptTests \ + && mkdir "${WORKDIR:?}/classpath" \ + && (cd gateleen-playground && mvn dependency:copy-dependencies \ + -DexcludeScope=provided -DoutputDirectory="${WORKDIR:?}/classpath/.") \ + && cp gateleen-playground/target/gateleen-playground-*.jar "${WORKDIR:?}/classpath/." \ + && mkdir "${WORKDIR:?}/etc" "${WORKDIR:?}/redis-state" \ + && printf >"${WORKDIR:?}/etc/redis.conf" '%s\n' \ + 'save ""' \ + 'appendonly yes' \ + 'appendfilename appendonly.aof' \ + && `# Squeeze those funny "static files" into redis` \ + && (cd "${WORKDIR:?}/redis-state" && redis-server "${WORKDIR:?}/etc/redis.conf" \ + & java -cp "${WORKDIR:?}/classpath/"'*' org.swisspush.gateleen.playground.Server \ + & sleep 3 \ + ) \ + && (cd "${WORKDIR:?}/gateleen" && mvn deploy -PuploadStaticFiles) \ + && pkill -TERM java && pkill -INT redis-server \ + && $PKGDEL $PKGS_TO_DEL \ + && $PKGCLEAN \ + && printf '\n DONE\n\n' \ + && true + + +### Run +true \ + && ip a | grep inet \ + && (cd "${WORKDIR:?}/redis-state" && redis-server "${WORKDIR:?}/etc/redis.conf") \ + & java -cp "${WORKDIR:?}/classpath/"'*' org.swisspush.gateleen.playground.Server \ + && true + diff --git a/src/main/docker/gateleen.Dockerfile b/src/main/docker/gateleen.Dockerfile deleted file mode 100644 index f604dc2..0000000 --- a/src/main/docker/gateleen.Dockerfile +++ /dev/null @@ -1,65 +0,0 @@ -# -# A Gateleen playground instance. -# - -ARG PARENT_IMAGE=alpine:3.16.0 -FROM $PARENT_IMAGE - -ARG GATELEEN_GIT_TAG=v1.3.28 -ARG UID=1000 -ARG GID=1000 -ARG PKGS_TO_ADD="maven nodejs npm curl redis openjdk11-jre-headless" -#ARG PKGS_TO_DEL="maven nodejs npm" -ARG PKGS_TO_DEL="nodejs npm" -ARG PKGINIT="true" -ARG PKGADD="apk add" -ARG PKGDEL="true" -ARG PKGCLEAN="true" - -WORKDIR /work - -RUN true \ - && printf 'user:x:%s:%s:user:/work:/bin/sh\n' "${UID:?}" "${GID:?}" >> /etc/passwd \ - && true - -RUN true \ - && $PKGINIT && $PKGADD $PKGS_TO_ADD \ - && sed -i "s,, /data/maven/.m2/repository\n,g" /usr/share/java/maven-3/conf/settings.xml \ - && mkdir /data /data/maven /work/gateleen \ - && chown "${UID:?}:${GID:?}" /data/maven /work /work/gateleen \ - && curl -sSL https://github.com/swisspush/gateleen/archive/refs/tags/"$GATELEEN_GIT_TAG".tar.gz > "/tmp/gateleen-$GATELEEN_GIT_TAG.tgz" \ - && cd /work/gateleen \ - && su user -c 'tar --strip-components 1 -xf /tmp/gateleen-"$GATELEEN_GIT_TAG".tgz' \ - && (cd gateleen-hook-js && su user -c 'npm install') \ - && su user -c 'mkdir -p gateleen-hook-js/node/node_modules/npm/bin' \ - && su user -c 'ln -s /usr/bin/node gateleen-hook-js/node/node' \ - && printf "require('/usr/lib/node_modules/npm/lib/cli.js')\n" | su user -c 'tee gateleen-hook-js/node/node_modules/npm/bin/npm-cli.js' >/dev/null \ - && su user -c 'mvn install -PpublicRepos -DskipTests -Dskip.installnodenpm -pl gateleen-hook-js' \ - && su user -c 'mvn install -PpublicRepos -DfailIfNoTests=false \ - -pl !gateleen-test,!gateleen-hook-js \ - -Dtest=!ReleaseLockLuaScriptTests,!RedisCacheStorageTest,!DeltaHandlerTest,!QueueCircuitBreakerCloseCircuitLuaScriptTests,!QueueCircuitBreakerGetAllCircuitsLuaScriptTests,!QueueCircuitBreakerHalfOpenCircuitsLuaScriptTests,!QueueCircuitBreakerReOpenCircuitLuaScriptTests,!QueueCircuitBreakerUpdateStatsLuaScriptTests,!RemoveExpiredQueuesLuaScriptTests,!StartQueueTimerLuaScriptTests' \ - && mkdir /work/classpath \ - && chown "${UID:?}:${GID:?}" /work/classpath \ - && su user -c 'cd gateleen-playground && mvn dependency:copy-dependencies \ - -DexcludeScope=provided -DoutputDirectory=/work/classpath/.' \ - && cp gateleen-playground/target/gateleen-playground-*.jar /work/classpath/. \ - && mkdir /work/etc \ - && printf >/work/etc/redis.conf '%s\n' \ - 'save ""' \ - 'appendonly yes' \ - 'appenddirname "redis-state"' \ - 'appendfilename appendonly.aof' \ - && (su user -c 'cd /work && redis-server /work/etc/redis.conf & \ - java -cp '"'/work/classpath/*'"' org.swisspush.gateleen.playground.Server' \ - & sleep 3) \ - && su user -c 'cd /work/gateleen && mvn deploy -PuploadStaticFiles' \ - && pkill -INT java && pkill -INT redis-server \ - && $PKGDEL $PKGS_TO_DEL \ - && $PKGCLEAN \ - && true - -USER "${UID}:${GID}" - -#CMD ["sleep", "36000"] -CMD ["sh", "-c", "ip a|grep inet && redis-server /work/etc/redis.conf & java -cp '/work/classpath/*' org.swisspush.gateleen.playground.Server"] - -- cgit v1.1 From fcb84f32536c5577307c440d07484d77f95df3cc Mon Sep 17 00:00:00 2001 From: Andreas Fankhauser hiddenalpha.ch Date: Tue, 17 Oct 2023 02:17:53 +0200 Subject: (qemu) Cleanup, Test new Gateleen build env --- doc/note/qemu/build-gateleen.txt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/doc/note/qemu/build-gateleen.txt b/doc/note/qemu/build-gateleen.txt index 77dcab8..5e71c05 100644 --- a/doc/note/qemu/build-gateleen.txt +++ b/doc/note/qemu/build-gateleen.txt @@ -7,6 +7,9 @@ true \ && PKGINIT=true \ && PKGADD="$SUDO apk add" \ && PKGCLEAN=true \ + && mkdir -p "${HOME:?}/.local/bin" \ + && printf '%s\n' '#!/bin/sh' 'printf "Sudo "' 'su root -c "$(echo "$@")"' > "${HOME:?}/.local/bin/mysudo" \ + && chmod u+x "${HOME:?}/.local/bin/mysudo" \ && true @@ -53,9 +56,11 @@ true \ & sleep 3 \ ) \ && (cd "${WORKDIR:?}/gateleen" && mvn deploy -PuploadStaticFiles) \ - && pkill -TERM java && pkill -INT redis-server \ + && (pkill -INT java || sleep 3 && pkill -TERM java || sleep 3 && pkill -9 java) \ + && pkill -INT redis-server \ && $PKGDEL $PKGS_TO_DEL \ && $PKGCLEAN \ + && sleep 3 \ && printf '\n DONE\n\n' \ && true @@ -63,7 +68,11 @@ true \ ### Run true \ && ip a | grep inet \ - && (cd "${WORKDIR:?}/redis-state" && redis-server "${WORKDIR:?}/etc/redis.conf") \ - & java -cp "${WORKDIR:?}/classpath/"'*' org.swisspush.gateleen.playground.Server \ + && (true \ + && (cd "${WORKDIR:?}/redis-state" && redis-server "${WORKDIR:?}/etc/redis.conf") \ + & true \ + && cd ~ \ + && java -cp "${WORKDIR:?}/classpath/"'*' org.swisspush.gateleen.playground.Server \ + ) \ && true -- cgit v1.1 From 45326d08584866373db07af9da3ad43acff854ac Mon Sep 17 00:00:00 2001 From: Andreas Fankhauser hiddenalpha.ch Date: Tue, 17 Oct 2023 02:28:31 +0200 Subject: (qemu) add hint how to merge snapshot images --- doc/note/qemu/qemu.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/note/qemu/qemu.txt b/doc/note/qemu/qemu.txt index 0abcd1d..994527c 100644 --- a/doc/note/qemu/qemu.txt +++ b/doc/note/qemu/qemu.txt @@ -21,6 +21,8 @@ Qemu ### Convert raw to qcow2 qemu-img convert -f raw -O qcow2 foo.img foo.qcow2 +### Create Standalone image based on snapshot image + qemu-img convert -O qcow2 derived.qcow2 standalone.qcow2 ## Shrink img -- cgit v1.1 From a1e4785f2a560ccbe3035d781472399e3847aa11 Mon Sep 17 00:00:00 2001 From: Andreas Fankhauser hiddenalpha.ch Date: Tue, 17 Oct 2023 03:06:47 +0200 Subject: (qemu) Gateleen add a 'mvn clean' after build --- doc/note/qemu/build-gateleen.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/note/qemu/build-gateleen.txt b/doc/note/qemu/build-gateleen.txt index 5e71c05..9666aa6 100644 --- a/doc/note/qemu/build-gateleen.txt +++ b/doc/note/qemu/build-gateleen.txt @@ -61,6 +61,7 @@ true \ && $PKGDEL $PKGS_TO_DEL \ && $PKGCLEAN \ && sleep 3 \ + && (cd "${WORKDIR:?}/gateleen" && mvn clean) \ && printf '\n DONE\n\n' \ && true -- cgit v1.1