Compare commits
3 commits
21855f256c
...
912c7f64ff
Author | SHA1 | Date | |
---|---|---|---|
912c7f64ff | |||
b5cd533031 | |||
f7e1c39975 |
3 changed files with 32 additions and 10 deletions
|
@ -8,7 +8,7 @@ exec_as() {
|
||||||
shift
|
shift
|
||||||
|
|
||||||
if [ "$(whoami)" != "$user" ]; then
|
if [ "$(whoami)" != "$user" ]; then
|
||||||
exec sudo -u "$user" "$0" "$@"
|
exec sudo -E -H -u "$user" -- "$0" "$@"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
7
etc/runit/sv/virtiofsd/run
Normal file
7
etc/runit/sv/virtiofsd/run
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#!/bin/sh -e
|
||||||
|
|
||||||
|
# Start a virtiofsd sharing qemu shared dir
|
||||||
|
exec /usr/lib/virtiofsd \
|
||||||
|
--shared-dir ~qemu/shared \
|
||||||
|
--socket-path /run/virtiofsd.sock \
|
||||||
|
--socket-group qemu
|
|
@ -1,20 +1,35 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from os import execvp
|
from os import environ
|
||||||
from multiprocessing import cpu_count
|
|
||||||
from psutil import virtual_memory
|
# Set number of vCPUs to use to the environment variable QEMUSH_NPROC or
|
||||||
|
# half of total vCPUs installed if it fails
|
||||||
|
try:
|
||||||
|
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
|
||||||
|
# of total RAM installed if it fails
|
||||||
|
try:
|
||||||
|
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
|
||||||
|
# are included and optional arguments are appended from argv
|
||||||
from sys import argv
|
from sys import argv
|
||||||
|
|
||||||
nproc = cpu_count() // 2
|
|
||||||
ram_kilo = virtual_memory().available // 2 // 1024
|
|
||||||
|
|
||||||
command = [
|
command = [
|
||||||
'qemu-system-x86_64',
|
'qemu-system-x86_64',
|
||||||
'-enable-kvm', '-daemonize',
|
'-enable-kvm', '-daemonize',
|
||||||
'-M', 'q35',
|
'-M', 'q35',
|
||||||
'-cpu', 'host', '-smp', str(nproc),
|
'-cpu', 'host', '-smp', nproc,
|
||||||
'-m', '{}K'.format(ram_kilo),
|
'-m', ram,
|
||||||
'-net', 'nic'
|
'-net', 'nic'
|
||||||
] + argv[1:]
|
] + argv[1:]
|
||||||
|
|
||||||
|
# Print the final command and replace the main process with it
|
||||||
print(command)
|
print(command)
|
||||||
|
from os import execvp
|
||||||
execvp(command[0], command)
|
execvp(command[0], command)
|
||||||
|
|
Loading…
Reference in a new issue