From 6e306c77d3bd945dd48fd9746ac1b07610e85f36 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 12 Apr 2017 14:53:15 +0200 Subject: Add support for KVM, monitoring bbot diagnostics --- bootstrap | 5 +++++ buildos | 42 +++++++++++++++++++++++++++++++++++++++++- doc/manual.cli | 19 ++++++++++++++++--- init | 6 ++++++ 4 files changed, 68 insertions(+), 4 deletions(-) diff --git a/bootstrap b/bootstrap index ca7cffe..cfbf59a 100755 --- a/bootstrap +++ b/bootstrap @@ -155,6 +155,8 @@ if [ "$stage" -eq "1" ]; then pkgs+=",bzip2,xz-utils" pkgs+=",less,nano" + pkgs+=",qemu-kvm,socat" + pkgs+=",g++,pkg-config" sudo debootstrap \ @@ -293,6 +295,7 @@ set -x # addgroup --gid 2000 build adduser --uid 2000 --gid 2000 --home /build --gecos "" --disabled-password build +adduser build kvm echo "build ALL=(ALL) NOPASSWD:ALL" >/etc/sudoers.d/build chmod 0440 /etc/sudoers.d/build @@ -415,6 +418,8 @@ EOF subvol_snapshot -r "$root" "$root-5" fi +exit 0 + # Test. # if [ ! -e /tmp/buildos-state ]; then diff --git a/buildos b/buildos index 0461e68..6c3e008 100755 --- a/buildos +++ b/buildos @@ -77,6 +77,14 @@ for v in "${cmdline[@]}"; do fi done +# Make sure /dev/kvm has correct permissions (while all the udev scripts seem +# to be there, it does not work for some reason). +# +if sudo test -c /dev/kvm; then + sudo chgrp kvm /dev/kvm + sudo chmod 0660 /dev/kvm +fi + hname="$(hostname)" # Get the build id. @@ -721,6 +729,7 @@ function bbot_start () # # start their bbot agents. # toolchain_boots=() +declare -A toolchain_cursors # Latest systemd journal cursor. # Monitoring loop. # @@ -844,7 +853,38 @@ EOF sudo systemctl reset-failed "bbot-agent@$tn" 2>&1 | \ tee -a "$tr/bbot-$count.log" 1>&2 else - continue # Nothing to do. + # See if there is any diagnostics in the systemd journal. We + # notify about warning and up. + # + # The old versions journalctl behavior is to not output anything + # (not even the cursor) if there are no new entries. The new + # versions output the old cursor. + # + c=(sudo journalctl --unit "bbot-agent@$tn") + + # Get the last cursor if any. + # + oc="${toolchain_cursors["$tn"]}" + if [ -n "$oc" ]; then + c+=("--after-cursor" "$oc") + fi + + nc="$("${c[@]}" --no-pager --quiet --priority 4 --show-cursor | \ +sed -n -re 's/^-- cursor: (.+)$/\1/p')" + + # If we have no new entries, then nothing to do. + # + if [ -n "$nc" -a "$nc" != "$oc" ]; then + s="bbot-agent@$tn service issued new diagnostics" + + info "$s" + email "$s" <-monitor +\ + +\ +ssh -f -L 5901:127.0.0.1:5901 build@build sleep 1 && vncviewer 127.0.0.1:5901 +\ " diff --git a/init b/init index 694dcb0..18a6b0b 100755 --- a/init +++ b/init @@ -66,6 +66,12 @@ SYSTEMD_LOG_LEVEL=info /lib/systemd/systemd-udevd --daemon --resolve-names=never udevadm trigger --action=add udevadm settle || true +# Initialize KVM. +# +#if ! (modprobe kvm_intel || modprobe kvm_amd); then +# error "no virtualization support available (is it disabled in BIOS?)" +#fi + # Parse the kernel command line. This is complicated by the fact that the # values can be quoted, for example: # -- cgit v1.1