Compare commits

..

2 commits

2 changed files with 18 additions and 31 deletions

View file

@ -1,34 +1,21 @@
#!/usr/bin/env python3 #!/usr/bin/env sh
set -x
# Set number of vCPUs to use to the environment variable QEMUSH_NPROC or # How many CPU cores to use
# half of total vCPUs installed if it fails nproc=$QEMUSH_NPROC
try: [ -z "$nproc" ] && nproc=$(($(nproc) / 2))
from os import environ
nproc = environ['QEMUSH_NPROC']
except KeyError:
from multiprocessing import cpu_count
nproc = str(cpu_count() // 2)
# Set amount of RAM to use to the environment variable QEMUSH_RAM or half # How much RAM to use
# of total RAM installed if it fails ram=$QEMUSH_RAM
try: [ -z "$ram" ] && ram=$(($(free | grep '^Mem:\s' | awk '{ print $NF }') / 2))K
ram = environ['QEMUSH_RAM']
except KeyError:
from psutil import virtual_memory
ram = str(virtual_memory().available // 2 // (1024 ** 2))
# Set the command to initialize; all required parameters to make a sane KVM # Set the arguments
# are included and optional arguments are appended from argv set -- qemu-system-x86_64 \
from sys import argv -enable-kvm \
command = [ -M q35 \
'qemu-system-x86_64', -cpu host -smp "$nproc" \
'-enable-kvm', -m "$ram" \
'-M', 'q35', "$@"
'-cpu', 'host', '-smp', nproc,
'-m', ram,
] + argv[1:]
# Print the final command and replace the main process with it # Start the machine
print(command) exec "$@"
from os import execvp
execvp(command[0], command)

View file

@ -1,6 +1,6 @@
#!/bin/sh -x #!/bin/sh -x
base=$(echo "$QEMUSH_BASE" | cut -d , -f 1) base=$(echo "$QEMUSH_BASE" | cut -d , -f 1)
QEMUSH_BASE=$(echo "$QEMUSH_BASE" | cut -d , -f 2-) QEMUSH_BASE=$(echo "$QEMUSH_BASE" | sed "s/^${base}//" | sed 's/^,//')
exec "$base" \ exec "$base" \
-vga qxl \ -vga qxl \