launchers/kvm : python -> sh
This commit is contained in:
parent
5a2233bd04
commit
1e7f5c43b8
1 changed files with 17 additions and 30 deletions
|
@ -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)
|
|
||||||
|
|
Loading…
Reference in a new issue