From 0f817fa673bc9fb881c260d7667d71972492fa84 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Mon, 27 Apr 2015 18:16:11 +0300 Subject: [PATCH] Improve VM support --- ex/makevm | 17 +++-------------- ex/runvm | 12 ++++-------- ex/vm.conf | 4 ++-- lib/Gruntmaster/Daemon/Format.pm | 18 +++++++++++------- lib/Gruntmaster/Daemon/Runner/Interactive.pm | 5 ----- 5 files changed, 20 insertions(+), 36 deletions(-) diff --git a/ex/makevm b/ex/makevm index bf240c3..f6ed255 100755 --- a/ex/makevm +++ b/ex/makevm @@ -1,7 +1,4 @@ #!/bin/bash -GROUP=$(getent group www-data | cut -f3 -d:) -USER=$(getent passwd www-data | cut -f3 -d:) - rm -rf vm/ vm.squashfs mkdir -p vm/proc/ mount /proc -o bind vm/proc @@ -9,28 +6,20 @@ multistrap -f ex/vm.conf ln -s vm/usr/bin/mawk vm/bin/awk echo '/sbin/poweroff -f' > vm/.bash_logout cat > vm/etc/fstab < vm/.profile < vm/etc/initramfs-tools/modules <> vm/etc/sudoers <nobody closefrom=5 Defaults>nobody !env_check Defaults>nobody env_keep="ONLINE_JUDGE PATH HOME" EOF install gruntmaster-exec gruntmaster-compile vm/usr/bin/ -chroot vm update-initramfs -d -k 3.2.0-4-amd64 -chroot vm update-initramfs -c -k 3.2.0-4-amd64 umount vm/proc mksquashfs vm vm.squashfs -comp lzo diff --git a/ex/runvm b/ex/runvm index 208aedc..8495e51 100755 --- a/ex/runvm +++ b/ex/runvm @@ -1,15 +1,11 @@ #!/bin/bash -ROOT=/home/marius/git/gruntmaster-daemon +ROOT=. qemu-system-x86_64 \ -enable-kvm -cpu host -m 256MB \ -nodefaults -nographic \ - -kernel $ROOT/vm/boot/vmlinuz-3.2.0-4-amd64 \ - -initrd $ROOT/vm/boot/initrd.img-3.2.0-4-amd64 \ - -append 'root=/dev/vda console=ttyS0,38400 quiet init=/bin/bash --login' \ + -kernel $ROOT/bzImage \ + -append 'root=/dev/vda console=ttyS0,1200 init=/bin/bash --login' \ -drive file=$ROOT/vm.squashfs,if=virtio,readonly \ -virtfs local,id=virtfs0,path=.,security_model=none,mount_tag=virtfs \ - -chardev stdio,id=stdio,signal=on \ - -chardev pipe,id=hostpipe,path=$1 \ - -serial chardev:stdio \ - -serial chardev:hostpipe + -serial stdio "$@" diff --git a/ex/vm.conf b/ex/vm.conf index f2aab06..19a9092 100644 --- a/ex/vm.conf +++ b/ex/vm.conf @@ -5,9 +5,9 @@ bootstrap=Debian aptsources=Debian [Debian] -packages=linux-image-3.2.0-4-amd64 mawk libbsd-resource-perl libipc-signal-perl gcc g++ mono-gmcs default-jdk golang-go gccgo ghc fpc perl python sudo +packages=sysvinit-core mawk libbsd-resource-perl libipc-signal-perl gcc g++ mono-gmcs default-jdk golang-go gccgo ghc fpc perl python sudo source=http://ftp.ro.debian.org/debian keyring=debian-archive-keyring -suite=wheezy +suite=jessie components=main omitdebsrc=true diff --git a/lib/Gruntmaster/Daemon/Format.pm b/lib/Gruntmaster/Daemon/Format.pm index bcfb2a4..6160a31 100644 --- a/lib/Gruntmaster/Daemon/Format.pm +++ b/lib/Gruntmaster/Daemon/Format.pm @@ -11,7 +11,6 @@ use File::Basename qw/fileparse/; use File::Slurp qw/read_file write_file/; use List::MoreUtils qw/natatime/; use Log::Log4perl qw/get_logger/; -use POSIX qw/mkfifo/; use String::ShellQuote qw/shell_quote/; use Try::Tiny; @@ -23,13 +22,13 @@ our @EXPORT_OK = qw/prepare_files stopvms/; our (%vm); sub runvm { - my ($name) = @_; + my ($name, $arg) = @_; return unless $ENV{GRUNTMASTER_VM}; - mkfifo "$name.in", 0600; - mkfifo "$name.out", 0600; - get_logger->trace("Starting VM $name"); + my $cmd = $ENV{GRUNTMASTER_VM}; + $cmd .= ' ' . $arg if $arg; + get_logger->trace("Starting VM $name ($cmd)"); $vm{$name} = Expect::Simple->new({ - Cmd => "$ENV{GRUNTMASTER_VM} $name", + Cmd => $cmd, Prompt => '# ', DisconnectCmd => 'exit', RawPty => 1, @@ -104,7 +103,12 @@ sub prepare{ sub prepare_files{ my $meta = shift; - runvm $_ for keys %{$meta->{files}}; + if ($meta->{runner} eq 'Interactive') { + runvm ver => '-serial unix:vm.sock,nowait,server'; + runvm prog => '-serial unix:vm.sock,nowait'; + } else { + runvm $_ for keys %{$meta->{files}}; + } for my $file (values %{$meta->{files}}) { my ($format, $name, $content) = @{$file}{qw/format name content/}; diff --git a/lib/Gruntmaster/Daemon/Runner/Interactive.pm b/lib/Gruntmaster/Daemon/Runner/Interactive.pm index af1581e..ed9a056 100644 --- a/lib/Gruntmaster/Daemon/Runner/Interactive.pm +++ b/lib/Gruntmaster/Daemon/Runner/Interactive.pm @@ -21,11 +21,6 @@ sub run{ mkfifo 'fifo1', 0600 or die "$!\n" unless -e 'fifo1'; mkfifo 'fifo2', 0600 or die "$!\n" unless -e 'fifo2'; - if ($test == 1 && $ENV{GRUNTMASTER_VM}) { - exec 'cat ver.in' if fork; - exec 'cat prog.in' if fork; - } - my $ret = fork // get_logger->logdie("Fork failed: $!"); if ($ret) { try { -- 2.39.2